diff --git a/pkg/domain/entities/volumes.go b/pkg/domain/entities/volumes.go index dad09e07bd..4acb7fc77d 100644 --- a/pkg/domain/entities/volumes.go +++ b/pkg/domain/entities/volumes.go @@ -30,6 +30,7 @@ type VolumeConfigResponse struct { type VolumeRmOptions struct { All bool Force bool + Ignore bool Timeout *uint } diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index edff325134..8d12b0020b 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -1450,6 +1450,9 @@ func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, opt for _, name := range podNames { pod, err := ic.Libpod.LookupPod(name) if err != nil { + if errors.Is(err, define.ErrNoSuchPod) { + continue + } return nil, err } ctr, err := pod.ServiceContainer() @@ -1463,23 +1466,23 @@ func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, opt } // Add the reports - reports.StopReport, err = ic.PodStop(ctx, podNames, entities.PodStopOptions{}) + reports.StopReport, err = ic.PodStop(ctx, podNames, entities.PodStopOptions{Ignore: true}) if err != nil { return nil, err } - reports.RmReport, err = ic.PodRm(ctx, podNames, entities.PodRmOptions{}) + reports.RmReport, err = ic.PodRm(ctx, podNames, entities.PodRmOptions{Ignore: true}) if err != nil { return nil, err } - reports.SecretRmReport, err = ic.SecretRm(ctx, secretNames, entities.SecretRmOptions{}) + reports.SecretRmReport, err = ic.SecretRm(ctx, secretNames, entities.SecretRmOptions{Ignore: true}) if err != nil { return nil, err } if options.Force { - reports.VolumeRmReport, err = ic.VolumeRm(ctx, volumeNames, entities.VolumeRmOptions{}) + reports.VolumeRmReport, err = ic.VolumeRm(ctx, volumeNames, entities.VolumeRmOptions{Ignore: true}) if err != nil { return nil, err } diff --git a/pkg/domain/infra/abi/secrets.go b/pkg/domain/infra/abi/secrets.go index a61e914d66..69d7ae5f5c 100644 --- a/pkg/domain/infra/abi/secrets.go +++ b/pkg/domain/infra/abi/secrets.go @@ -166,17 +166,10 @@ func (ic *ContainerEngine) SecretRm(ctx context.Context, nameOrIDs []string, opt } for _, nameOrID := range toRemove { deletedID, err := manager.Delete(nameOrID) - if err == nil || strings.Contains(err.Error(), "no such secret") { - if !options.Ignore { - reports = append(reports, &entities.SecretRmReport{ - Err: err, - ID: deletedID, - }) - } + if options.Ignore && errors.Is(err, secrets.ErrNoSuchSecret) { continue - } else { - return nil, err } + reports = append(reports, &entities.SecretRmReport{Err: err, ID: deletedID}) } return reports, nil diff --git a/pkg/domain/infra/abi/volumes.go b/pkg/domain/infra/abi/volumes.go index 3588716011..1423ac571f 100644 --- a/pkg/domain/infra/abi/volumes.go +++ b/pkg/domain/infra/abi/volumes.go @@ -61,6 +61,9 @@ func (ic *ContainerEngine) VolumeRm(ctx context.Context, namesOrIds []string, op for _, id := range namesOrIds { vol, err := ic.Libpod.LookupVolume(id) if err != nil { + if opts.Ignore && errors.Is(err, define.ErrNoSuchVolume) { + continue + } reports = append(reports, &entities.VolumeRmReport{ Err: err, Id: id, diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index f6a13cd1bf..902cf64190 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -4148,11 +4148,15 @@ invalid kube kind Expect(ls).Should(Exit(0)) Expect(ls.OutputToStringArray()).To(HaveLen(1)) - // teardown teardown := podmanTest.Podman([]string{"play", "kube", "--down", kubeYaml}) teardown.WaitWithDefaultTimeout() Expect(teardown).Should(Exit(0)) + // Removing a 2nd time to make sure no "no such error" is returned (see #19711) + teardown = podmanTest.Podman([]string{"play", "kube", "--down", kubeYaml}) + teardown.WaitWithDefaultTimeout() + Expect(teardown).Should(Exit(0)) + checkls := podmanTest.Podman([]string{"pod", "ps", "--format", "'{{.ID}}'"}) checkls.WaitWithDefaultTimeout() Expect(checkls).Should(Exit(0)) @@ -4172,12 +4176,16 @@ invalid kube kind Expect(ls).Should(Exit(0)) Expect(ls.OutputToStringArray()).To(HaveLen(1)) - // teardown teardown := podmanTest.Podman([]string{"kube", "down", kubeYaml}) teardown.WaitWithDefaultTimeout() Expect(teardown).Should(Exit(0)) Expect(teardown.OutputToString()).Should(ContainSubstring(ls.OutputToString())) + // Removing a 2nd time to make sure no "no such error" is returned (see #19711) + teardown = podmanTest.Podman([]string{"kube", "down", kubeYaml}) + teardown.WaitWithDefaultTimeout() + Expect(teardown).Should(Exit(0)) + checkls := podmanTest.Podman([]string{"secret", "ls", "--format", "'{{.ID}}'"}) checkls.WaitWithDefaultTimeout() Expect(checkls).Should(Exit(0)) @@ -4185,13 +4193,15 @@ invalid kube kind }) It("podman play kube teardown pod does not exist", func() { - // teardown + err := writeYaml(simplePodYaml, kubeYaml) + Expect(err).ToNot(HaveOccurred()) + teardown := podmanTest.Podman([]string{"play", "kube", "--down", kubeYaml}) teardown.WaitWithDefaultTimeout() - Expect(teardown).Should(Exit(125)) + Expect(teardown).Should(Exit(0)) }) - It("podman play kube teardown with volume without force delete", func() { + It("podman play kube teardown volume --force", func() { volName := RandomString(12) volDevice := define.TypeTmpfs @@ -4217,35 +4227,18 @@ invalid kube kind teardown.WaitWithDefaultTimeout() Expect(teardown).To(Exit(0)) - // volume should not be deleted on teardown + // volume should not be deleted on teardown without --force exists = podmanTest.Podman([]string{"volume", "exists", volName}) exists.WaitWithDefaultTimeout() Expect(exists).To(Exit(0)) - }) - It("podman play kube teardown with volume force delete", func() { + // volume gets deleted with --force + teardown = podmanTest.Podman([]string{"play", "kube", "--down", "--force", kubeYaml}) + teardown.WaitWithDefaultTimeout() + Expect(teardown).To(Exit(0)) - volName := RandomString(12) - volDevice := define.TypeTmpfs - volType := define.TypeTmpfs - volOpts := "nodev,noexec" - - pvc := getPVC(withPVCName(volName), - withPVCAnnotations(util.VolumeDeviceAnnotation, volDevice), - withPVCAnnotations(util.VolumeTypeAnnotation, volType), - withPVCAnnotations(util.VolumeMountOptsAnnotation, volOpts)) - err = generateKubeYaml("persistentVolumeClaim", pvc, kubeYaml) - Expect(err).ToNot(HaveOccurred()) - - kube := podmanTest.Podman([]string{"play", "kube", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(Exit(0)) - - exists := podmanTest.Podman([]string{"volume", "exists", volName}) - exists.WaitWithDefaultTimeout() - Expect(exists).To(Exit(0)) - - teardown := podmanTest.Podman([]string{"play", "kube", "--down", "--force", kubeYaml}) + // Removing a 2nd should succeed as well even if no volume matches + teardown = podmanTest.Podman([]string{"play", "kube", "--down", "--force", kubeYaml}) teardown.WaitWithDefaultTimeout() Expect(teardown).To(Exit(0))