From ba3da15e0e23625ef5057430f04b9242aac23cfd Mon Sep 17 00:00:00 2001 From: danishprakash Date: Tue, 6 Jun 2023 21:31:21 +0530 Subject: [PATCH] play.go: remove volumes on down -f * add e2e test Signed-off-by: danishprakash --- pkg/domain/infra/abi/play.go | 11 +++++++++++ test/e2e/play_kube_test.go | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index c19178b68e..7e2570fc5d 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -1343,6 +1343,17 @@ func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, opt return nil, fmt.Errorf("unable to read YAML as Kube Pod: %w", err) } podNames = append(podNames, podYAML.ObjectMeta.Name) + + for _, vol := range podYAML.Spec.Volumes { + switch vs := vol.VolumeSource; { + case vs.PersistentVolumeClaim != nil: + volumeNames = append(volumeNames, vs.PersistentVolumeClaim.ClaimName) + case vs.ConfigMap != nil: + volumeNames = append(volumeNames, vs.ConfigMap.Name) + case vs.Secret != nil: + volumeNames = append(volumeNames, vs.Secret.SecretName) + } + } case "Deployment": var deploymentYAML v1apps.Deployment diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 7d4077a2fc..29ccab9f54 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -4984,6 +4984,19 @@ spec: exec.WaitWithDefaultTimeout() Expect(exec).Should(Exit(0)) Expect(exec.OutputToString()).Should(Equal("hi")) + + teardown := podmanTest.Podman([]string{"kube", "down", "--force", kubeYaml}) + teardown.WaitWithDefaultTimeout() + Expect(teardown).Should(Exit(0)) + Expect(teardown.OutputToString()).Should(ContainSubstring("testvol")) + + // kube down --force should remove volumes + // specified in the manifest but not externally + // created volumes, testvol1 in this case + checkVol := podmanTest.Podman([]string{"volume", "ls", "--format", "{{.Name}}"}) + checkVol.WaitWithDefaultTimeout() + Expect(checkVol).Should(Exit(0)) + Expect(checkVol.OutputToString()).To(Equal("testvol1")) }) It("podman play kube with hostPath subpaths", func() {