Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add k8s env froms #4969

Merged
merged 21 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions charts/flyte/README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions charts/flyte/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ flyte:
- FLYTE_AWS_ACCESS_KEY_ID: minio
- FLYTE_AWS_SECRET_ACCESS_KEY: miniostorage
default-memory: 200Mi
default-env-vars-from-configmaps: []
default-env-vars-from-secrets: []

# -- Logger configuration
logger:
Expand Down
6 changes: 4 additions & 2 deletions deployment/sandbox/flyte_helm_generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ data:
- FLYTE_AWS_ENDPOINT: http://minio.flyte:9000
- FLYTE_AWS_ACCESS_KEY_ID: minio
- FLYTE_AWS_SECRET_ACCESS_KEY: miniostorage
default-env-vars-from-configmaps: []
default-env-vars-from-secrets: []
default-memory: 200Mi
logger.yaml: |
logger:
Expand Down Expand Up @@ -7170,7 +7172,7 @@ spec:
template:
metadata:
annotations:
configChecksum: "a82c947246fac99ad98c86bc01cdd99569b2ea11f25d3e1361cd40d145bed87"
configChecksum: "3f87b4e38dcccebef4f630a9af22718ca79bf6e283b44a6368359b6698a4d2f"
labels:
app.kubernetes.io/name: flytepropeller
app.kubernetes.io/instance: flyte
Expand Down Expand Up @@ -7244,7 +7246,7 @@ spec:
app.kubernetes.io/name: flyte-pod-webhook
app.kubernetes.io/version: v1.11.0-b1
annotations:
configChecksum: "a82c947246fac99ad98c86bc01cdd99569b2ea11f25d3e1361cd40d145bed87"
configChecksum: "3f87b4e38dcccebef4f630a9af22718ca79bf6e283b44a6368359b6698a4d2f"
spec:
securityContext:
fsGroup: 65534
Expand Down
4 changes: 2 additions & 2 deletions docker/sandbox-bundled/manifests/complete-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ type: Opaque
---
apiVersion: v1
data:
haSharedSecret: UVdVTnB4cXBMVXMyRjhGUw==
haSharedSecret: d1J2MUxKRktZZDVGdU5NZg==
proxyPassword: ""
proxyUsername: ""
kind: Secret
Expand Down Expand Up @@ -1412,7 +1412,7 @@ spec:
metadata:
annotations:
checksum/config: 8f50e768255a87f078ba8b9879a0c174c3e045ffb46ac8723d2eedbe293c8d81
checksum/secret: 7dd7be244652f0c2d4d5651db7e9d879fb74fb3a4407a80c48cba3dcd7b74e53
checksum/secret: a4f85b741a9e736bb72d552240e8ff9149549da7ec966d81076f3dcf3628d6e0
labels:
app: docker-registry
release: flyte-sandbox
Expand Down
4 changes: 2 additions & 2 deletions docker/sandbox-bundled/manifests/complete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ type: Opaque
---
apiVersion: v1
data:
haSharedSecret: cnBScDd2Y3Y0a2JlcHlzVQ==
haSharedSecret: SDZFWm1hSWx0QnV2ckRwQw==
proxyPassword: ""
proxyUsername: ""
kind: Secret
Expand Down Expand Up @@ -1360,7 +1360,7 @@ spec:
metadata:
annotations:
checksum/config: 8f50e768255a87f078ba8b9879a0c174c3e045ffb46ac8723d2eedbe293c8d81
checksum/secret: 459fe43b90e7be7fce10bc94020ba94037c1a21501b61d4e7121c84251f1b198
checksum/secret: b0e2fb97dfbd24814d0652dbc139494b19091a16718746145b67ef26b63b2868
labels:
app: docker-registry
release: flyte-sandbox
Expand Down
4 changes: 2 additions & 2 deletions docker/sandbox-bundled/manifests/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ metadata:
---
apiVersion: v1
data:
haSharedSecret: NlJkVzYyZ1MzZmZIRE1nOA==
haSharedSecret: RUZDeVl0a0twd295dUV2bQ==
proxyPassword: ""
proxyUsername: ""
kind: Secret
Expand Down Expand Up @@ -934,7 +934,7 @@ spec:
metadata:
annotations:
checksum/config: 8f50e768255a87f078ba8b9879a0c174c3e045ffb46ac8723d2eedbe293c8d81
checksum/secret: 2e417b7dd337346d064d1cd4edf6b5624d335fce92ccfe22acd20485be450ec9
checksum/secret: 52c5e1654b5494d6e531ba21378dcebc9eef964c40aa39dcd8455bd46624b749
labels:
app: docker-registry
release: flyte-sandbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ type K8sPluginConfig struct {
DefaultEnvVars map[string]string `json:"default-env-vars" pflag:"-,Additional environment variable that should be injected into every resource"`
// Provide additional environment variable pairs whose values resolve from the plugin's execution environment.
DefaultEnvVarsFromEnv map[string]string `json:"default-env-vars-from-env" pflag:"-,Additional environment variable that should be injected into every resource"`
// Provide additional environment variable parts from configMaps
DefaultEnvVarsFromConfigMaps []string `json:"default-env-vars-from-configmaps" pflag:"-,Additional environment variables should be injected into each pod from these configMaps"`
// Provide additional environment variable parts from secrets
DefaultEnvVarsFromSecrets []string `json:"default-env-vars-from-secrets" pflag:"-,Additional environment variables should be injected into each pod from these secret"`

// default cpu requests for a container
DefaultCPURequest resource.Quantity `json:"default-cpus" pflag:",Defines a default value for cpu for containers if not specified."`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ func DecorateEnvVars(ctx context.Context, envVars []v1.EnvVar, taskEnvironmentVa
value := os.Getenv(envVarName)
envVars = append(envVars, v1.EnvVar{Name: k, Value: value})
}
for _, configMapName := range config.GetK8sPluginConfig().DefaultEnvVarsFromConfigMaps {
envVars = append(envVars, v1.EnvVar{
ValueFrom: &v1.EnvVarSource{
ConfigMapKeyRef: &v1.ConfigMapKeySelector{
Key: configMapName,
},
},
})
}
eapolinario marked this conversation as resolved.
Show resolved Hide resolved
for _, secretName := range config.GetK8sPluginConfig().DefaultEnvVarsFromSecrets {
envVars = append(envVars, v1.EnvVar{
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
Key: secretName,
},
},
})
}

return envVars
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ func TestDecorateEnvVars(t *testing.T) {
"k": "value",
}

var emptyConfigMaps []string
envVarConfigMaps := []string{
"test-cm-1",
}

var emptySecrets []string
envVarSecrets := []string{
"test-secret-1",
}

originalEnvVal := os.Getenv("value")
err := os.Setenv("value", "v")
if err != nil {
Expand All @@ -259,6 +269,22 @@ func TestDecorateEnvVars(t *testing.T) {
expected := append(defaultEnv, GetContextEnvVars(ctx)...)
expected = append(expected, GetExecutionEnvVars(mockTaskExecutionIdentifier{})...)

expectedPlusCMs := append(expected, v12.EnvVar{
ValueFrom: &v12.EnvVarSource{
ConfigMapKeyRef: &v12.ConfigMapKeySelector{
Key: envVarConfigMaps[0],
},
},
})

expectedPlusSecrets := append(expected, v12.EnvVar{
ValueFrom: &v12.EnvVarSource{
SecretKeyRef: &v12.SecretKeySelector{
Key: envVarSecrets[0],
},
},
})

aggregated := append(expected, v12.EnvVar{Name: "k", Value: "v"})
type args struct {
envVars []v12.EnvVar
Expand All @@ -270,18 +296,24 @@ func TestDecorateEnvVars(t *testing.T) {
additionEnvVar map[string]string
additionEnvVarFromEnv map[string]string
executionEnvVar map[string]string
configMapEnvNames []string
secretEnvNames []string
want []v12.EnvVar
}{
{"no-additional", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, emptyEnvVar, emptyEnvVar, emptyEnvVar, expected},
{"with-additional", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, additionalEnv, emptyEnvVar, emptyEnvVar, aggregated},
{"from-env", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, emptyEnvVar, envVarsFromEnv, emptyEnvVar, aggregated},
{"from-execution-metadata", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, emptyEnvVar, emptyEnvVar, additionalEnv, aggregated},
{"no-additional", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, emptyEnvVar, emptyEnvVar, emptyEnvVar, emptyConfigMaps, emptySecrets, expected},
{"with-additional", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, additionalEnv, emptyEnvVar, emptyEnvVar, emptyConfigMaps, emptySecrets, aggregated},
{"from-env", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, emptyEnvVar, envVarsFromEnv, emptyEnvVar, emptyConfigMaps, emptySecrets, aggregated},
{"from-execution-metadata", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, emptyEnvVar, emptyEnvVar, additionalEnv, emptyConfigMaps, emptySecrets, aggregated},
{"with-from-configmap", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, emptyEnvVar, emptyEnvVar, emptyEnvVar, envVarConfigMaps, emptySecrets, expectedPlusCMs},
{"with-from-secret", args{envVars: defaultEnv, id: mockTaskExecutionIdentifier{}}, emptyEnvVar, emptyEnvVar, emptyEnvVar, emptyConfigMaps, envVarSecrets, expectedPlusSecrets},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{
DefaultEnvVars: tt.additionEnvVar,
DefaultEnvVarsFromEnv: tt.additionEnvVarFromEnv,
DefaultEnvVars: tt.additionEnvVar,
DefaultEnvVarsFromEnv: tt.additionEnvVarFromEnv,
DefaultEnvVarsFromConfigMaps: tt.configMapEnvNames,
DefaultEnvVarsFromSecrets: tt.secretEnvNames,
}))
if got := DecorateEnvVars(ctx, tt.args.envVars, tt.executionEnvVar, tt.args.id); !reflect.DeepEqual(got, tt.want) {
t.Errorf("DecorateEnvVars() = %v, want %v", got, tt.want)
Expand Down
Loading