Skip to content

Commit

Permalink
fix: pod metadata patch
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 e0070bf commit 762c791
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
28 changes: 24 additions & 4 deletions workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,23 +486,43 @@ func (wfc *WorkflowController) processNextPodCleanupItem(ctx context.Context) bo
return err
}
case labelPodCompleted:
_, err := pods.Patch(
data, err := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
common.LabelKeyCompleted: "true",
},
"finalizers": []string{},
},
})
if err != nil {
return err
}

_, err = pods.Patch(
ctx,
podName,
types.MergePatchType,
[]byte(`{"metadata": {"labels": {"workflows.argoproj.io/completed": "true"}, "finalizers": []}}`),
data,
metav1.PatchOptions{},
)
if err != nil {
return err
}
case deletePod:
// remove the finalizer to allow the pod to be deleted
_, err := pods.Patch(
data, err := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"finalizers": []string{},
},
})
if err != nil {
return err
}
_, err = pods.Patch(
ctx,
podName,
types.MergePatchType,
[]byte(`{"metadata": {"finalizers": []}}`),
data,
metav1.PatchOptions{},
)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions workflow/controller/taskset.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,16 @@ func (woc *wfOperationCtx) createTaskSet(ctx context.Context) error {

if apierr.IsConflict(err) || apierr.IsAlreadyExists(err) {
woc.log.Debug("patching the exiting taskset")
wfFinalizers := woc.wf.Finalizers
if woc.wf.Status.Fulfilled() {
wfFinalizers = []string{}
}
spec := map[string]interface{}{
"metadata": metav1.ObjectMeta{
Labels: map[string]string{
common.LabelKeyCompleted: strconv.FormatBool(woc.wf.Status.Fulfilled()),
},
Finalizers: wfFinalizers,
},
"spec": wfv1.WorkflowTaskSetSpec{Tasks: woc.taskSet},
}
Expand Down

0 comments on commit 762c791

Please sign in to comment.