From 36d2389f23dc832fe962025ad7b2a6cf6ed9bce3 Mon Sep 17 00:00:00 2001 From: Ed Marks <63232030+Marks-Ed@users.noreply.github.com> Date: Wed, 11 Aug 2021 23:18:20 +0100 Subject: [PATCH] fix: use execWf when setting PodMetadata (#6512) Signed-off-by: Ed Marks --- workflow/controller/workflowpod_test.go | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/workflow/controller/workflowpod_test.go b/workflow/controller/workflowpod_test.go index a3b1e2760bec..15b05fffaab4 100644 --- a/workflow/controller/workflowpod_test.go +++ b/workflow/controller/workflowpod_test.go @@ -1584,3 +1584,59 @@ func TestPodMetadataWithWorkflowDefaults(t *testing.T) { assert.Equal(t, "label-value", pod.ObjectMeta.Labels["controller-level-pod-label"]) cancel() } + +func TestPodMetadataWithWorkflowDefaults(t *testing.T) { + cancel, controller := newController() + defer cancel() + + wfDefaultAnnotations := make(map[string]string) + wfDefaultAnnotations["controller-level-pod-annotation"] = "annotation-value" + wfDefaultAnnotations["workflow-level-pod-annotation"] = "set-by-controller" + wfDefaultLabels := make(map[string]string) + wfDefaultLabels["controller-level-pod-label"] = "label-value" + wfDefaultLabels["workflow-level-pod-label"] = "set-by-controller" + controller.Config.WorkflowDefaults = &wfv1.Workflow{ + Spec: wfv1.WorkflowSpec{ + PodMetadata: &wfv1.Metadata{ + Annotations: wfDefaultAnnotations, + Labels: wfDefaultLabels, + }, + }, + } + + wf := wfv1.MustUnmarshalWorkflow(helloWorldWf) + ctx := context.Background() + woc := newWorkflowOperationCtx(wf, controller) + err := woc.setExecWorkflow(ctx) + assert.NoError(t, err) + mainCtr := woc.execWf.Spec.Templates[0].Container + pod, _ := woc.createWorkflowPod(ctx, wf.Name, []apiv1.Container{*mainCtr}, &wf.Spec.Templates[0], &createWorkflowPodOpts{}) + assert.Equal(t, "annotation-value", pod.ObjectMeta.Annotations["controller-level-pod-annotation"]) + assert.Equal(t, "set-by-controller", pod.ObjectMeta.Annotations["workflow-level-pod-annotation"]) + assert.Equal(t, "label-value", pod.ObjectMeta.Labels["controller-level-pod-label"]) + assert.Equal(t, "set-by-controller", pod.ObjectMeta.Labels["workflow-level-pod-label"]) + cancel() // need to cancel to spin up pods with the same name + + cancel, controller = newController() + defer cancel() + controller.Config.WorkflowDefaults = &wfv1.Workflow{ + Spec: wfv1.WorkflowSpec{ + PodMetadata: &wfv1.Metadata{ + Annotations: wfDefaultAnnotations, + Labels: wfDefaultLabels, + }, + }, + } + wf = wfv1.MustUnmarshalWorkflow(wfWithPodMetadata) + ctx = context.Background() + woc = newWorkflowOperationCtx(wf, controller) + err = woc.setExecWorkflow(ctx) + assert.NoError(t, err) + mainCtr = woc.execWf.Spec.Templates[0].Container + pod, _ = woc.createWorkflowPod(ctx, wf.Name, []apiv1.Container{*mainCtr}, &wf.Spec.Templates[0], &createWorkflowPodOpts{}) + assert.Equal(t, "foo", pod.ObjectMeta.Annotations["workflow-level-pod-annotation"]) + assert.Equal(t, "bar", pod.ObjectMeta.Labels["workflow-level-pod-label"]) + assert.Equal(t, "annotation-value", pod.ObjectMeta.Annotations["controller-level-pod-annotation"]) + assert.Equal(t, "label-value", pod.ObjectMeta.Labels["controller-level-pod-label"]) + cancel() +}