Skip to content

Commit 56544b8

Browse files
committed
fix(controller):
1. fix inline artifact outputs missing finalizers 2. fix inline step missing template name Signed-off-by: joey <[email protected]>
1 parent 90cfa7e commit 56544b8

File tree

3 files changed

+123
-3
lines changed

3 files changed

+123
-3
lines changed

workflow/controller/artifact_gc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ func (woc *wfOperationCtx) HasArtifactGC() bool {
9090
return true
9191
}
9292
}
93+
for _, steps := range template.Steps {
94+
for _, step := range steps.Steps {
95+
if step.Inline != nil {
96+
for _, artifact := range step.Inline.Outputs.Artifacts {
97+
strategy := woc.execWf.GetArtifactGCStrategy(&artifact)
98+
if strategy != wfv1.ArtifactGCStrategyUndefined && strategy != wfv1.ArtifactGCNever {
99+
return true
100+
}
101+
}
102+
}
103+
}
104+
}
93105
}
94106

95107
// need to go to woc.wf.Status.StoredTemplates in the case of a Step referencing a WorkflowTemplate

workflow/controller/artifact_gc_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,108 @@ func TestWorkflowHasArtifactGC(t *testing.T) {
723723
}
724724

725725
}
726+
727+
func TestInlineWorkflowHasArtifactGC(t *testing.T) {
728+
tests := []struct {
729+
name string
730+
workflowArtGCStrategySpec string
731+
artifactGCStrategySpec string
732+
expectedResult bool
733+
}{
734+
{
735+
name: "WorkflowSpecGC_Completion",
736+
workflowArtGCStrategySpec: `
737+
artifactGC:
738+
strategy: OnWorkflowCompletion`,
739+
artifactGCStrategySpec: "",
740+
expectedResult: true,
741+
},
742+
{
743+
name: "ArtifactSpecGC_Completion",
744+
workflowArtGCStrategySpec: "",
745+
artifactGCStrategySpec: `
746+
artifactGC:
747+
strategy: OnWorkflowCompletion`,
748+
expectedResult: true,
749+
},
750+
{
751+
name: "WorkflowSpecGC_Deletion",
752+
workflowArtGCStrategySpec: `
753+
artifactGC:
754+
strategy: OnWorkflowDeletion`,
755+
artifactGCStrategySpec: "",
756+
expectedResult: true,
757+
},
758+
{
759+
name: "ArtifactSpecGC_Deletion",
760+
workflowArtGCStrategySpec: "",
761+
artifactGCStrategySpec: `
762+
artifactGC:
763+
strategy: OnWorkflowDeletion`,
764+
expectedResult: true,
765+
},
766+
{
767+
name: "NoGC",
768+
workflowArtGCStrategySpec: "",
769+
artifactGCStrategySpec: "",
770+
expectedResult: false,
771+
},
772+
{
773+
name: "WorkflowSpecGC_None",
774+
workflowArtGCStrategySpec: `
775+
artifactGC:
776+
strategy: ""`,
777+
artifactGCStrategySpec: "",
778+
expectedResult: false,
779+
},
780+
{
781+
name: "ArtifactSpecGC_None",
782+
workflowArtGCStrategySpec: `
783+
artifactGC:
784+
strategy: OnWorkflowDeletion`,
785+
artifactGCStrategySpec: `
786+
artifactGC:
787+
strategy: Never`,
788+
expectedResult: false,
789+
},
790+
}
791+
792+
for _, tt := range tests {
793+
t.Run(tt.name, func(t *testing.T) {
794+
795+
workflowSpec := fmt.Sprintf(`apiVersion: argoproj.io/v1alpha1
796+
kind: Workflow
797+
metadata:
798+
generateName: artifact-passing-
799+
spec:
800+
entrypoint: whalesay
801+
%s
802+
templates:
803+
- name: whalesay
804+
steps:
805+
- - name: generate-artifact
806+
inline:
807+
container:
808+
image: docker/whalesay:latest
809+
command: [sh, -c]
810+
args: ["sleep 1; cowsay hello world | tee /tmp/hello_world.txt"]
811+
outputs:
812+
artifacts:
813+
- name: out
814+
path: /out
815+
s3:
816+
key: out
817+
%s`, tt.workflowArtGCStrategySpec, tt.artifactGCStrategySpec)
818+
819+
wf := wfv1.MustUnmarshalWorkflow(workflowSpec)
820+
ctx := logging.TestContext(t.Context())
821+
cancel, controller := newController(ctx, wf)
822+
defer cancel()
823+
woc := newWorkflowOperationCtx(ctx, wf, controller)
824+
825+
hasArtifact := woc.HasArtifactGC()
826+
827+
assert.Equal(t, tt.expectedResult, hasArtifact)
828+
})
829+
}
830+
}

workflow/controller/steps.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (woc *wfOperationCtx) executeSteps(ctx context.Context, nodeName string, tm
7070
{
7171
sgNode, err := woc.wf.GetNodeByName(sgNodeName)
7272
if err != nil {
73-
_ = woc.initializeNode(ctx, sgNodeName, wfv1.NodeTypeStepGroup, stepTemplateScope, &wfv1.WorkflowStep{}, stepsCtx.boundaryID, wfv1.NodeRunning, &wfv1.NodeFlag{}, true)
73+
_ = woc.initializeNode(ctx, sgNodeName, wfv1.NodeTypeStepGroup, stepTemplateScope, &wfv1.WorkflowStep{Template: tmpl.Name}, stepsCtx.boundaryID, wfv1.NodeRunning, &wfv1.NodeFlag{}, true)
7474
} else if !sgNode.Fulfilled() {
7575
_ = woc.markNodePhase(ctx, sgNodeName, wfv1.NodeRunning)
7676
}
@@ -107,7 +107,7 @@ func (woc *wfOperationCtx) executeSteps(ctx context.Context, nodeName string, tm
107107
}
108108
}
109109

110-
sgNode, err := woc.executeStepGroup(ctx, stepGroup.Steps, sgNodeName, &stepsCtx)
110+
sgNode, err := woc.executeStepGroup(ctx, stepGroup.Steps, sgNodeName, &stepsCtx, tmpl.Name)
111111
if err != nil {
112112
return woc.markNodeError(ctx, sgNodeName, err), nil
113113
}
@@ -229,7 +229,7 @@ func (woc *wfOperationCtx) updateOutboundNodes(ctx context.Context, nodeName str
229229

230230
// executeStepGroup examines a list of parallel steps and executes them in parallel.
231231
// Handles referencing of variables in scope, expands `withItem` clauses, and evaluates `when` expressions
232-
func (woc *wfOperationCtx) executeStepGroup(ctx context.Context, stepGroup []wfv1.WorkflowStep, sgNodeName string, stepsCtx *stepsContext) (*wfv1.NodeStatus, error) {
232+
func (woc *wfOperationCtx) executeStepGroup(ctx context.Context, stepGroup []wfv1.WorkflowStep, sgNodeName string, stepsCtx *stepsContext, tmplName string) (*wfv1.NodeStatus, error) {
233233
node, err := woc.wf.GetNodeByName(sgNodeName)
234234
if err != nil {
235235
return nil, err
@@ -259,6 +259,9 @@ func (woc *wfOperationCtx) executeStepGroup(ctx context.Context, stepGroup []wfv
259259

260260
// Kick off all parallel steps in the group
261261
for _, step := range stepGroup {
262+
if step.Template == "" && step.TemplateRef == nil {
263+
step.Template = tmplName
264+
}
262265
childNodeName := fmt.Sprintf("%s.%s", sgNodeName, step.Name)
263266

264267
// Check the step's when clause to decide if it should execute

0 commit comments

Comments
 (0)