Skip to content

Commit d0b11af

Browse files
committed
Add tests for the optional field for secret/configmap environment variables
- Update protobuf definitions and regenerate bindings - Fix backend driver to handle Optional field correctly - Update tests and ensure backward compatibility Signed-off-by: ddalvi <[email protected]>
1 parent be50c3c commit d0b11af

File tree

5 files changed

+304
-81
lines changed

5 files changed

+304
-81
lines changed

backend/src/v2/driver/k8s.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,19 @@ func extendPodSpecPatch(
309309
// Get secret env information
310310
for _, secretAsEnv := range kubernetesExecutorConfig.GetSecretAsEnv() {
311311
for _, keyToEnv := range secretAsEnv.GetKeyToEnv() {
312+
secretKeySelector := &k8score.SecretKeySelector{
313+
Key: keyToEnv.GetSecretKey(),
314+
}
315+
316+
// Set Optional field when explicitly provided (true or false), leave nil when not specified
317+
if secretAsEnv.Optional != nil {
318+
secretKeySelector.Optional = secretAsEnv.Optional
319+
}
320+
312321
secretEnvVar := k8score.EnvVar{
313322
Name: keyToEnv.GetEnvVar(),
314323
ValueFrom: &k8score.EnvVarSource{
315-
SecretKeyRef: &k8score.SecretKeySelector{
316-
Key: keyToEnv.GetSecretKey(),
317-
},
324+
SecretKeyRef: secretKeySelector,
318325
},
319326
}
320327

@@ -392,12 +399,19 @@ func extendPodSpecPatch(
392399
// Get config map env information
393400
for _, configMapAsEnv := range kubernetesExecutorConfig.GetConfigMapAsEnv() {
394401
for _, keyToEnv := range configMapAsEnv.GetKeyToEnv() {
402+
configMapKeySelector := &k8score.ConfigMapKeySelector{
403+
Key: keyToEnv.GetConfigMapKey(),
404+
}
405+
406+
// Set Optional field when explicitly provided (true or false), leave nil when not specified
407+
if configMapAsEnv.Optional != nil {
408+
configMapKeySelector.Optional = configMapAsEnv.Optional
409+
}
410+
395411
configMapEnvVar := k8score.EnvVar{
396412
Name: keyToEnv.GetEnvVar(),
397413
ValueFrom: &k8score.EnvVarSource{
398-
ConfigMapKeyRef: &k8score.ConfigMapKeySelector{
399-
Key: keyToEnv.GetConfigMapKey(),
400-
},
414+
ConfigMapKeyRef: configMapKeySelector,
401415
},
402416
}
403417

0 commit comments

Comments
 (0)