play.go: remove volumes on down -f

* add e2e test

Signed-off-by: danishprakash <danish.prakash@suse.com>
This commit is contained in:
danishprakash
2023-06-06 21:31:21 +05:30
parent f9844521bd
commit ba3da15e0e
2 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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() {