Skip to content

Commit

Permalink
fix(controller): Carry-over labels for re-submitted workflows. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Jul 30, 2020
1 parent 3f3a4c9 commit f77780f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
9 changes: 5 additions & 4 deletions workflow/util/util.go
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions workflow/util/util_test.go
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
})

}

0 comments on commit f77780f

Please sign in to comment.