diff --git a/docs/source/markdown/podman-systemd.unit.5.md b/docs/source/markdown/podman-systemd.unit.5.md index 7a2764eae4..0067c361d6 100644 --- a/docs/source/markdown/podman-systemd.unit.5.md +++ b/docs/source/markdown/podman-systemd.unit.5.md @@ -640,6 +640,7 @@ Valid options for `[Kube]` are listed below: | ConfigMap=/tmp/config.map | --config-map /tmp/config.map | | ContainersConfModule=/etc/nvd\.conf | --module=/etc/nvd\.conf | | GlobalArgs=--log-level=debug | --log-level=debug | +| KubeDownForce=true | --force (for `podman kube down`) | | LogDriver=journald | --log-driver journald | | Network=host | --net host | | PodmanArgs=\-\-annotation=key=value | --annotation=key=value | @@ -696,6 +697,10 @@ escaped to allow inclusion of whitespace and other control characters. This key can be listed multiple times. +### `KubeDownForce=` + +Remove all resources, including volumes, when calling `podman kube down`. +Equivalent to the Podman `--force` option. ### `LogDriver=` diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index edb020fb49..d90de98f8e 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -90,6 +90,7 @@ const ( KeyIP = "IP" KeyIP6 = "IP6" KeyImage = "Image" + KeyKubeDownForce = "KubeDownForce" KeyLabel = "Label" KeyLogDriver = "LogDriver" KeyMask = "Mask" @@ -264,6 +265,7 @@ var ( KeyContainersConfModule: true, KeyExitCodePropagation: true, KeyGlobalArgs: true, + KeyKubeDownForce: true, KeyLogDriver: true, KeyNetwork: true, KeyPodmanArgs: true, @@ -1139,7 +1141,14 @@ func ConvertKube(kube *parser.UnitFile, names map[string]string, isUser bool) (* // Use `ExecStopPost` to make sure cleanup happens even in case of // errors; otherwise containers, pods, etc. would be left behind. execStop := createBasePodmanCommand(kube, KubeGroup) - execStop.add("kube", "down", yamlPath) + + execStop.add("kube", "down") + + if kubeDownForce, ok := kube.LookupBoolean(KubeGroup, KeyKubeDownForce); ok { + execStop.addBool("--force", kubeDownForce) + } + + execStop.add(yamlPath) service.AddCmdline(ServiceGroup, "ExecStopPost", execStop.Args) err = handleSetWorkingDirectory(kube, service) diff --git a/test/e2e/quadlet/downforce.kube b/test/e2e/quadlet/downforce.kube new file mode 100644 index 0000000000..19f5fd1b85 --- /dev/null +++ b/test/e2e/quadlet/downforce.kube @@ -0,0 +1,8 @@ +## assert-podman-stop-post-args "kube" +## assert-podman-stop-post-args "down" +## assert-podman-stop-post-args "--force" +## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml + +[Kube] +Yaml=deployment.yml +KubeDownForce=true diff --git a/test/e2e/quadlet_test.go b/test/e2e/quadlet_test.go index d50cd3ee04..3279ddd5d6 100644 --- a/test/e2e/quadlet_test.go +++ b/test/e2e/quadlet_test.go @@ -765,6 +765,7 @@ BOGUS=foo Entry("Kube - global args", "globalargs.kube", 0, ""), Entry("Kube - Containers Conf Modules", "containersconfmodule.kube", 0, ""), Entry("Kube - Service Type=oneshot", "oneshot.kube", 0, ""), + Entry("Kube - Down force", "downforce.kube", 0, ""), Entry("Network - Basic", "basic.network", 0, ""), Entry("Network - Disable DNS", "disable-dns.network", 0, ""), diff --git a/test/system/252-quadlet.bats b/test/system/252-quadlet.bats index c03742d663..fe49a3e15a 100644 --- a/test/system/252-quadlet.bats +++ b/test/system/252-quadlet.bats @@ -1246,4 +1246,83 @@ EOF run_podman rmi --ignore $(pause_image) } +@test "quadlet - kube down force" { + local test_random_string=$(random_string) + + local quadlet_kube_volume_name=test-volume_$test_random_string + local pod_name="test_pod_$test_random_string" + local container_name="test" + local quadlet_kube_pod_yaml_file=$PODMAN_TMPDIR/pod_$test_random_string.yaml + cat > $quadlet_kube_pod_yaml_file < $quadlet_kube_pod_unit_file <