Skip to content

Commit

Permalink
play.go: remove volumes on down -f
Browse files Browse the repository at this point in the history
* add e2e test

Signed-off-by: danishprakash <[email protected]>
  • Loading branch information
danishprakash committed Jun 19, 2023
1 parent f984452 commit ba3da15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ba3da15

Please sign in to comment.