From f77780f5bdeb875506b4f619b63c40295b66810a Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Thu, 30 Jul 2020 09:28:52 -0700 Subject: [PATCH] fix(controller): Carry-over labels for re-submitted workflows. Fixes #3622 (#3638) --- workflow/util/util.go | 9 +++++---- workflow/util/util_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/workflow/util/util.go b/workflow/util/util.go index d768880f267c..16ac41021066 100644 --- a/workflow/util/util.go +++ b/workflow/util/util.go @@ -546,15 +546,16 @@ func FormulateResubmitWorkflow(wf *wfv1.Workflow, memoized bool) (*wfv1.Workflow newWF.Spec.Shutdown = "" // carry over user labels and annotations from previous workflow. - // skip any argoproj.io labels except for the controller instanceID label. if newWF.ObjectMeta.Labels == nil { newWF.ObjectMeta.Labels = make(map[string]string) } for key, val := range wf.ObjectMeta.Labels { - if strings.HasPrefix(key, workflow.WorkflowFullName+"/") && key != common.LabelKeyControllerInstanceID { - continue + switch key { + case common.LabelKeyCreator, common.LabelKeyPhase, common.LabelKeyCompleted: + // ignore + default: + newWF.ObjectMeta.Labels[key] = val } - newWF.ObjectMeta.Labels[key] = val } // Append an additional label so it's easy for user to see the // name of the original workflow that has been resubmitted. diff --git a/workflow/util/util_test.go b/workflow/util/util_test.go index 4a6a798f6544..fbf7ad5b9ba8 100644 --- a/workflow/util/util_test.go +++ b/workflow/util/util_test.go @@ -15,6 +15,7 @@ import ( wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1" fakeClientset "github.com/argoproj/argo/pkg/client/clientset/versioned/fake" + "github.com/argoproj/argo/workflow/common" hydratorfake "github.com/argoproj/argo/workflow/hydrator/fake" ) @@ -521,3 +522,33 @@ func TestApplySubmitOpts(t *testing.T) { } }) } + +func TestFormulateResubmitWorkflow(t *testing.T) { + t.Run("Labels", func(t *testing.T) { + wf := &wfv1.Workflow{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + common.LabelKeyControllerInstanceID: "1", + common.LabelKeyClusterWorkflowTemplate: "1", + common.LabelKeyCronWorkflow: "1", + common.LabelKeyWorkflowTemplate: "1", + common.LabelKeyCreator: "1", + common.LabelKeyPhase: "1", + common.LabelKeyCompleted: "1", + }, + }, + } + wf, err := FormulateResubmitWorkflow(wf, false) + if assert.NoError(t, err) { + assert.Contains(t, wf.GetLabels(), common.LabelKeyControllerInstanceID) + assert.Contains(t, wf.GetLabels(), common.LabelKeyClusterWorkflowTemplate) + assert.Contains(t, wf.GetLabels(), common.LabelKeyCronWorkflow) + assert.Contains(t, wf.GetLabels(), common.LabelKeyWorkflowTemplate) + assert.NotContains(t, wf.GetLabels(), common.LabelKeyCreator) + assert.NotContains(t, wf.GetLabels(), common.LabelKeyPhase) + assert.NotContains(t, wf.GetLabels(), common.LabelKeyCompleted) + assert.Contains(t, wf.GetLabels(), common.LabelKeyPreviousWorkflowName) + } + }) + +}