Skip to content

Commit

Permalink
fix(executor): Fix docker "created" issue. Fixes #5252 (#5249)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <[email protected]>
  • Loading branch information
alexec authored Mar 2, 2021
1 parent 38b0f55 commit 9b538d9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions workflow/executor/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (d *DockerExecutor) syncContainerIDs(ctx context.Context, containerNames []
"ps",
"--all", // container could have already exited, but there could also have been two containers for the same pod (old container not yet cleaned-up)
"--no-trunc", // display long container IDs
"--format={{.Label \"io.kubernetes.container.name\"}}={{.ID}}",
"--format={{.Status}}|{{.Label \"io.kubernetes.container.name\"}}|{{.ID}}", // similar to `Up 3 hours,main,035a98c4e72e`
// https://github.com/kubernetes/kubernetes/blob/ca6bdba014f0a98efe0e0dd4e15f57d1c121d6c9/pkg/kubelet/dockertools/labels.go#L37
"--filter=label=io.kubernetes.pod.namespace="+d.namespace,
"--filter=label=io.kubernetes.pod.name="+d.podName,
Expand All @@ -215,13 +215,23 @@ func (d *DockerExecutor) syncContainerIDs(ctx context.Context, containerNames []
return err
}
for _, l := range strings.Split(string(output), "\n") {
parts := strings.Split(strings.TrimSpace(l), "=")
if len(parts) != 2 {
parts := strings.Split(strings.TrimSpace(l), "|")
if len(parts) != 3 {
continue
}
containerName := parts[0]
containerID := parts[1]
status := strings.SplitN(parts[0], " ", 2)[0] // Created,Exited,Up,
containerName := parts[1]
containerID := parts[2]
if d.containers[containerName] == "" && containerID != "" {
if status == "Created" { // for "Created" we must check to see if it was an early (non-zero) exit
output, err := common.RunCommand("docker", "inspect", containerID, "--format={{.State.ExitCode}}")
if err != nil {
return err
}
if strings.TrimSpace(string(output)) == "0" { // this remain "0" until it is not "Created" anymore
continue
}
}
d.containers[containerName] = containerID
log.Infof("mapped container name %q to container ID %q", containerName, containerID)
}
Expand Down

0 comments on commit 9b538d9

Please sign in to comment.