Merge pull request #19769 from vrothberg/fix-19711

kube down/play --replace: handle absent objects
This commit is contained in:
OpenShift Merge Robot 2023-08-28 15:15:41 +02:00 committed by GitHub
commit 009ff3af69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 42 deletions

View File

@ -30,6 +30,7 @@ type VolumeConfigResponse struct {
type VolumeRmOptions struct {
All bool
Force bool
Ignore bool
Timeout *uint
}

View File

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

View File

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

View File

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

View File

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