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 all 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-from-configmaps: []
default-env-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 @@ -646,6 +646,8 @@ data:
plugins:
k8s:
default-cpus: 100m
default-env-from-configmaps: []
default-env-from-secrets: []
default-env-vars:
- FLYTE_AWS_ENDPOINT: http://minio.flyte:9000
- FLYTE_AWS_ACCESS_KEY_ID: minio
Expand Down Expand Up @@ -7170,7 +7172,7 @@ spec:
template:
metadata:
annotations:
configChecksum: "ecefcb1d6df38b32a9ec77d91de63cd40da935a3239b70a5bb0396435878c80"
configChecksum: "3500386bee9f0763c6f14460f607cea4e6e24be4224a806c0673db71e13e287"
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
annotations:
configChecksum: "ecefcb1d6df38b32a9ec77d91de63cd40da935a3239b70a5bb0396435878c80"
configChecksum: "3500386bee9f0763c6f14460f607cea4e6e24be4224a806c0673db71e13e287"
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: VTg5RFBvY205cXRtcEVFbw==
haSharedSecret: U0tNSVV0aUwzZzYxNVZnVQ==
proxyPassword: ""
proxyUsername: ""
kind: Secret
Expand Down Expand Up @@ -1412,7 +1412,7 @@ spec:
metadata:
annotations:
checksum/config: 8f50e768255a87f078ba8b9879a0c174c3e045ffb46ac8723d2eedbe293c8d81
checksum/secret: b8339a7b42c1e04b994b517d4ddd749074787df4a0eaef9e1aa2181988aea2d7
checksum/secret: e0d4db2f1f52d2e4d16959b463e9470d657899ab22db5d8eb2fbc605cdcda0a2
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: ZTNEUmhqY1VsWDBXNFowTg==
haSharedSecret: bmNtdzJkQ0l2Rm5BS3VZSg==
proxyPassword: ""
proxyUsername: ""
kind: Secret
Expand Down Expand Up @@ -1360,7 +1360,7 @@ spec:
metadata:
annotations:
checksum/config: 8f50e768255a87f078ba8b9879a0c174c3e045ffb46ac8723d2eedbe293c8d81
checksum/secret: cedf489b22e27428631c5c365e58bfd51cf8465bf04d07a74462677278017b80
checksum/secret: b1ca10c95becb2e7214c9ece8101acc322ecde650f1e70bdb1bbb37323c948f6
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: bkV2U2JzN0o2TXNVcHJTMg==
haSharedSecret: S2hmRkxmVjdKZUpoTkR6OQ==
proxyPassword: ""
proxyUsername: ""
kind: Secret
Expand Down Expand Up @@ -934,7 +934,7 @@ spec:
metadata:
annotations:
checksum/config: 8f50e768255a87f078ba8b9879a0c174c3e045ffb46ac8723d2eedbe293c8d81
checksum/secret: 2f2e4b3f4abc8a670a75900bd0c7987fb3afa6b2a287fdf7292fbeb755c00c12
checksum/secret: 446da9acad72026ea6684e9f0cf3e47f8a458fa10d29d61ac3f8bc509afc7c11
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
DefaultEnvFromConfigMaps []string `json:"default-env-from-configmaps" pflag:"-,Additional environment variable sets that should be injected into each pod from these configMaps"`
// Provide additional environment variable parts from secrets
DefaultEnvFromSecrets []string `json:"default-env-from-secrets" pflag:"-,Additional environment variable sets that 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 @@ -291,7 +291,7 @@ func AddFlyteCustomizationsToContainer(ctx context.Context, parameters template.
}
container.Args = modifiedArgs

container.Env = DecorateEnvVars(ctx, container.Env, parameters.TaskExecMetadata.GetEnvironmentVariables(), parameters.TaskExecMetadata.GetTaskExecutionID())
container.Env, container.EnvFrom = DecorateEnvVars(ctx, container.Env, parameters.TaskExecMetadata.GetEnvironmentVariables(), parameters.TaskExecMetadata.GetTaskExecutionID())

// retrieve platformResources and overrideResources to use when aggregating container resources
platformResources := parameters.TaskExecMetadata.GetPlatformResources()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
return envVars
}

func DecorateEnvVars(ctx context.Context, envVars []v1.EnvVar, taskEnvironmentVariables map[string]string, id pluginsCore.TaskExecutionID) []v1.EnvVar {
func DecorateEnvVars(ctx context.Context, envVars []v1.EnvVar, taskEnvironmentVariables map[string]string, id pluginsCore.TaskExecutionID) ([]v1.EnvVar, []v1.EnvFromSource) {
envVars = append(envVars, GetContextEnvVars(ctx)...)
envVars = append(envVars, GetExecutionEnvVars(id)...)

Expand All @@ -128,7 +128,21 @@
envVars = append(envVars, v1.EnvVar{Name: k, Value: value})
}

return envVars
envFroms := []v1.EnvFromSource{}

for _, secretName := range config.GetK8sPluginConfig().DefaultEnvFromSecrets {
optional := true
secretRef := v1.SecretEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: secretName}, Optional: &optional}
envFroms = append(envFroms, v1.EnvFromSource{SecretRef: &secretRef})
}

Check warning on line 137 in flyteplugins/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go#L134-L137

Added lines #L134 - L137 were not covered by tests

for _, cmName := range config.GetK8sPluginConfig().DefaultEnvFromConfigMaps {
optional := true
cmRef := v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: cmName}, Optional: &optional}
envFroms = append(envFroms, v1.EnvFromSource{ConfigMapRef: &cmRef})
}

Check warning on line 143 in flyteplugins/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go#L140-L143

Added lines #L140 - L143 were not covered by tests

return envVars, envFroms
}

func GetPodTolerations(interruptible bool, resourceRequirements ...v1.ResourceRequirements) []v1.Toleration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func TestDecorateEnvVars(t *testing.T) {
DefaultEnvVars: tt.additionEnvVar,
DefaultEnvVarsFromEnv: tt.additionEnvVarFromEnv,
}))
if got := DecorateEnvVars(ctx, tt.args.envVars, tt.executionEnvVar, tt.args.id); !reflect.DeepEqual(got, tt.want) {
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func UpdateBatchInputForArray(_ context.Context, batchInput *batch.SubmitJobInpu

func getEnvVarsForTask(ctx context.Context, execID pluginCore.TaskExecutionID, containerEnvVars []*core.KeyValuePair,
defaultEnvVars map[string]string) []v1.EnvVar {
envVars := flytek8s.DecorateEnvVars(ctx, flytek8s.ToK8sEnvVar(containerEnvVars), nil, execID)
envVars, _ := flytek8s.DecorateEnvVars(ctx, flytek8s.ToK8sEnvVar(containerEnvVars), nil, execID)
m := make(map[string]string, len(envVars))
for _, envVar := range envVars {
m[envVar.Name] = envVar.Value
Expand Down
Loading