Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): Carry-over labels for re-submitted workflows. Fixes #3622 #3638

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions workflow/util/util.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)
}
})

}