Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(executor): Delegate PNS wait to K8SAPI executor. #5307

Merged
merged 3 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions workflow/executor/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,21 @@ func isTerminated(ctx context.Context, c KubernetesClientInterface, containerNam
if err != nil {
return false, err
}
for _, s := range containerStatus {
log.Debugf("%q %v", s.Name, s.State.Terminated)
if s.State.Terminated == nil && slice.ContainsString(containerNames, s.Name) {
return false, nil
return AllTerminated(containerStatus, containerNames), nil
}

func AllTerminated(containerStatuses []v1.ContainerStatus, containerNames []string) bool {
terminated := make(map[string]bool)
// I've seen a few cases where containers are missing from container status just after a pod started.
for _, c := range containerStatuses {
terminated[c.Name] = c.State.Terminated != nil
}
for _, n := range containerNames {
if !terminated[n] {
return false
}
}
return true, nil
return true
}

// TerminatePodWithContainerID invoke the given SIG against the PID1 of the container.
Expand Down
9 changes: 2 additions & 7 deletions workflow/executor/k8sapi/k8sapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
restclient "k8s.io/client-go/rest"

"github.com/argoproj/argo-workflows/v3/errors"
"github.com/argoproj/argo-workflows/v3/util/slice"
"github.com/argoproj/argo-workflows/v3/workflow/executor/common"
)

type K8sAPIExecutor struct {
Expand Down Expand Up @@ -58,12 +58,7 @@ func (k *K8sAPIExecutor) GetExitCode(ctx context.Context, containerName string)
// Wait for the container to complete
func (k *K8sAPIExecutor) Wait(ctx context.Context, containerNames, sidecarNames []string) error {
Copy link
Member

@sarabala1979 sarabala1979 Mar 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we terminate Sidecar containers also?

return k.Until(ctx, func(pod *corev1.Pod) bool {
for _, s := range pod.Status.ContainerStatuses {
if s.State.Terminated == nil && slice.ContainsString(containerNames, s.Name) {
return false
}
}
return true
return common.AllTerminated(pod.Status.ContainerStatuses, containerNames)
})
}

Expand Down
12 changes: 6 additions & 6 deletions workflow/executor/pns/pns.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ func (p *PNSExecutor) Wait(ctx context.Context, containerNames, sidecarNames []s
time.Sleep(1 * time.Second)
}

if !p.haveContainerPIDs(containerNames) {
log.Info("container PIDs still unknown (maybe short running container, or late starting)")
return p.K8sAPIExecutor.Wait(ctx, containerNames, sidecarNames)
}

OUTER:
for _, containerName := range containerNames {
Copy link
Contributor Author

@alexec alexec Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very rarely, containers can successfully complete, but the Kubernetes API does not yet know about it, so kubectl logs will then fail, resulting in the wait container failing.

I don't see any easy way around this, so this reverts us to how v2.12.

It's a shame to lose this performance boost, but a much worse shame to have unpredictable workflow failures.

pid := p.getContainerPID(containerName)
if pid == 0 {
log.Infof("container %q pid unknown - maybe short running, or late starting container", containerName)
continue
}
log.Infof("Waiting for %q pid %d to complete", containerName, pid)
for {
select {
Expand All @@ -184,7 +183,8 @@ OUTER:
}
}
}
return nil

return p.K8sAPIExecutor.Wait(ctx, containerNames, sidecarNames)
}

// pollRootProcesses will poll /proc for root pids (pids without parents) in a tight loop, for the
Expand Down