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

Closes containers#18797

Signed-off-by: danishprakash <danish.prakash@suse.com>
  • Loading branch information
danishprakash committed Jun 8, 2023
1 parent 8e3ecc8 commit d24e111
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions libpod/runtime_volume_common.go
Expand Up @@ -51,6 +51,7 @@ func (r *Runtime) newVolume(ctx context.Context, noCreatePluginVolume bool, opti
if volume.config.Driver == "" {
volume.config.Driver = define.VolumeDriverLocal
}

volume.config.CreatedTime = time.Now()

// Check if volume with given name exists.
Expand Down
4 changes: 4 additions & 0 deletions pkg/domain/infra/abi/play.go
Expand Up @@ -1343,6 +1343,10 @@ 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 _, volume := range podYAML.Spec.Volumes {
volumeNames = append(volumeNames, volume.Name)
}
case "Deployment":
var deploymentYAML v1apps.Deployment

Expand Down
2 changes: 1 addition & 1 deletion pkg/specgen/generate/kube/play_test.go
Expand Up @@ -226,7 +226,7 @@ func TestConfigMapVolumes(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
result, err := VolumeFromConfigMap(test.volume.ConfigMap, test.configmaps)
result, err := VolumeFromConfigMap(test.volume.ConfigMap, test.configmaps, test.volume.Name)
if test.errorMessage == "" {
assert.NoError(t, err)
assert.Equal(t, test.expectedItems, result.Items)
Expand Down
9 changes: 4 additions & 5 deletions pkg/specgen/generate/kube/volume.go
Expand Up @@ -185,7 +185,7 @@ func VolumeFromPersistentVolumeClaim(claim *v1.PersistentVolumeClaimVolumeSource
}, nil
}

func VolumeFromConfigMap(configMapVolumeSource *v1.ConfigMapVolumeSource, configMaps []v1.ConfigMap) (*KubeVolume, error) {
func VolumeFromConfigMap(configMapVolumeSource *v1.ConfigMapVolumeSource, configMaps []v1.ConfigMap, volName string) (*KubeVolume, error) {
var configMap *v1.ConfigMap
kv := &KubeVolume{
Type: KubeVolumeTypeConfigMap,
Expand All @@ -194,8 +194,8 @@ func VolumeFromConfigMap(configMapVolumeSource *v1.ConfigMapVolumeSource, config
for _, cm := range configMaps {
if cm.Name == configMapVolumeSource.Name {
matchedCM := cm
// Set the source to the config map name
kv.Source = cm.Name
// Set the source to the volume name
kv.Source = volName
configMap = &matchedCM
break
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func VolumeFromSource(volumeSource v1.VolumeSource, configMaps []v1.ConfigMap, s
case volumeSource.PersistentVolumeClaim != nil:
return VolumeFromPersistentVolumeClaim(volumeSource.PersistentVolumeClaim)
case volumeSource.ConfigMap != nil:
return VolumeFromConfigMap(volumeSource.ConfigMap, configMaps)
return VolumeFromConfigMap(volumeSource.ConfigMap, configMaps, volName)
case volumeSource.Secret != nil:
return VolumeFromSecret(volumeSource.Secret, secretsManager)
case volumeSource.EmptyDir != nil:
Expand All @@ -270,7 +270,6 @@ func InitializeVolumes(specVolumes []v1.Volume, configMaps []v1.ConfigMap, secre
if err != nil {
return nil, fmt.Errorf("failed to create volume %q: %w", specVolume.Name, err)
}

volumes[specVolume.Name] = volume
}

Expand Down
9 changes: 9 additions & 0 deletions test/e2e/play_kube_test.go
Expand Up @@ -4984,6 +4984,15 @@ 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))

checkVol := podmanTest.Podman([]string{"volume", "ls", "--format", "'{{.Name}}'"})
checkVol.WaitWithDefaultTimeout()
Expect(checkVol).Should(Exit(0))
Expect(checkVol.OutputToStringArray()).To(BeEmpty())
})

It("podman play kube with hostPath subpaths", func() {
Expand Down

0 comments on commit d24e111

Please sign in to comment.