Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Carry over DefaultEnvVarsFromEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Grätz committed Oct 12, 2022
1 parent dc4c4f1 commit eec24ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/tasks/plugins/k8s/spark/spark.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (sparkResourceHandler) BuildResource(ctx context.Context, taskCtx pluginsCo
for _, envVar := range envVars {
sparkEnvVars[envVar.Name] = envVar.Value
}

for k, v := range config.GetK8sPluginConfig().DefaultEnvVarsFromEnv {
sparkEnvVars[k] = v
}

sparkEnvVars["FLYTE_MAX_ATTEMPTS"] = strconv.Itoa(int(taskCtx.TaskExecutionMetadata().GetMaxAttempts()))

serviceAccountName := flytek8s.GetServiceAccountNameFromTaskExecutionMetadata(taskCtx.TaskExecutionMetadata())
Expand Down
6 changes: 6 additions & 0 deletions go/tasks/plugins/k8s/spark/spark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ func TestBuildResourceSpark(t *testing.T) {
defaultEnvVars := make(map[string]string)
defaultEnvVars["foo"] = "bar"

defaultEnvVarsFromEnv := make(map[string]string)
defaultEnvVarsFromEnv["fooEnv"] = "barEnv"

assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{
DefaultPodSecurityContext: &corev1.PodSecurityContext{
RunAsUser: &runAsUser,
Expand Down Expand Up @@ -416,6 +419,7 @@ func TestBuildResourceSpark(t *testing.T) {
SchedulerName: schedulerName,
EnableHostNetworkingPod: &defaultPodHostNetwork,
DefaultEnvVars: defaultEnvVars,
DefaultEnvVarsFromEnv: defaultEnvVarsFromEnv,
}),
)
resource, err := sparkResourceHandler.BuildResource(context.TODO(), dummySparkTaskContext(taskTemplate, true))
Expand Down Expand Up @@ -532,6 +536,8 @@ func TestBuildResourceSpark(t *testing.T) {
assert.Equal(t, len(sparkApp.Spec.Driver.EnvVars["FLYTE_MAX_ATTEMPTS"]), 1)
assert.Equal(t, sparkApp.Spec.Driver.EnvVars["foo"], defaultEnvVars["foo"])
assert.Equal(t, sparkApp.Spec.Executor.EnvVars["foo"], defaultEnvVars["foo"])
assert.Equal(t, sparkApp.Spec.Driver.EnvVars["fooEnv"], defaultEnvVarsFromEnv["fooEnv"])
assert.Equal(t, sparkApp.Spec.Executor.EnvVars["fooEnv"], defaultEnvVarsFromEnv["fooEnv"])

// Case 2: Driver/Executor request cores set.
dummyConfWithRequest := make(map[string]string)
Expand Down

0 comments on commit eec24ca

Please sign in to comment.