Skip to content

Commit

Permalink
feat: add finalizer to workflow pod to prevent "pod deleted"
Browse files Browse the repository at this point in the history
Signed-off-by: Rohan Kumar <rohankmr414@gmail.com>
  • Loading branch information
rohankmr414 committed Jul 21, 2022
1 parent 57bac33 commit e0070bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions workflow/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ const (
ErrDeadlineExceeded = "DeadlineExceeded"

ConfigMapName = "workflow-controller-configmap"

WorkflowFinalizer = "argoproj.io/workflow-finalizer"
)

// AnnotationKeyKillCmd specifies the command to use to kill to container, useful for injected sidecars
Expand Down
15 changes: 13 additions & 2 deletions workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,26 @@ func (wfc *WorkflowController) processNextPodCleanupItem(ctx context.Context) bo
ctx,
podName,
types.MergePatchType,
[]byte(`{"metadata": {"labels": {"workflows.argoproj.io/completed": "true"}}}`),
[]byte(`{"metadata": {"labels": {"workflows.argoproj.io/completed": "true"}, "finalizers": []}}`),
metav1.PatchOptions{},
)
if err != nil {
return err
}
case deletePod:
// remove the finalizer to allow the pod to be deleted
_, err := pods.Patch(
ctx,
podName,
types.MergePatchType,
[]byte(`{"metadata": {"finalizers": []}}`),
metav1.PatchOptions{},
)
if err != nil {
return err
}
propagation := metav1.DeletePropagationBackground
err := pods.Delete(ctx, podName, metav1.DeleteOptions{
err = pods.Delete(ctx, podName, metav1.DeleteOptions{
PropagationPolicy: &propagation,
GracePeriodSeconds: wfc.Config.PodGCGracePeriodSeconds,
})
Expand Down
1 change: 1 addition & 0 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(woc.wf, wfv1.SchemeGroupVersion.WithKind(workflow.WorkflowKind)),
},
Finalizers: []string{common.WorkflowFinalizer},
},
Spec: apiv1.PodSpec{
RestartPolicy: apiv1.RestartPolicyNever,
Expand Down

0 comments on commit e0070bf

Please sign in to comment.