Skip to content

Commit 82465ca

Browse files
andrewazorestthvo
andauthored
feat(discovery): implement All Namespaces discovery (#213)
Co-authored-by: Thuan Vo <[email protected]>
1 parent 2d5ca9c commit 82465ca

13 files changed

+543
-157
lines changed

charts/cryostat/README.md

Lines changed: 87 additions & 86 deletions
Large diffs are not rendered by default.

charts/cryostat/templates/cryostat_deployment.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,21 @@ spec:
118118
value: http://localhost:3000
119119
- name: GRAFANA_DASHBOARD_EXT_URL
120120
value: /grafana/
121-
{{- if .Values.core.discovery.kubernetes.enabled }}
121+
{{- with .Values.core.discovery.kubernetes }}
122+
{{- if .enabled }}
122123
- name: CRYOSTAT_DISCOVERY_KUBERNETES_ENABLED
123124
value: "true"
124-
{{- with .Values.core.discovery.kubernetes }}
125-
- name: CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES
126-
value: {{ include "cryostat.commaSepList" (list .namespaces $.Release.Namespace .installNamespaceDisabled) }}
127125
- name: CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NAMES
128126
value: {{ include "cryostat.commaSepList" (list .portNames "jfr-jmx" .builtInPortNamesDisabled) }}
129127
- name: CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NUMBERS
130128
value: {{ include "cryostat.commaSepList" (list .portNumbers 9091 .builtInPortNumbersDisabled) }}
129+
{{- if .allowAllNamespaces }}
130+
- name: CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES
131+
value: '*'
132+
{{- else }}
133+
- name: CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES
134+
value: {{ include "cryostat.commaSepList" (list .namespaces $.Release.Namespace .installNamespaceDisabled) }}
135+
{{- end }}
131136
{{- end }}
132137
{{- end }}
133138
{{- with (.Values.core.config.extra).envVars }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{{- if and .Values.rbac.create .Values.core.discovery.kubernetes.enabled .Values.core.discovery.kubernetes.allowAllNamespaces -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: {{ include "cryostat.fullname" . }}-discovery
6+
labels:
7+
{{- include "cryostat.labels" . | nindent 4 }}
8+
rules:
9+
- apiGroups:
10+
- ""
11+
resources:
12+
- namespaces
13+
verbs:
14+
- list
15+
- apiGroups:
16+
- discovery.k8s.io
17+
resources:
18+
- endpointslices
19+
verbs:
20+
- get
21+
- list
22+
- watch
23+
- apiGroups:
24+
- ""
25+
resources:
26+
- pods
27+
- replicationcontrollers
28+
verbs:
29+
- get
30+
- apiGroups:
31+
- apps
32+
resources:
33+
- replicasets
34+
- deployments
35+
- daemonsets
36+
- statefulsets
37+
verbs:
38+
- get
39+
- apiGroups:
40+
- apps.openshift.io
41+
resources:
42+
- deploymentconfigs
43+
verbs:
44+
- get
45+
- apiGroups:
46+
- route.openshift.io
47+
resources:
48+
- routes
49+
verbs:
50+
- get
51+
- list
52+
{{- end -}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- if and .Values.rbac.create .Values.core.discovery.kubernetes.enabled .Values.core.discovery.kubernetes.allowAllNamespaces -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRoleBinding
4+
metadata:
5+
name: {{ include "cryostat.fullname" . }}-discovery
6+
labels:
7+
{{- include "cryostat.labels" . | nindent 4 }}
8+
roleRef:
9+
apiGroup: rbac.authorization.k8s.io
10+
kind: ClusterRole
11+
name: {{ include "cryostat.fullname" . }}-discovery
12+
subjects:
13+
- kind: ServiceAccount
14+
name: {{ include "cryostat.serviceAccountName" . }}
15+
namespace: {{ .Release.Namespace }}
16+
{{- end }}

charts/cryostat/templates/role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ rules:
5050
{{- end -}}
5151
{{- end -}}
5252

53-
{{- if and .Values.rbac.create .Values.core.discovery.kubernetes.enabled -}}
53+
{{- if and .Values.rbac.create .Values.core.discovery.kubernetes.enabled (not .Values.core.discovery.kubernetes.allowAllNamespaces) -}}
5454
{{- $watchNs := compact (default list .Values.core.discovery.kubernetes.namespaces) | uniq -}}
5555
{{- if and (not $watchNs) (not .Values.core.discovery.kubernetes.installNamespaceDisabled) -}}
5656
{{- $watchNs = list .Release.Namespace -}}

charts/cryostat/templates/rolebinding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ subjects:
2020
{{- end -}}
2121
{{- end -}}
2222

23-
{{- if and .Values.rbac.create .Values.core.discovery.kubernetes.enabled -}}
23+
{{- if and .Values.rbac.create .Values.core.discovery.kubernetes.enabled (not .Values.core.discovery.kubernetes.allowAllNamespaces) -}}
2424
{{- $watchNs := compact (default list .Values.core.discovery.kubernetes.namespaces) | uniq -}}
2525
{{- if and (not $watchNs) (not .Values.core.discovery.kubernetes.installNamespaceDisabled) -}}
2626
{{- $watchNs = list .Release.Namespace -}}

charts/cryostat/tests/cryostat_deployment_test.yaml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,3 +1204,120 @@ tests:
12041204
- secretRef:
12051205
name: sercret-special-config-for-main
12061206
optional: false
1207+
1208+
- it: should allow Kubernetes discovery disabling
1209+
set:
1210+
core.discovery.kubernetes.enabled: false
1211+
asserts:
1212+
- notExists:
1213+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_ENABLED')]
1214+
- notExists:
1215+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES')]
1216+
- notExists:
1217+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NAMES')]
1218+
- notExists:
1219+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NUMBERS')]
1220+
1221+
- it: should allow Kubernetes discovery built-in names and number disabling
1222+
set:
1223+
core.discovery.kubernetes.builtInPortNamesDisabled: true
1224+
core.discovery.kubernetes.builtInPortNumbersDisabled: true
1225+
asserts:
1226+
- equal:
1227+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_ENABLED')].value
1228+
value: "true"
1229+
- equal:
1230+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES')].value
1231+
value: "NAMESPACE"
1232+
- equal:
1233+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NAMES')].value
1234+
value: ""
1235+
- equal:
1236+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NUMBERS')].value
1237+
value: ""
1238+
1239+
- it: should allow Kubernetes discovery namespaces customization
1240+
set:
1241+
core.discovery.kubernetes.namespaces: ['a', 'b']
1242+
asserts:
1243+
- equal:
1244+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_ENABLED')].value
1245+
value: "true"
1246+
- equal:
1247+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES')].value
1248+
value: "a,b"
1249+
- equal:
1250+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NAMES')].value
1251+
value: "jfr-jmx"
1252+
- equal:
1253+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NUMBERS')].value
1254+
value: "9091"
1255+
1256+
- it: should allow Kubernetes discovery port name customization
1257+
set:
1258+
core.discovery.kubernetes.portNames: ['a', 'b']
1259+
asserts:
1260+
- equal:
1261+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_ENABLED')].value
1262+
value: "true"
1263+
- equal:
1264+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES')].value
1265+
value: "NAMESPACE"
1266+
- equal:
1267+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NAMES')].value
1268+
value: "a,b"
1269+
- equal:
1270+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NUMBERS')].value
1271+
value: "9091"
1272+
1273+
- it: should allow Kubernetes discovery port number customization
1274+
set:
1275+
core.discovery.kubernetes.portNumbers: [1, 2]
1276+
asserts:
1277+
- equal:
1278+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_ENABLED')].value
1279+
value: "true"
1280+
- equal:
1281+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES')].value
1282+
value: "NAMESPACE"
1283+
- equal:
1284+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NAMES')].value
1285+
value: "jfr-jmx"
1286+
- equal:
1287+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NUMBERS')].value
1288+
value: "1,2"
1289+
1290+
- it: should allow Kubernetes All Namespaces mode
1291+
set:
1292+
core.discovery.kubernetes.allowAllNamespaces: true
1293+
asserts:
1294+
- equal:
1295+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_ENABLED')].value
1296+
value: "true"
1297+
- equal:
1298+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES')].value
1299+
value: "*"
1300+
- equal:
1301+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NAMES')].value
1302+
value: "jfr-jmx"
1303+
- equal:
1304+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NUMBERS')].value
1305+
value: "9091"
1306+
1307+
- it: Kubernetes All Namespaces mode should override individual namespace settings
1308+
set:
1309+
core.discovery.kubernetes.allowAllNamespaces: true
1310+
core.discovery.kubernetes.namespaces: ['a', 'b']
1311+
asserts:
1312+
- equal:
1313+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_ENABLED')].value
1314+
value: "true"
1315+
- equal:
1316+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_NAMESPACES')].value
1317+
value: "*"
1318+
- equal:
1319+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NAMES')].value
1320+
value: "jfr-jmx"
1321+
- equal:
1322+
path: spec.template.spec.containers[?(@.name=='cryostat')].env[?(@.name=='CRYOSTAT_DISCOVERY_KUBERNETES_PORT_NUMBERS')].value
1323+
value: "9091"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
suite: test discovery_clusterrole.yaml
2+
templates:
3+
- discovery_clusterrole.yaml
4+
5+
tests:
6+
- it: should do nothing if Kubernetes All Namespaces discovery is not enabled
7+
set:
8+
rbac.create: true
9+
core.discovery.kubernetes.enabled: true
10+
core.discovery.kubernetes.allowAllNamespaces: false
11+
asserts:
12+
- hasDocuments:
13+
count: 0
14+
15+
- it: should do nothing if Kubernetes discovery is not enabled
16+
set:
17+
rbac.create: true
18+
core.discovery.kubernetes.enabled: false
19+
core.discovery.kubernetes.allowAllNamespaces: true
20+
asserts:
21+
- hasDocuments:
22+
count: 0
23+
24+
- it: should do nothing if RBAC creation is not enabled
25+
set:
26+
rbac.create: false
27+
core.discovery.kubernetes.enabled: true
28+
core.discovery.kubernetes.allowAllNamespaces: true
29+
asserts:
30+
- hasDocuments:
31+
count: 0
32+
33+
- it: should create ClusterRole
34+
set:
35+
rbac.create: true
36+
core.discovery.kubernetes.enabled: true
37+
core.discovery.kubernetes.allowAllNamespaces: true
38+
asserts:
39+
- hasDocuments:
40+
count: 1
41+
- equal:
42+
path: kind
43+
value: ClusterRole
44+
- equal:
45+
path: metadata.name
46+
value: RELEASE-NAME-cryostat-discovery
47+
- equal:
48+
path: metadata.labels
49+
value:
50+
app.kubernetes.io/instance: RELEASE-NAME
51+
app.kubernetes.io/part-of: cryostat
52+
app.kubernetes.io/managed-by: Helm
53+
app.kubernetes.io/name: cryostat
54+
app.kubernetes.io/version: "4.1.0-dev"
55+
helm.sh/chart: cryostat-2.0.0-dev
56+
- equal:
57+
path: rules
58+
value:
59+
- apiGroups:
60+
- ""
61+
resources:
62+
- namespaces
63+
verbs:
64+
- list
65+
- apiGroups:
66+
- discovery.k8s.io
67+
resources:
68+
- endpointslices
69+
verbs:
70+
- get
71+
- list
72+
- watch
73+
- apiGroups:
74+
- ""
75+
resources:
76+
- pods
77+
- replicationcontrollers
78+
verbs:
79+
- get
80+
- apiGroups:
81+
- apps
82+
resources:
83+
- replicasets
84+
- deployments
85+
- daemonsets
86+
- statefulsets
87+
verbs:
88+
- get
89+
- apiGroups:
90+
- apps.openshift.io
91+
resources:
92+
- deploymentconfigs
93+
verbs:
94+
- get
95+
- apiGroups:
96+
- route.openshift.io
97+
resources:
98+
- routes
99+
verbs:
100+
- get
101+
- list

0 commit comments

Comments
 (0)