Skip to content

Commit

Permalink
fix: mark all its children(container) as deleted if pod deleted. Fixes
Browse files Browse the repository at this point in the history
…#13951

Signed-off-by: oninowang <[email protected]>
  • Loading branch information
jswxstw authored and oninowang committed Dec 9, 2024
1 parent 10aaf3e commit e6c935c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 24 additions & 11 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,17 +1234,8 @@ func (woc *wfOperationCtx) podReconciliation(ctx context.Context) (error, bool)
woc.updated = true
}
woc.markNodeError(node.Name, errors.New("", "pod deleted"))
// Set pod's child(container) error if pod deleted
for _, childNodeID := range node.Children {
childNode, err := woc.wf.Status.Nodes.Get(childNodeID)
if err != nil {
woc.log.Errorf("was unable to obtain node for %s", childNodeID)
continue
}
if childNode.Type == wfv1.NodeTypeContainer {
woc.markNodeError(childNode.Name, errors.New("", "container deleted"))
}
}
// Mark all its children(container) as deleted if pod deleted
woc.markAllContainersDeleted(node.ID)
}
}
return nil, !taskResultIncomplete
Expand All @@ -1262,6 +1253,28 @@ func recentlyStarted(node wfv1.NodeStatus) bool {
return time.Since(node.StartedAt.Time) <= envutil.LookupEnvDurationOr("RECENTLY_STARTED_POD_DURATION", 10*time.Second)
}

// markAllContainersDeleted mark all its children(container) as deleted
func (woc *wfOperationCtx) markAllContainersDeleted(nodeID string) {
node, err := woc.wf.Status.Nodes.Get(nodeID)
if err != nil {
woc.log.Errorf("was unable to obtain node for %s", nodeID)
return
}

for _, childNodeID := range node.Children {
childNode, err := woc.wf.Status.Nodes.Get(childNodeID)
if err != nil {
woc.log.Errorf("was unable to obtain node for %s", childNodeID)
continue
}
if childNode.Type == wfv1.NodeTypeContainer {
woc.markNodeError(childNode.Name, errors.New("", "container deleted"))
// Recursively mark successor node(container) as deleted
woc.markAllContainersDeleted(childNodeID)
}
}
}

// shouldPrintPodSpec return eligible to print to the pod spec
func (woc *wfOperationCtx) shouldPrintPodSpec(node *wfv1.NodeStatus) bool {
return woc.controller.Config.PodSpecLogStrategy.AllPods ||
Expand Down
2 changes: 2 additions & 0 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11194,6 +11194,8 @@ spec:
- '-c'
- sleep 9000
resources: {}
dependencies:
- main
entrypoint: init
arguments: {}
ttlStrategy:
Expand Down

0 comments on commit e6c935c

Please sign in to comment.