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): Always poll for Docker injected sidecars. Resolves #5448 #5479

Merged
merged 9 commits into from
Mar 24, 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
37 changes: 37 additions & 0 deletions test/e2e/failed_main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// +build functional

package e2e

import (
"testing"

"github.com/stretchr/testify/suite"

"github.com/argoproj/argo-workflows/v3/test/e2e/fixtures"
)

type FailedMainSuite struct {
fixtures.E2ESuite
}

func (s *FailedMainSuite) TestFailedMain() {
s.Given().
Workflow(`
metadata:
generateName: failed-main-
spec:
entrypoint: main
templates:
- name: main
container:
image: argoproj/argosay:v2
args: [ exit, "1" ]
`).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeFailed)
}

func TestFailedMainSuite(t *testing.T) {
suite.Run(t, new(FailedMainSuite))
}
32 changes: 21 additions & 11 deletions workflow/executor/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,19 @@ func (d *DockerExecutor) GetExitCode(ctx context.Context, containerName string)
}

func (d *DockerExecutor) Wait(ctx context.Context, containerNames []string) error {
err := d.syncContainerIDs(ctx, containerNames)
if err != nil {
return err
go func() {
err := d.pollContainerIDs(ctx, containerNames)
Copy link
Member

@whynowy whynowy Mar 22, 2021

Choose a reason for hiding this comment

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

If pollContainerIDs returns with a timeout error, it could stay at for !d.haveContainers(containerNames) forever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

poll now runs for ever

if err != nil {
log.WithError(err).Error("failed to poll container IDs")
}
}()
for !d.haveContainers(containerNames) {
select {
case <-ctx.Done():
return ctx.Err()
default:
time.Sleep(1 * time.Second)
}
}
containerIDs, err := d.getContainerIDs(containerNames)
if err != nil {
Expand All @@ -197,7 +207,7 @@ func (d *DockerExecutor) Wait(ctx context.Context, containerNames []string) erro
return err
}

func (d *DockerExecutor) syncContainerIDs(ctx context.Context, containerNames []string) error {
func (d *DockerExecutor) pollContainerIDs(ctx context.Context, containerNames []string) error {
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -247,13 +257,14 @@ func (d *DockerExecutor) syncContainerIDs(ctx context.Context, containerNames []
containerStatus[containerName] = status
log.Infof("mapped container name %q to container ID %q (created at %v, status %s)", containerName, containerID, createdAt, status)
}
// sidecars start after the main containers, so we can't just exit once we know about all the main containers,
// we need a bit more time
if d.haveContainers(containerNames) && time.Since(started) > 3*time.Second {
return nil
}
}
time.Sleep(1 * time.Second) // this is a hard-loop because containers can run very short periods of time
// sidecars start after the main containers, so we can't just exit once we know about all the main containers,
// we need a bit more time
if !d.haveContainers(containerNames) || time.Since(started) < 30*time.Second {
time.Sleep(1 * time.Second) // this is a hard-loop because containers can run very short periods of time
} else {
time.Sleep(10 * time.Second)
}
}
}

Expand Down Expand Up @@ -291,7 +302,6 @@ func (d *DockerExecutor) Kill(ctx context.Context, containerNames []string, term
_, err = common.RunCommand("docker", killArgs...)
if err != nil {
log.Warningf("Ignored error from 'docker kill --signal TERM': %s", err)
return nil
}
waitArgs := append([]string{"wait"}, containerIDs...)
waitCmd := exec.Command("docker", waitArgs...)
Expand Down