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

remote wait: fix "removed" condition #18912

Merged
merged 1 commit into from
Jun 16, 2023
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: 14 additions & 4 deletions pkg/api/handlers/utils/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,21 @@ var notRunningStates = []define.ContainerStatus{
}

func waitRemoved(ctrWait containerWaitFn) (int32, error) {
code, err := ctrWait(define.ContainerStateUnknown)
if err != nil && errors.Is(err, define.ErrNoSuchCtr) {
return code, nil
var code int32
for {
c, err := ctrWait(define.ContainerStateExited)
if errors.Is(err, define.ErrNoSuchCtr) {
// Make sure to wait until the container has been removed.
break
}
if err != nil {
return code, err
}
// If the container doesn't exist, the return code is -1, so
// only set it in case of success.
code = c
}
return code, err
return code, nil
}

func waitNextExit(ctx context.Context, containerName string) (int32, error) {
Expand Down
11 changes: 8 additions & 3 deletions test/apiv2/26-containersWait.at
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ CTR="WaitTestingCtr"

t POST "containers/nonExistent/wait?condition=next-exit" 404

podman create --name "${CTR}" --entrypoint '["true"]' "${IMAGE}"
# Make sure to test a non-zero exit code (see #18889)
podman create --name "${CTR}" "${IMAGE}" sh -c "exit 3"

t POST "containers/${CTR}/wait?condition=non-existent-cond" 400

Expand All @@ -24,7 +25,7 @@ child_pid=$!

# This will block until the background job completes
t POST "containers/${CTR}/wait?condition=next-exit" 200 \
.StatusCode=0 \
.StatusCode=3 \
.Error=null
wait "${child_pid}"

Expand All @@ -41,6 +42,10 @@ fi
child_pid=$!

t POST "containers/${CTR}/wait?condition=removed" 200 \
.StatusCode=0 \
.StatusCode=3 \
.Error=null
# Make sure the container has really been removed after waiting for
# "condition=removed". This check is racy but should flake in case it doesn't
# work correctly.
t POST "containers/${CTR}/wait?condition=next-exit" 404
wait "${child_pid}"