podman: don't restart after kill

Also add a new `StoppedByUser` field to the container-inspect state
which can be useful during debugging and is now also used in the
regression test.  Note that I moved the `false` check one test above
such that we can compare the previous Podman version which should just
be stuck in the `wait $ctr` command since it will continue restarting.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg 2023-09-07 14:56:43 +02:00
parent c17c190f89
commit 589867d716
4 changed files with 19 additions and 1 deletions

View File

@ -292,7 +292,7 @@ func (c *Container) Kill(signal uint) error {
return c.waitForConmonToExitAndSave()
}
return nil
return c.save()
}
// Attach attaches to a container.

View File

@ -140,6 +140,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
CheckpointPath: runtimeInfo.CheckpointPath,
CheckpointLog: runtimeInfo.CheckpointLog,
RestoreLog: runtimeInfo.RestoreLog,
StoppedByUser: c.state.StoppedByUser,
},
Image: config.RootfsImageID,
ImageName: config.RootfsImageName,

View File

@ -228,6 +228,7 @@ type InspectContainerState struct {
CheckpointPath string `json:"CheckpointPath,omitempty"`
RestoreLog string `json:"RestoreLog,omitempty"`
Restored bool `json:"Restored,omitempty"`
StoppedByUser bool `json:"StoppedByUser,omitempty"`
}
// Healthcheck returns the HealthCheckResults. This is used for old podman compat

View File

@ -145,6 +145,8 @@ load helpers
@test "podman wait - exit codes" {
random_name=$(random_string 10)
run_podman create --name=$random_name $IMAGE /no/such/command
run_podman container inspect --format "{{.State.StoppedByUser}}" $random_name
is "$output" "false" "container not marked to be stopped by a user"
# Container never ran -> exit code == 0
run_podman wait $random_name
# Container did not start successfully -> exit code != 0
@ -153,4 +155,18 @@ load helpers
run_podman wait $random_name
}
@test "podman kill - no restart" {
ctr=$(random_string 10)
run_podman run -d --restart=always --name=$ctr $IMAGE \
sh -c "trap 'exit 42' SIGTERM; echo READY; while :; do sleep 0.2; done"
run_podman container inspect --format "{{.State.Status}}" $ctr
is "$output" "running" "make sure container is running"
# Send SIGTERM and make sure the container exits.
run_podman kill -s=TERM $ctr
run_podman wait $ctr
is "$output" "42" "container exits with 42 on receiving SIGTERM"
run_podman container inspect --format "{{.State.StoppedByUser}}" $ctr
is "$output" "true" "container is marked to be stopped by a user"
}
# vim: filetype=sh