Skip to content

Commit 21a8d22

Browse files
feat(helm): support global.castai overrides (apiURL, grpcURL, clusterID) for umbrella chart (#653)
Add support for global.castai.apiURL, global.castai.grpcURL, and global.castai.clusterID in helm templates, enabling the castai-umbrella chart to override kvisor's values centrally. - Extract kvisor.apiGrpcAddr and kvisor.apiURL helpers to deduplicate coalesce+dig logic across agent.yaml and controller.yaml - Modify kvisor.clusterIDEnv to resolve global.castai.clusterID inline, preserving existing validation against clusterIdConfigMapKeyRef/SecretKeyRef - Align kvisor.cloudProvider helper to use the same inline style - Priority order: global value > local value > default - Add 13 unit tests covering all fallback scenarios
1 parent 816b6ca commit 21a8d22

File tree

5 files changed

+315
-9
lines changed

5 files changed

+315
-9
lines changed

charts/kvisor/templates/_helpers.tpl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ 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 (or .Values.castai.clusterIdConfigMapKeyRef.name .Values.castai.clusterIdSecretKeyRef.name) }}
59+
{{- $clusterID := coalesce (dig "castai" "clusterID" "" (.Values.global | default dict)) .Values.castai.clusterID -}}
60+
{{- if and $clusterID (or .Values.castai.clusterIdConfigMapKeyRef.name .Values.castai.clusterIdSecretKeyRef.name) }}
6061
{{- fail "clusterID cannot be used together with clusterIdConfigMapKeyRef or clusterIdSecretKeyRef" }}
61-
{{- else if .Values.castai.clusterID }}
62+
{{- else if $clusterID }}
6263
- name: CLUSTER_ID
63-
value: {{ .Values.castai.clusterID | quote }}
64+
value: {{ $clusterID | quote }}
6465
valueFrom: null # workaround for https://github.com/helm/helm/issues/8994
6566
{{- else if .Values.castai.clusterIdConfigMapKeyRef.name }}
6667
- name: CLUSTER_ID
@@ -329,8 +330,21 @@ Resolve cloud provider for --cloud-provider arg.
329330
Only used as a fallback when controller.extraArgs.cloud-provider is not set.
330331
*/}}
331332
{{- define "kvisor.cloudProvider" -}}
332-
{{- $global := .Values.global | default dict -}}
333-
{{- dig "castai" "provider" "" $global -}}
333+
{{- dig "castai" "provider" "" (.Values.global | default dict) -}}
334+
{{- end }}
335+
336+
{{/*
337+
Resolve CASTAI_API_GRPC_ADDR: global.castai.grpcURL > .Values.castai.grpcAddr
338+
*/}}
339+
{{- define "kvisor.apiGrpcAddr" -}}
340+
{{- coalesce (dig "castai" "grpcURL" "" (.Values.global | default dict)) .Values.castai.grpcAddr -}}
341+
{{- end }}
342+
343+
{{/*
344+
Resolve CASTAI_API_URL: global.castai.apiURL > .Values.castai.apiURL
345+
*/}}
346+
{{- define "kvisor.apiURL" -}}
347+
{{- coalesce (dig "castai" "apiURL" "" (.Values.global | default dict)) .Values.castai.apiURL -}}
334348
{{- end }}
335349

336350
{{/*

charts/kvisor/templates/agent.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ spec:
111111
value: {{ if .Values.mockServer.enabled -}}
112112
{{ (printf "%s:8443" (include "kvisor.castaiMockServer.service" .)) | quote }}
113113
{{- else -}}
114-
{{ .Values.castai.grpcAddr | quote }}
114+
{{ include "kvisor.apiGrpcAddr" . | quote }}
115115
{{- end }}
116116
- name: CASTAI_API_URL
117117
value: {{ if .Values.mockServer.enabled -}}
118118
{{ (printf "http://%s:8080" (include "kvisor.castaiMockServer.service" .)) | quote }}
119119
{{- else -}}
120-
{{ .Values.castai.apiURL | quote }}
120+
{{ include "kvisor.apiURL" . | quote }}
121121
{{- end }}
122122
{{- include "kvisor.clusterIDEnv" (set (deepCopy .) "envFrom" .Values.agent.envFrom) | nindent 12 }}
123123
{{- if .Values.agent.debug.ebpf }}

charts/kvisor/templates/controller.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ spec:
108108
value: {{ if .Values.mockServer.enabled -}}
109109
{{ (printf "%s:8443" (include "kvisor.castaiMockServer.service" .)) | quote }}
110110
{{- else -}}
111-
{{ .Values.castai.grpcAddr | quote }}
111+
{{ include "kvisor.apiGrpcAddr" . | quote }}
112112
{{- end }}
113113
- name: CASTAI_API_URL
114114
value: {{ if .Values.mockServer.enabled -}}
115115
{{ (printf "http://%s:8080" (include "kvisor.castaiMockServer.service" .)) | quote }}
116116
{{- else -}}
117-
{{ .Values.castai.apiURL | quote }}
117+
{{ include "kvisor.apiURL" . | quote }}
118118
{{- end }}
119119
{{- include "kvisor.clusterIDEnv" (set (deepCopy .) "envFrom" .Values.controller.envFrom) | nindent 12 }}
120120
{{- range $k, $v := .Values.controller.additionalEnv }}
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
suite: global values fallback tests
2+
templates:
3+
- agent.yaml
4+
- controller.yaml
5+
- secret.yaml
6+
values:
7+
- values.yaml
8+
tests:
9+
- it: should use global.castai.apiURL when local castai.apiURL is not set
10+
set:
11+
global:
12+
castai:
13+
apiURL: "https://global.cast.ai/"
14+
asserts:
15+
- contains:
16+
path: spec.template.spec.containers[0].env
17+
content:
18+
name: CASTAI_API_URL
19+
value: "https://global.cast.ai/"
20+
template: controller.yaml
21+
documentIndex: 0
22+
- contains:
23+
path: spec.template.spec.containers[0].env
24+
content:
25+
name: CASTAI_API_URL
26+
value: "https://global.cast.ai/"
27+
template: agent.yaml
28+
documentIndex: 0
29+
30+
- it: should use global.castai.grpcURL over local default grpcAddr
31+
set:
32+
global:
33+
castai:
34+
grpcURL: "grpc.global.cast.ai:443"
35+
asserts:
36+
- contains:
37+
path: spec.template.spec.containers[0].env
38+
content:
39+
name: CASTAI_API_GRPC_ADDR
40+
value: "grpc.global.cast.ai:443"
41+
template: controller.yaml
42+
documentIndex: 0
43+
- contains:
44+
path: spec.template.spec.containers[0].env
45+
content:
46+
name: CASTAI_API_GRPC_ADDR
47+
value: "grpc.global.cast.ai:443"
48+
template: agent.yaml
49+
documentIndex: 0
50+
51+
- it: should prefer global.castai.apiURL over local castai.apiURL
52+
set:
53+
castai.apiURL: "https://local.cast.ai/"
54+
global:
55+
castai:
56+
apiURL: "https://global.cast.ai/"
57+
asserts:
58+
- contains:
59+
path: spec.template.spec.containers[0].env
60+
content:
61+
name: CASTAI_API_URL
62+
value: "https://global.cast.ai/"
63+
template: controller.yaml
64+
documentIndex: 0
65+
- contains:
66+
path: spec.template.spec.containers[0].env
67+
content:
68+
name: CASTAI_API_URL
69+
value: "https://global.cast.ai/"
70+
template: agent.yaml
71+
documentIndex: 0
72+
73+
- it: should prefer global.castai.grpcURL over local castai.grpcAddr
74+
set:
75+
castai.grpcAddr: "grpc.local.cast.ai:443"
76+
global:
77+
castai:
78+
grpcURL: "grpc.global.cast.ai:443"
79+
asserts:
80+
- contains:
81+
path: spec.template.spec.containers[0].env
82+
content:
83+
name: CASTAI_API_GRPC_ADDR
84+
value: "grpc.global.cast.ai:443"
85+
template: controller.yaml
86+
documentIndex: 0
87+
- contains:
88+
path: spec.template.spec.containers[0].env
89+
content:
90+
name: CASTAI_API_GRPC_ADDR
91+
value: "grpc.global.cast.ai:443"
92+
template: agent.yaml
93+
documentIndex: 0
94+
95+
- it: should use default grpcAddr when neither local nor global is set
96+
asserts:
97+
- contains:
98+
path: spec.template.spec.containers[0].env
99+
content:
100+
name: CASTAI_API_GRPC_ADDR
101+
value: "kvisor.prod-master.cast.ai:443"
102+
template: controller.yaml
103+
documentIndex: 0
104+
- contains:
105+
path: spec.template.spec.containers[0].env
106+
content:
107+
name: CASTAI_API_GRPC_ADDR
108+
value: "kvisor.prod-master.cast.ai:443"
109+
template: agent.yaml
110+
documentIndex: 0
111+
112+
- it: should use local castai.apiURL when global is not set
113+
set:
114+
castai.apiURL: "https://local.cast.ai/"
115+
asserts:
116+
- contains:
117+
path: spec.template.spec.containers[0].env
118+
content:
119+
name: CASTAI_API_URL
120+
value: "https://local.cast.ai/"
121+
template: controller.yaml
122+
documentIndex: 0
123+
- contains:
124+
path: spec.template.spec.containers[0].env
125+
content:
126+
name: CASTAI_API_URL
127+
value: "https://local.cast.ai/"
128+
template: agent.yaml
129+
documentIndex: 0
130+
131+
- it: should fall back to defaults when global is empty map
132+
set:
133+
global: {}
134+
asserts:
135+
- contains:
136+
path: spec.template.spec.containers[0].env
137+
content:
138+
name: CASTAI_API_GRPC_ADDR
139+
value: "kvisor.prod-master.cast.ai:443"
140+
template: controller.yaml
141+
documentIndex: 0
142+
- contains:
143+
path: spec.template.spec.containers[0].env
144+
content:
145+
name: CASTAI_API_GRPC_ADDR
146+
value: "kvisor.prod-master.cast.ai:443"
147+
template: agent.yaml
148+
documentIndex: 0
149+
150+
- it: should fall back to defaults when global.castai is empty map
151+
set:
152+
global:
153+
castai: {}
154+
asserts:
155+
- contains:
156+
path: spec.template.spec.containers[0].env
157+
content:
158+
name: CASTAI_API_GRPC_ADDR
159+
value: "kvisor.prod-master.cast.ai:443"
160+
template: controller.yaml
161+
documentIndex: 0
162+
- contains:
163+
path: spec.template.spec.containers[0].env
164+
content:
165+
name: CASTAI_API_GRPC_ADDR
166+
value: "kvisor.prod-master.cast.ai:443"
167+
template: agent.yaml
168+
documentIndex: 0
169+
170+
- it: should use local values when global is empty map
171+
set:
172+
global: {}
173+
castai.apiURL: "https://local.cast.ai/"
174+
castai.grpcAddr: "grpc.local.cast.ai:443"
175+
asserts:
176+
- contains:
177+
path: spec.template.spec.containers[0].env
178+
content:
179+
name: CASTAI_API_URL
180+
value: "https://local.cast.ai/"
181+
template: controller.yaml
182+
documentIndex: 0
183+
- contains:
184+
path: spec.template.spec.containers[0].env
185+
content:
186+
name: CASTAI_API_GRPC_ADDR
187+
value: "grpc.local.cast.ai:443"
188+
template: controller.yaml
189+
documentIndex: 0
190+
- contains:
191+
path: spec.template.spec.containers[0].env
192+
content:
193+
name: CASTAI_API_URL
194+
value: "https://local.cast.ai/"
195+
template: agent.yaml
196+
documentIndex: 0
197+
- contains:
198+
path: spec.template.spec.containers[0].env
199+
content:
200+
name: CASTAI_API_GRPC_ADDR
201+
value: "grpc.local.cast.ai:443"
202+
template: agent.yaml
203+
documentIndex: 0
204+
205+
- it: should use global.castai.clusterID over local castai.clusterID
206+
set:
207+
global:
208+
castai:
209+
clusterID: "global-cluster-id"
210+
asserts:
211+
- contains:
212+
path: spec.template.spec.containers[0].env
213+
content:
214+
name: CLUSTER_ID
215+
value: "global-cluster-id"
216+
valueFrom: null
217+
template: controller.yaml
218+
documentIndex: 0
219+
- contains:
220+
path: spec.template.spec.containers[0].env
221+
content:
222+
name: CLUSTER_ID
223+
value: "global-cluster-id"
224+
valueFrom: null
225+
template: agent.yaml
226+
documentIndex: 0
227+
228+
- it: should prefer global.castai.clusterID over local castai.clusterID
229+
set:
230+
castai.clusterID: "local-cluster-id"
231+
global:
232+
castai:
233+
clusterID: "global-cluster-id"
234+
asserts:
235+
- contains:
236+
path: spec.template.spec.containers[0].env
237+
content:
238+
name: CLUSTER_ID
239+
value: "global-cluster-id"
240+
valueFrom: null
241+
template: controller.yaml
242+
documentIndex: 0
243+
- contains:
244+
path: spec.template.spec.containers[0].env
245+
content:
246+
name: CLUSTER_ID
247+
value: "global-cluster-id"
248+
valueFrom: null
249+
template: agent.yaml
250+
documentIndex: 0
251+
252+
- it: should fail when global.castai.clusterID and clusterIdSecretKeyRef are both set
253+
set:
254+
castai.clusterID: ""
255+
castai.clusterIdSecretKeyRef:
256+
name: "cluster-secret"
257+
key: "CLUSTER_ID"
258+
global:
259+
castai:
260+
clusterID: "global-cluster-id"
261+
asserts:
262+
- failedTemplate:
263+
errorMessage: "clusterID cannot be used together with clusterIdConfigMapKeyRef or clusterIdSecretKeyRef"
264+
template: controller.yaml
265+
266+
- it: should use local castai.clusterID when global is empty map
267+
set:
268+
global: {}
269+
asserts:
270+
- contains:
271+
path: spec.template.spec.containers[0].env
272+
content:
273+
name: CLUSTER_ID
274+
value: "test-cluster-id"
275+
valueFrom: null
276+
template: controller.yaml
277+
documentIndex: 0
278+
- contains:
279+
path: spec.template.spec.containers[0].env
280+
content:
281+
name: CLUSTER_ID
282+
value: "test-cluster-id"
283+
valueFrom: null
284+
template: agent.yaml
285+
documentIndex: 0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
agent:
2+
enabled: true
3+
controller:
4+
enabled: true
5+
castai:
6+
apiKey: test-api-key
7+
clusterID: test-cluster-id

0 commit comments

Comments
 (0)