From 83de7608f2bdb20232f93cc136869db8c20d329f Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Fri, 22 Dec 2023 15:08:47 +0000 Subject: [PATCH 01/11] Add option in K8s plugin config to inject user identity into pod labels Signed-off-by: Fabio Graetz --- .../go/tasks/pluginmachinery/flytek8s/config/config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flyteplugins/go/tasks/pluginmachinery/flytek8s/config/config.go b/flyteplugins/go/tasks/pluginmachinery/flytek8s/config/config.go index 55f9cfa68c..643c37fb43 100644 --- a/flyteplugins/go/tasks/pluginmachinery/flytek8s/config/config.go +++ b/flyteplugins/go/tasks/pluginmachinery/flytek8s/config/config.go @@ -199,6 +199,9 @@ type K8sPluginConfig struct { // SendObjectEvents indicates whether to send k8s object events in TaskExecutionEvent updates (similar to kubectl get events). SendObjectEvents bool `json:"send-object-events" pflag:",If true, will send k8s object events in TaskExecutionEvent updates."` + + // InjectExecutionIdentity indicates whether to inject the execution identity (if set in the workflow) into the pod as a label. + InjectExecutionIdentity bool `json:"inject-execution-identity" pflag:",If true, will inject execution identity into the pod as a label."` } // FlyteCoPilotConfig specifies configuration for the Flyte CoPilot system. FlyteCoPilot, allows running flytekit-less containers From 62dc608e1f5ee1828a8381b20cf57332a46956ed Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Fri, 22 Dec 2023 15:09:14 +0000 Subject: [PATCH 02/11] Inject user identity into TaskExecutionMetadata labels Signed-off-by: Fabio Graetz --- .../nodes/task/k8s/task_exec_context.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go index 14984e3f97..6c672cf474 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go @@ -3,10 +3,13 @@ package k8s import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" pluginsCore "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/core" + "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/flytek8s/config" "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/utils" "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/utils/secrets" ) +const executionIdentityVariable = "execution_identity" + // TaskExecutionContext provides a layer on top of core TaskExecutionContext with a custom TaskExecutionMetadata. type TaskExecutionContext struct { pluginsCore.TaskExecutionContext @@ -42,25 +45,30 @@ func (t TaskExecutionMetadata) GetAnnotations() map[string]string { } // newTaskExecutionMetadata creates a TaskExecutionMetadata with secrets serialized as annotations and a label added -// to trigger the flyte pod webhook +// to trigger the flyte pod webhook. Optionally, the execution identity is injected as a label. func newTaskExecutionMetadata(tCtx pluginsCore.TaskExecutionMetadata, taskTmpl *core.TaskTemplate) (TaskExecutionMetadata, error) { var err error secretsMap := make(map[string]string) - injectSecretsLabel := make(map[string]string) + injectLabels := make(map[string]string) if taskTmpl.SecurityContext != nil && len(taskTmpl.SecurityContext.Secrets) > 0 { secretsMap, err = secrets.MarshalSecretsToMapStrings(taskTmpl.SecurityContext.Secrets) if err != nil { return TaskExecutionMetadata{}, err } - injectSecretsLabel = map[string]string{ - secrets.PodLabel: secrets.PodLabelValue, + injectLabels[secrets.PodLabel] = secrets.PodLabelValue + } + + if config.GetK8sPluginConfig().InjectExecutionIdentity { + id := tCtx.GetSecurityContext().RunAs.ExecutionIdentity + if id != "" { + injectLabels[executionIdentityVariable] = id } } return TaskExecutionMetadata{ TaskExecutionMetadata: tCtx, annotations: utils.UnionMaps(tCtx.GetAnnotations(), secretsMap), - labels: utils.UnionMaps(tCtx.GetLabels(), injectSecretsLabel), + labels: utils.UnionMaps(tCtx.GetLabels(), injectLabels, injectLabels), }, nil } From 3e55a3fea0bf3bcc69f18497000835c9a7babd31 Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Fri, 22 Dec 2023 15:09:24 +0000 Subject: [PATCH 03/11] Add unit tests Signed-off-by: Fabio Graetz --- .../nodes/task/k8s/task_exec_context_test.go | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go index 8807236bff..f4a8f99937 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go @@ -7,6 +7,7 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/core/mocks" + "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/flytek8s/config" ) func Test_newTaskExecutionMetadata(t *testing.T) { @@ -64,6 +65,69 @@ func Test_newTaskExecutionMetadata(t *testing.T) { "inject-flyte-secrets": "true", }, actual.GetLabels()) }) + + t.Run("Inject exec identity", func(t *testing.T) { + config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: true}) + + existingMetadata := &mocks.TaskExecutionMetadata{} + existingAnnotations := map[string]string{} + existingMetadata.OnGetAnnotations().Return(existingAnnotations) + + existingMetadata.OnGetSecurityContext().Return(core.SecurityContext{RunAs: &core.Identity{ExecutionIdentity: "test-exec-identity"}}) + + existingLabels := map[string]string{ + "existingLabel": "existingLabelValue", + } + existingMetadata.OnGetLabels().Return(existingLabels) + + actual, err := newTaskExecutionMetadata(existingMetadata, &core.TaskTemplate{}) + assert.NoError(t, err) + + assert.Equal(t, 2, len(actual.GetLabels())) + assert.Equal(t, "test-exec-identity", actual.GetLabels()[executionIdentityVariable]) + }) + + t.Run("No inject exec identity", func(t *testing.T) { + config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: false}) + + existingMetadata := &mocks.TaskExecutionMetadata{} + existingAnnotations := map[string]string{} + existingMetadata.OnGetAnnotations().Return(existingAnnotations) + + existingMetadata.OnGetSecurityContext().Return(core.SecurityContext{RunAs: &core.Identity{ExecutionIdentity: "test-exec-identity"}}) + + existingLabels := map[string]string{ + "existingLabel": "existingLabelValue", + } + existingMetadata.OnGetLabels().Return(existingLabels) + + actual, err := newTaskExecutionMetadata(existingMetadata, &core.TaskTemplate{}) + assert.NoError(t, err) + + assert.Equal(t, 1, len(actual.GetLabels())) + assert.Equal(t, "existingLabelValue", actual.GetLabels()["existingLabel"]) + }) + + t.Run("Inject non-existing exec identity", func(t *testing.T) { + config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: true}) // configure to inject exec identity + + existingMetadata := &mocks.TaskExecutionMetadata{} + existingAnnotations := map[string]string{} + existingMetadata.OnGetAnnotations().Return(existingAnnotations) + + existingMetadata.OnGetSecurityContext().Return(core.SecurityContext{RunAs: &core.Identity{}}) // no exec identity + + existingLabels := map[string]string{ + "existingLabel": "existingLabelValue", + } + existingMetadata.OnGetLabels().Return(existingLabels) + + actual, err := newTaskExecutionMetadata(existingMetadata, &core.TaskTemplate{}) + assert.NoError(t, err) + + assert.Equal(t, 1, len(actual.GetLabels())) + assert.Equal(t, "existingLabelValue", actual.GetLabels()["existingLabel"]) + }) } func Test_newTaskExecutionContext(t *testing.T) { From 0ae162e8ec9c5dbd1b2e30dc621445b4c15c510d Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Fri, 22 Dec 2023 15:39:45 +0000 Subject: [PATCH 04/11] Remove duplicate labels injection Signed-off-by: Fabio Graetz --- .../pkg/controller/nodes/task/k8s/task_exec_context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go index 6c672cf474..a7c7d2326b 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go @@ -69,6 +69,6 @@ func newTaskExecutionMetadata(tCtx pluginsCore.TaskExecutionMetadata, taskTmpl * return TaskExecutionMetadata{ TaskExecutionMetadata: tCtx, annotations: utils.UnionMaps(tCtx.GetAnnotations(), secretsMap), - labels: utils.UnionMaps(tCtx.GetLabels(), injectLabels, injectLabels), + labels: utils.UnionMaps(tCtx.GetLabels(), injectLabels), }, nil } From ab6c0730b304b90c34e061d7d2fd28d4ee1c51d2 Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Fri, 22 Dec 2023 16:03:39 +0000 Subject: [PATCH 05/11] Lint Signed-off-by: Fabio Graetz --- .../pkg/controller/nodes/task/k8s/task_exec_context_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go index f4a8f99937..be62f050f3 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go @@ -67,7 +67,7 @@ func Test_newTaskExecutionMetadata(t *testing.T) { }) t.Run("Inject exec identity", func(t *testing.T) { - config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: true}) + assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: true})) existingMetadata := &mocks.TaskExecutionMetadata{} existingAnnotations := map[string]string{} @@ -88,7 +88,7 @@ func Test_newTaskExecutionMetadata(t *testing.T) { }) t.Run("No inject exec identity", func(t *testing.T) { - config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: false}) + assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: false})) existingMetadata := &mocks.TaskExecutionMetadata{} existingAnnotations := map[string]string{} @@ -109,7 +109,7 @@ func Test_newTaskExecutionMetadata(t *testing.T) { }) t.Run("Inject non-existing exec identity", func(t *testing.T) { - config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: true}) // configure to inject exec identity + assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: true})) // configure to inject exec identity existingMetadata := &mocks.TaskExecutionMetadata{} existingAnnotations := map[string]string{} From e0f379461abc3c38b5dcdc3da756f71f5c6f0915 Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Thu, 4 Jan 2024 11:48:50 +0000 Subject: [PATCH 06/11] Revert "Add option in K8s plugin config to inject user identity into pod labels" This reverts commit c42a4a02fd9ba30c2af7d2c42b1a7b5916140fb4. Signed-off-by: Fabio Graetz --- .../go/tasks/pluginmachinery/flytek8s/config/config.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/flyteplugins/go/tasks/pluginmachinery/flytek8s/config/config.go b/flyteplugins/go/tasks/pluginmachinery/flytek8s/config/config.go index 643c37fb43..55f9cfa68c 100644 --- a/flyteplugins/go/tasks/pluginmachinery/flytek8s/config/config.go +++ b/flyteplugins/go/tasks/pluginmachinery/flytek8s/config/config.go @@ -199,9 +199,6 @@ type K8sPluginConfig struct { // SendObjectEvents indicates whether to send k8s object events in TaskExecutionEvent updates (similar to kubectl get events). SendObjectEvents bool `json:"send-object-events" pflag:",If true, will send k8s object events in TaskExecutionEvent updates."` - - // InjectExecutionIdentity indicates whether to inject the execution identity (if set in the workflow) into the pod as a label. - InjectExecutionIdentity bool `json:"inject-execution-identity" pflag:",If true, will inject execution identity into the pod as a label."` } // FlyteCoPilotConfig specifies configuration for the Flyte CoPilot system. FlyteCoPilot, allows running flytekit-less containers From 5e63cbface26f968f5a84d741c8d9786dce5e0d8 Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Thu, 4 Jan 2024 11:59:02 +0000 Subject: [PATCH 07/11] Always inject user identity as pod label if known Signed-off-by: Fabio Graetz --- .../nodes/task/k8s/task_exec_context.go | 11 +++----- .../nodes/task/k8s/task_exec_context_test.go | 26 +------------------ 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go index a7c7d2326b..2bdaeeba58 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go @@ -3,7 +3,6 @@ package k8s import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" pluginsCore "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/core" - "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/flytek8s/config" "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/utils" "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/utils/secrets" ) @@ -45,7 +44,7 @@ func (t TaskExecutionMetadata) GetAnnotations() map[string]string { } // newTaskExecutionMetadata creates a TaskExecutionMetadata with secrets serialized as annotations and a label added -// to trigger the flyte pod webhook. Optionally, the execution identity is injected as a label. +// to trigger the flyte pod webhook. If known, the execution identity is injected as a label. func newTaskExecutionMetadata(tCtx pluginsCore.TaskExecutionMetadata, taskTmpl *core.TaskTemplate) (TaskExecutionMetadata, error) { var err error secretsMap := make(map[string]string) @@ -59,11 +58,9 @@ func newTaskExecutionMetadata(tCtx pluginsCore.TaskExecutionMetadata, taskTmpl * injectLabels[secrets.PodLabel] = secrets.PodLabelValue } - if config.GetK8sPluginConfig().InjectExecutionIdentity { - id := tCtx.GetSecurityContext().RunAs.ExecutionIdentity - if id != "" { - injectLabels[executionIdentityVariable] = id - } + id := tCtx.GetSecurityContext().RunAs.ExecutionIdentity + if id != "" { + injectLabels[executionIdentityVariable] = id } return TaskExecutionMetadata{ diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go index be62f050f3..c15e5978f0 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go @@ -7,7 +7,6 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/core/mocks" - "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/flytek8s/config" ) func Test_newTaskExecutionMetadata(t *testing.T) { @@ -67,7 +66,6 @@ func Test_newTaskExecutionMetadata(t *testing.T) { }) t.Run("Inject exec identity", func(t *testing.T) { - assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: true})) existingMetadata := &mocks.TaskExecutionMetadata{} existingAnnotations := map[string]string{} @@ -87,29 +85,7 @@ func Test_newTaskExecutionMetadata(t *testing.T) { assert.Equal(t, "test-exec-identity", actual.GetLabels()[executionIdentityVariable]) }) - t.Run("No inject exec identity", func(t *testing.T) { - assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: false})) - - existingMetadata := &mocks.TaskExecutionMetadata{} - existingAnnotations := map[string]string{} - existingMetadata.OnGetAnnotations().Return(existingAnnotations) - - existingMetadata.OnGetSecurityContext().Return(core.SecurityContext{RunAs: &core.Identity{ExecutionIdentity: "test-exec-identity"}}) - - existingLabels := map[string]string{ - "existingLabel": "existingLabelValue", - } - existingMetadata.OnGetLabels().Return(existingLabels) - - actual, err := newTaskExecutionMetadata(existingMetadata, &core.TaskTemplate{}) - assert.NoError(t, err) - - assert.Equal(t, 1, len(actual.GetLabels())) - assert.Equal(t, "existingLabelValue", actual.GetLabels()["existingLabel"]) - }) - - t.Run("Inject non-existing exec identity", func(t *testing.T) { - assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{InjectExecutionIdentity: true})) // configure to inject exec identity + t.Run("Empty exec identity", func(t *testing.T) { existingMetadata := &mocks.TaskExecutionMetadata{} existingAnnotations := map[string]string{} From 2d870a974090a33f0aed41c538dc06d355e345f7 Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Thu, 4 Jan 2024 12:01:35 +0000 Subject: [PATCH 08/11] Use hyphen instead of underscore in pod label Signed-off-by: Fabio Graetz --- .../pkg/controller/nodes/task/k8s/task_exec_context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go index 2bdaeeba58..e9230b081e 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go @@ -7,7 +7,7 @@ import ( "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/utils/secrets" ) -const executionIdentityVariable = "execution_identity" +const executionIdentityVariable = "execution-identity" // TaskExecutionContext provides a layer on top of core TaskExecutionContext with a custom TaskExecutionMetadata. type TaskExecutionContext struct { From 4437c4cf7e8fff013de2546a965e13651fc387f0 Mon Sep 17 00:00:00 2001 From: "Fabio M. Graetz, Ph.D" Date: Thu, 4 Jan 2024 22:09:29 +0100 Subject: [PATCH 09/11] Update flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go Signed-off-by: Fabio M. Graetz, Ph.D. Signed-off-by: Fabio Graetz --- .../pkg/controller/nodes/task/k8s/task_exec_context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go index e9230b081e..17bbce5398 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go @@ -59,7 +59,7 @@ func newTaskExecutionMetadata(tCtx pluginsCore.TaskExecutionMetadata, taskTmpl * } id := tCtx.GetSecurityContext().RunAs.ExecutionIdentity - if id != "" { + if len(id) > 0 { injectLabels[executionIdentityVariable] = id } From 965c29a3593fca22e1142a34d1046829f4dabc63 Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Mon, 8 Jan 2024 11:30:28 +0000 Subject: [PATCH 10/11] Fix tests Signed-off-by: Fabio Graetz --- .../pkg/controller/nodes/task/k8s/plugin_manager_test.go | 1 + .../pkg/controller/nodes/task/k8s/task_exec_context_test.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go b/flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go index a96536e7ac..2c7fda0f6e 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go @@ -200,6 +200,7 @@ func getMockTaskExecutionMetadata() pluginsCore.TaskExecutionMetadata { taskExecutionMetadata.On("GetAnnotations").Return(map[string]string{"aKey": "aVal"}) taskExecutionMetadata.On("GetLabels").Return(map[string]string{"lKey": "lVal"}) taskExecutionMetadata.On("GetOwnerReference").Return(metav1.OwnerReference{Name: "x"}) + taskExecutionMetadata.On("GetSecurityContext").Return(core.SecurityContext{RunAs: &core.Identity{}}) id := &pluginsCoreMock.TaskExecutionID{} id.On("GetGeneratedName").Return("test") diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go index c15e5978f0..4e232ddef2 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go @@ -21,6 +21,7 @@ func Test_newTaskExecutionMetadata(t *testing.T) { "existingLabel": "existingLabelValue", } existingMetadata.OnGetLabels().Return(existingLabels) + existingMetadata.OnGetSecurityContext().Return(core.SecurityContext{RunAs: &core.Identity{}}) actual, err := newTaskExecutionMetadata(existingMetadata, &core.TaskTemplate{}) assert.NoError(t, err) @@ -40,6 +41,7 @@ func Test_newTaskExecutionMetadata(t *testing.T) { "existingLabel": "existingLabelValue", } existingMetadata.OnGetLabels().Return(existingLabels) + existingMetadata.OnGetSecurityContext().Return(core.SecurityContext{RunAs: &core.Identity{}}) actual, err := newTaskExecutionMetadata(existingMetadata, &core.TaskTemplate{ SecurityContext: &core.SecurityContext{ From cc4d7c730137c579934c4cb200060dd142d2a640 Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Mon, 8 Jan 2024 11:31:47 +0000 Subject: [PATCH 11/11] Remove duplicate unit test logic Signed-off-by: Fabio Graetz --- .../nodes/task/k8s/task_exec_context_test.go | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go index 4e232ddef2..bf9ca1eadb 100644 --- a/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go +++ b/flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context_test.go @@ -86,26 +86,6 @@ func Test_newTaskExecutionMetadata(t *testing.T) { assert.Equal(t, 2, len(actual.GetLabels())) assert.Equal(t, "test-exec-identity", actual.GetLabels()[executionIdentityVariable]) }) - - t.Run("Empty exec identity", func(t *testing.T) { - - existingMetadata := &mocks.TaskExecutionMetadata{} - existingAnnotations := map[string]string{} - existingMetadata.OnGetAnnotations().Return(existingAnnotations) - - existingMetadata.OnGetSecurityContext().Return(core.SecurityContext{RunAs: &core.Identity{}}) // no exec identity - - existingLabels := map[string]string{ - "existingLabel": "existingLabelValue", - } - existingMetadata.OnGetLabels().Return(existingLabels) - - actual, err := newTaskExecutionMetadata(existingMetadata, &core.TaskTemplate{}) - assert.NoError(t, err) - - assert.Equal(t, 1, len(actual.GetLabels())) - assert.Equal(t, "existingLabelValue", actual.GetLabels()["existingLabel"]) - }) } func Test_newTaskExecutionContext(t *testing.T) {