From 4a5581ce0dfa43a6dab3c1396d54fa852eaacbf2 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 30 Nov 2022 16:10:46 -0500 Subject: [PATCH] stop reporting errors removing containers that don't exist Init containers are removed once they exit, but podman reports and error that the container does not exist, when it was previously removed. Stop reporting missing containers when removing. Signed-off-by: Daniel J Walsh --- libpod/pod_api.go | 4 ---- test/system/700-play.bats | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/libpod/pod_api.go b/libpod/pod_api.go index 7b143b478c..08a2e14294 100644 --- a/libpod/pod_api.go +++ b/libpod/pod_api.go @@ -44,10 +44,6 @@ func (p *Pod) startInitContainers(ctx context.Context) error { icLock.Unlock() return fmt.Errorf("failed to remove once init container %s: %w", initCon.ID(), err) } - // Removing a container this way requires an explicit call to clean up the db - if err := p.runtime.state.RemoveContainerFromPod(p, initCon); err != nil { - logrus.Errorf("Removing container %s from database: %v", initCon.ID(), err) - } icLock.Unlock() } } diff --git a/test/system/700-play.bats b/test/system/700-play.bats index 390e8365a5..411e88dae3 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -207,7 +207,7 @@ EOF run_podman container inspect --format "{{.HostConfig.NetworkMode}}" $infraID is "$output" "none" "network mode none is set for the container" - run_podman kube down - < $PODMAN_TMPDIR/test.yaml + run_podman kube down $PODMAN_TMPDIR/test.yaml run_podman 125 inspect test_pod-test is "$output" ".*Error: inspecting object: no such object: \"test_pod-test\"" run_podman pod rm -a @@ -436,6 +436,38 @@ status: {} run_podman rm -f -t0 myyaml } +@test "podman play with init container" { + TESTDIR=$PODMAN_TMPDIR/testdir + mkdir -p $TESTDIR + +testUserYaml=" +apiVersion: v1 +kind: Pod +metadata: + name: pod +spec: + containers: + - command: + - ls + - /dev/shm/test1 + image: $IMAGE + name: testCtr + initContainers: + - command: + - touch + - /dev/shm/test1 + image: $IMAGE + name: initCtr +" + echo "$testUserYaml" > $PODMAN_TMPDIR/test.yaml + run_podman kube play $PODMAN_TMPDIR/test.yaml + assert "$output" !~ "level=" "init containers should not generate logrus.Error" + run_podman inspect --format "{{.State.ExitCode}}" pod-testCtr + is "$output" "0" "init container should have created /dev/shm/test1" + + run_podman kube down $PODMAN_TMPDIR/test.yaml +} + @test "podman kube play - hostport" { HOST_PORT=$(random_free_port) echo "