aboutsummaryrefslogtreecommitdiff
path: root/test/system
diff options
context:
space:
mode:
authorValentin Rothberg <vrothberg@redhat.com>2022-04-13 16:21:21 +0200
committerValentin Rothberg <vrothberg@redhat.com>2022-05-02 13:29:59 +0200
commit4eff0c8cf284a6007122aec731e4d97059750166 (patch)
treecdbfee34bd64bb295556667129a6a3c5db9b4612 /test/system
parent77d872ea38ec7b685ec99efe6688d1793c9fa256 (diff)
downloadpodman-4eff0c8cf284a6007122aec731e4d97059750166.tar.gz
podman-4eff0c8cf284a6007122aec731e4d97059750166.tar.bz2
podman-4eff0c8cf284a6007122aec731e4d97059750166.zip
pod: add exit policies
Add the notion of an "exit policy" to a pod. This policy controls the behaviour when the last container of pod exits. Initially, there are two policies: - "continue" : the pod continues running. This is the default policy when creating a pod. - "stop" : stop the pod when the last container exits. This is the default behaviour for `play kube`. In order to implement the deferred stop of a pod, add a worker queue to the libpod runtime. The queue will pick up work items and in this case helps resolve dead locks that would otherwise occur if we attempted to stop a pod during container cleanup. Note that the default restart policy of `play kube` is "Always". Hence, in order to really solve #13464, the YAML files must set a custom restart policy; the tests use "OnFailure". Fixes: #13464 Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
Diffstat (limited to 'test/system')
-rw-r--r--test/system/200-pod.bats69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/system/200-pod.bats b/test/system/200-pod.bats
index 64f95f723..39982848f 100644
--- a/test/system/200-pod.bats
+++ b/test/system/200-pod.bats
@@ -406,7 +406,76 @@ EOF
run_podman pod inspect test --format {{.InfraConfig.HostNetwork}}
is "$output" "true" "Host network sharing with only ipc should be true"
run_podman pod rm test
+}
+
+# Wait for the pod (1st arg) to transition into the state (2nd arg)
+function _ensure_pod_state() {
+ for i in {0..5}; do
+ run_podman pod inspect $1 --format "{{.State}}"
+ if [[ $output == "$2" ]]; then
+ break
+ fi
+ sleep 0.5
+ done
+
+ is "$output" "$2" "unexpected pod state"
+}
+
+@test "pod exit policies" {
+ # Test setting exit policies
+ run_podman pod create
+ podID="$output"
+ run_podman pod inspect $podID --format "{{.ExitPolicy}}"
+ is "$output" "continue" "default exit policy"
+ run_podman pod rm $podID
+
+ run_podman pod create --exit-policy stop
+ podID="$output"
+ run_podman pod inspect $podID --format "{{.ExitPolicy}}"
+ is "$output" "stop" "custom exit policy"
+ run_podman pod rm $podID
+
+ run_podman 125 pod create --exit-policy invalid
+ is "$output" "Error: .*error running pod create option: invalid pod exit policy: \"invalid\"" "invalid exit policy"
+
+ # Test exit-policy behaviour
+ run_podman pod create --exit-policy continue
+ podID="$output"
+ run_podman run --pod $podID $IMAGE true
+ run_podman pod inspect $podID --format "{{.State}}"
+ _ensure_pod_state $podID Degraded
+ run_podman pod rm $podID
+
+ run_podman pod create --exit-policy stop
+ podID="$output"
+ run_podman run --pod $podID $IMAGE true
+ run_podman pod inspect $podID --format "{{.State}}"
+ _ensure_pod_state $podID Exited
+ run_podman pod rm $podID
+}
+@test "pod exit policies - play kube" {
+ # play-kube sets the exit policy to "stop"
+ local name="$(random_string 10 | tr A-Z a-z)"
+
+ kubeFile="apiVersion: v1
+kind: Pod
+metadata:
+ name: $name-pod
+spec:
+ containers:
+ - command:
+ - \"true\"
+ image: $IMAGE
+ name: ctr
+ restartPolicy: OnFailure"
+
+ echo "$kubeFile" > $PODMAN_TMPDIR/test.yaml
+ run_podman play kube $PODMAN_TMPDIR/test.yaml
+ run_podman pod inspect $name-pod --format "{{.ExitPolicy}}"
+ is "$output" "stop" "custom exit policy"
+ _ensure_pod_state $name-pod Exited
+ run_podman pod rm $name-pod
}
# vim: filetype=sh