From 8e05c823a5ea56b1add71c23f5b94cb61923e571 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Tue, 1 Oct 2024 14:09:52 -0400 Subject: [PATCH] docker: fix script check execution In #24095 we made a fix for non-streaming exec into Docker tasks for script checks and `change_mode = "script"`, but didn't complete E2E testing. We need to use `ContainerExecAttach` in the new API in order to get stdout/stderr from tasklets, but the previous `ContainerExecStart` call will prevent this from running successfully with an error that the exec has already run. * Ref: [NET-11202 (comment)](https://hashicorp.atlassian.net/browse/NET-11202?focusedCommentId=551618) * This has shipped in Nomad 1.9.0-beta.1 but not production yet. * This should fix the remaining issues in nightly E2E for Docker. --- drivers/docker/handle.go | 12 +++--------- e2e/consul/input/on_update_check_restart.nomad | 2 -- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/docker/handle.go b/drivers/docker/handle.go index 4f144a14d63..968fe393a8b 100644 --- a/drivers/docker/handle.go +++ b/drivers/docker/handle.go @@ -105,17 +105,11 @@ func (h *taskHandle) Exec(ctx context.Context, cmd string, args []string) (*driv Detach: false, Tty: false, } - if err := h.dockerClient.ContainerExecStart(ctx, exec.ID, startOpts); err != nil { - return nil, err - } // hijack exec output streams - hijacked, err := h.dockerClient.ContainerExecAttach(ctx, exec.ID, containerapi.ExecStartOptions{ - Detach: false, - Tty: false, - }) + hijacked, err := h.dockerClient.ContainerExecAttach(ctx, exec.ID, startOpts) if err != nil { - return nil, fmt.Errorf("failed to attach to exec: %v", err) + return nil, fmt.Errorf("failed to attach to exec object: %w", err) } _, err = stdcopy.StdCopy(stdout, stderr, hijacked.Reader) @@ -128,7 +122,7 @@ func (h *taskHandle) Exec(ctx context.Context, cmd string, args []string) (*driv execResult.Stderr = stderr.Bytes() res, err := h.dockerClient.ContainerExecInspect(ctx, exec.ID) if err != nil { - return execResult, err + return execResult, fmt.Errorf("failed to inspect exit code of exec object: %w", err) } execResult.ExitResult.ExitCode = res.ExitCode diff --git a/e2e/consul/input/on_update_check_restart.nomad b/e2e/consul/input/on_update_check_restart.nomad index a8eadfb9215..3aa22e32868 100644 --- a/e2e/consul/input/on_update_check_restart.nomad +++ b/e2e/consul/input/on_update_check_restart.nomad @@ -48,7 +48,6 @@ job "test" { on_update = "ignore_warnings" args = [ - "-c", "/local/ready.sh" ] @@ -95,4 +94,3 @@ EOT } } } -