Skip to content

Commit

Permalink
Make k8s secrets optional (flyteorg#482)
Browse files Browse the repository at this point in the history
* make secrets optional - to skip mounting missing values

Signed-off-by: Daniel Rammer <[email protected]>

* add env var secrets to optional values

Signed-off-by: Daniel Rammer <[email protected]>

* fixed lint issue

Signed-off-by: Daniel Rammer <[email protected]>

* fixed unit tests

Signed-off-by: Daniel Rammer <[email protected]>

* fixed lint issue

Signed-off-by: Daniel Rammer <[email protected]>

Signed-off-by: Daniel Rammer <[email protected]>
  • Loading branch information
hamersaw authored Oct 5, 2022
1 parent 560bb1b commit 66eaf12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/webhook/k8s_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

func TestK8sSecretInjector_Inject(t *testing.T) {
optional := true

inputPod := corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
Expand All @@ -36,6 +38,7 @@ func TestK8sSecretInjector_Inject(t *testing.T) {
LocalObjectReference: corev1.LocalObjectReference{
Name: "grOUP",
},
Optional: &optional,
},
},
},
Expand Down Expand Up @@ -63,6 +66,7 @@ func TestK8sSecretInjector_Inject(t *testing.T) {
Path: "hello",
},
},
Optional: &optional,
},
},
},
Expand Down Expand Up @@ -110,6 +114,7 @@ func TestK8sSecretInjector_Inject(t *testing.T) {
Path: "world",
},
},
Optional: &optional,
},
},
},
Expand Down Expand Up @@ -147,6 +152,7 @@ func TestK8sSecretInjector_Inject(t *testing.T) {
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "hello",
Optional: &optional,
},
},
},
Expand Down
6 changes: 5 additions & 1 deletion pkg/webhook/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@ func hasEnvVar(envVars []corev1.EnvVar, envVarKey string) bool {
}

func CreateEnvVarForSecret(secret *core.Secret) corev1.EnvVar {
optional := true
return corev1.EnvVar{
Name: strings.ToUpper(K8sDefaultEnvVarPrefix + secret.Group + EnvVarGroupKeySeparator + secret.Key),
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: secret.Group,
},
Key: secret.Key,
Key: secret.Key,
Optional: &optional,
},
},
}
}

func CreateVolumeForSecret(secret *core.Secret) corev1.Volume {
optional := true
return corev1.Volume{
// we don't want to create different volume for the same secret group
Name: encoding.Base32Encoder.EncodeToString([]byte(secret.Group + EnvVarGroupKeySeparator + secret.GroupVersion)),
Expand All @@ -51,6 +54,7 @@ func CreateVolumeForSecret(secret *core.Secret) corev1.Volume {
Path: strings.ToLower(secret.Key),
},
},
Optional: &optional,
},
},
}
Expand Down

0 comments on commit 66eaf12

Please sign in to comment.