Skip to content

Commit

Permalink
fix: PodGC works with WorkflowTemplate. Fixes #8448 (#8452)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec committed Apr 22, 2022
1 parent 35492a1 commit 9854dd3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
20 changes: 20 additions & 0 deletions test/e2e/pod_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,26 @@ spec:
WaitForPod(fixtures.PodDeleted)
}

func (s *PodCleanupSuite) TestOnWorkflowTemplate() {
s.Given().
WorkflowTemplate(`
metadata:
name: test-pod-cleanup
spec:
podGC:
strategy: OnWorkflowCompletion
entrypoint: main
templates:
- name: main
container:
image: argoproj/argosay:v2
`).
When().
CreateWorkflowTemplates().
SubmitWorkflowsFromWorkflowTemplates().
WaitForPod(fixtures.PodDeleted)
}

func TestPodCleanupSuite(t *testing.T) {
suite.Run(t, new(PodCleanupSuite))
}
32 changes: 32 additions & 0 deletions tmp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: pod-gc-strategy
spec:
entrypoint: pod-gc-strategy
podGC:
# Pod GC strategy must be one of the following:
# * OnPodCompletion - delete pods immediately when pod is completed (including errors/failures)
# * OnPodSuccess - delete pods immediately when pod is successful
# * OnWorkflowCompletion - delete pods when workflow is completed
# * OnWorkflowSuccess - delete pods when workflow is successful
strategy: "OnWorkflowCompletion"

templates:
- name: pod-gc-strategy
steps:
- - name: fail
template: fail
- name: succeed
template: succeed

- name: fail
container:
image: alpine:3.7
command: [sh, -c]
args: ["exit 1"]

- name: succeed
container:
image: alpine:3.7
command: [sh, -c]
3 changes: 2 additions & 1 deletion workflow/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ spec:
makePodsPhase(ctx, woc, apiv1.PodSucceeded)

woc.operate(ctx)
controller.processNextPodCleanupItem(ctx)
assert.True(t, controller.processNextPodCleanupItem(ctx))
assert.True(t, controller.processNextPodCleanupItem(ctx))
assert.Equal(t, wfv1.WorkflowSucceeded, woc.wf.Status.Phase)
podCleanupKey := "test/my-wf/labelPodCompleted"
assert.Equal(t, 0, controller.podCleanupQueue.NumRequeues(podCleanupKey))
Expand Down
2 changes: 1 addition & 1 deletion workflow/controller/pod_cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (woc *wfOperationCtx) queuePodsForCleanup() {
for _, obj := range objs {
pod := obj.(*apiv1.Pod)
nodeID := woc.nodeID(pod)
if !woc.execWf.Status.Nodes[nodeID].Phase.Fulfilled() {
if !woc.wf.Status.Nodes[nodeID].Phase.Fulfilled() {
continue
}
switch determinePodCleanupAction(selector, pod.Labels, strategy, workflowPhase, pod.Status.Phase) {
Expand Down

0 comments on commit 9854dd3

Please sign in to comment.