Skip to content

Commit 292cbe6

Browse files
author
Samu
authored
feat: allow reading cluster_id from configMap (#640)
1 parent 5362d99 commit 292cbe6

File tree

6 files changed

+174
-5
lines changed

6 files changed

+174
-5
lines changed

charts/kvisor/templates/_helpers.tpl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,25 @@ Create chart name and version as used by the chart label.
5656

5757
{{- define "kvisor.clusterIDEnv" -}}
5858
{{- $envFrom := .envFrom -}}
59-
{{- if and .Values.castai.clusterID .Values.castai.clusterIdSecretKeyRef.name }}
60-
{{- fail "clusterID and clusterIdSecretKeyRef are mutually exclusive" }}
59+
{{- if and .Values.castai.clusterID (or .Values.castai.clusterIdConfigMapKeyRef.name .Values.castai.clusterIdSecretKeyRef.name) }}
60+
{{- fail "clusterID cannot be used together with clusterIdConfigMapKeyRef or clusterIdSecretKeyRef" }}
6161
{{- else if .Values.castai.clusterID }}
6262
- name: CLUSTER_ID
6363
value: {{ .Values.castai.clusterID | quote }}
64+
{{- else if .Values.castai.clusterIdConfigMapKeyRef.name }}
65+
- name: CLUSTER_ID
66+
valueFrom:
67+
configMapKeyRef:
68+
name: {{ .Values.castai.clusterIdConfigMapKeyRef.name }}
69+
key: {{ .Values.castai.clusterIdConfigMapKeyRef.key }}
6470
{{- else if .Values.castai.clusterIdSecretKeyRef.name }}
6571
- name: CLUSTER_ID
6672
valueFrom:
6773
secretKeyRef:
6874
name: {{ .Values.castai.clusterIdSecretKeyRef.name }}
6975
key: {{ .Values.castai.clusterIdSecretKeyRef.key }}
7076
{{- else if not $envFrom }}
71-
{{- fail "castai.clusterID or castai.clusterIdSecretKeyRef must be provided" }}
77+
{{- fail "castai.clusterID, castai.clusterIdConfigMapKeyRef or castai.clusterIdSecretKeyRef must be provided" }}
7278
{{- end }}
7379
{{- end }}
7480

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
suite: cluster ID configuration tests
2+
templates:
3+
- agent.yaml
4+
- controller.yaml
5+
- secret.yaml
6+
values:
7+
- values.yaml
8+
tests:
9+
- it: should use direct clusterID value when provided
10+
asserts:
11+
- contains:
12+
path: spec.template.spec.containers[0].env
13+
content:
14+
name: CLUSTER_ID
15+
value: "test-cluster-id"
16+
template: agent.yaml
17+
documentIndex: 0
18+
- contains:
19+
path: spec.template.spec.containers[0].env
20+
content:
21+
name: CLUSTER_ID
22+
value: "test-cluster-id"
23+
template: controller.yaml
24+
documentIndex: 0
25+
26+
- it: should use clusterIdConfigMapKeyRef when provided
27+
set:
28+
castai.clusterID: ""
29+
castai.clusterIdConfigMapKeyRef:
30+
name: "cluster-config"
31+
key: "CLUSTER_ID"
32+
asserts:
33+
- contains:
34+
path: spec.template.spec.containers[0].env
35+
content:
36+
name: CLUSTER_ID
37+
valueFrom:
38+
configMapKeyRef:
39+
name: "cluster-config"
40+
key: "CLUSTER_ID"
41+
template: agent.yaml
42+
documentIndex: 0
43+
- contains:
44+
path: spec.template.spec.containers[0].env
45+
content:
46+
name: CLUSTER_ID
47+
valueFrom:
48+
configMapKeyRef:
49+
name: "cluster-config"
50+
key: "CLUSTER_ID"
51+
template: controller.yaml
52+
documentIndex: 0
53+
54+
- it: should use clusterIdSecretKeyRef when provided
55+
set:
56+
castai.clusterID: ""
57+
castai.clusterIdSecretKeyRef:
58+
name: "cluster-secret"
59+
key: "CLUSTER_ID"
60+
asserts:
61+
- contains:
62+
path: spec.template.spec.containers[0].env
63+
content:
64+
name: CLUSTER_ID
65+
valueFrom:
66+
secretKeyRef:
67+
name: "cluster-secret"
68+
key: "CLUSTER_ID"
69+
template: agent.yaml
70+
documentIndex: 0
71+
- contains:
72+
path: spec.template.spec.containers[0].env
73+
content:
74+
name: CLUSTER_ID
75+
valueFrom:
76+
secretKeyRef:
77+
name: "cluster-secret"
78+
key: "CLUSTER_ID"
79+
template: controller.yaml
80+
documentIndex: 0
81+
82+
- it: should use custom key from clusterIdConfigMapKeyRef
83+
set:
84+
castai.clusterID: ""
85+
castai.clusterIdConfigMapKeyRef:
86+
name: "my-config"
87+
key: "MY_CUSTOM_KEY"
88+
asserts:
89+
- contains:
90+
path: spec.template.spec.containers[0].env
91+
content:
92+
name: CLUSTER_ID
93+
valueFrom:
94+
configMapKeyRef:
95+
name: "my-config"
96+
key: "MY_CUSTOM_KEY"
97+
template: agent.yaml
98+
documentIndex: 0
99+
100+
- it: should fail when both clusterID and clusterIdSecretKeyRef are set
101+
set:
102+
castai.clusterIdSecretKeyRef:
103+
name: "cluster-secret"
104+
key: "CLUSTER_ID"
105+
asserts:
106+
- failedTemplate:
107+
errorMessage: "clusterID cannot be used together with clusterIdConfigMapKeyRef or clusterIdSecretKeyRef"
108+
template: controller.yaml
109+
110+
- it: should fail when both clusterID and clusterIdConfigMapKeyRef are set
111+
set:
112+
castai.clusterIdConfigMapKeyRef:
113+
name: "cluster-config"
114+
key: "CLUSTER_ID"
115+
asserts:
116+
- failedTemplate:
117+
errorMessage: "clusterID cannot be used together with clusterIdConfigMapKeyRef or clusterIdSecretKeyRef"
118+
template: controller.yaml
119+
120+
- it: should prefer clusterIdConfigMapKeyRef over clusterIdSecretKeyRef when both are set
121+
set:
122+
castai.clusterID: ""
123+
castai.clusterIdSecretKeyRef:
124+
name: "cluster-secret"
125+
key: "SECRET_KEY"
126+
castai.clusterIdConfigMapKeyRef:
127+
name: "cluster-config"
128+
key: "CONFIG_KEY"
129+
asserts:
130+
- contains:
131+
path: spec.template.spec.containers[0].env
132+
content:
133+
name: CLUSTER_ID
134+
valueFrom:
135+
configMapKeyRef:
136+
name: "cluster-config"
137+
key: "CONFIG_KEY"
138+
template: agent.yaml
139+
documentIndex: 0
140+
- notContains:
141+
path: spec.template.spec.containers[0].env
142+
content:
143+
name: CLUSTER_ID
144+
valueFrom:
145+
secretKeyRef:
146+
name: "cluster-secret"
147+
key: "SECRET_KEY"
148+
template: agent.yaml
149+
documentIndex: 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
agent:
2+
enabled: true
3+
4+
controller:
5+
enabled: true
6+
7+
castai:
8+
apiKey: test-api-key
9+
clusterID: test-cluster-id

charts/kvisor/tests/openshift-scc_test.yaml renamed to charts/kvisor/tests/openshift-scc/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ templates:
44
- agent.yaml
55
- secret.yaml
66
values:
7-
- openshift-scc_values.yaml
7+
- values.yaml
88
tests:
99
- it: should not create SCC when agent.openshift.scc.create is false
1010
set:
File renamed without changes.

charts/kvisor/values.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ castai:
1919

2020
apiURL: ""
2121

22-
# clusterID and clusterIdSecretKeyRef are mutually exclusive
22+
# clusterID, clusterIdConfigMapKeyRef and clusterIdSecretKeyRef are mutually exclusive
2323
clusterID: ""
24+
# clusterIdConfigMapKeyRef -- Name and Key of configMap with ClusterID
25+
# The referenced configMap must provide the ClusterID in .data[<<.Values.castai.clusterIdConfigMapKeyRef.key>>]
26+
clusterIdConfigMapKeyRef:
27+
name: ""
28+
key: "CLUSTER_ID"
2429
# clusterIdSecretKeyRef -- Name and Key of secret with ClusterID
2530
# The referenced secret must provide the ClusterID in .data[<<.Values.castai.clusterIdSecretKeyRef.key>>]
2631
clusterIdSecretKeyRef:

0 commit comments

Comments
 (0)