Skip to content

Commit

Permalink
Merge pull request containers#16980 from vrothberg/fix-kube
Browse files Browse the repository at this point in the history
kube play: fix the error logic with --quiet
  • Loading branch information
openshift-merge-robot committed Jan 3, 2023
2 parents 987aeb7 + 03c7f47 commit b2da34e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cmd/podman/kube/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,12 @@ func teardown(body io.Reader, options entities.PlayKubeDownOptions, quiet bool)
fmt.Println("Pods stopped:")
}
for _, stopped := range reports.StopReport {
if len(stopped.Errs) == 0 && !quiet {
fmt.Println(stopped.Id)
} else {
switch {
case len(stopped.Errs) > 0:
podStopErrors = append(podStopErrors, stopped.Errs...)
case quiet:
default:
fmt.Println(stopped.Id)
}
}
// Dump any stop errors
Expand All @@ -361,10 +363,12 @@ func teardown(body io.Reader, options entities.PlayKubeDownOptions, quiet bool)
fmt.Println("Pods removed:")
}
for _, removed := range reports.RmReport {
if removed.Err == nil && !quiet {
fmt.Println(removed.Id)
} else {
switch {
case removed.Err != nil:
podRmErrors = append(podRmErrors, removed.Err)
case quiet:
default:
fmt.Println(removed.Id)
}
}

Expand All @@ -378,10 +382,12 @@ func teardown(body io.Reader, options entities.PlayKubeDownOptions, quiet bool)
fmt.Println("Volumes removed:")
}
for _, removed := range reports.VolumeRmReport {
if removed.Err == nil && !quiet {
fmt.Println(removed.Id)
} else {
switch {
case removed.Err != nil:
volRmErrors = append(volRmErrors, removed.Err)
case quiet:
default:
fmt.Println(removed.Id)
}
}

Expand Down
32 changes: 32 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4519,6 +4519,38 @@ cgroups="disabled"`), 0644)
Expect(kube).Should(Exit(0))
})

It("podman kube --quiet with error", func() {
yaml := `
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
replicas: 2
template:
metadata:
labels:
app: guestbook
tier: frontend
spec:
containers:
- name: php-redis
image: quay.io/libpod/alpine_nginx:latest
ports:
- containerPort: 1234
`

err = writeYaml(yaml, kubeYaml)
Expect(err).ToNot(HaveOccurred())

kube := podmanTest.Podman([]string{"kube", "play", "--quiet", kubeYaml})
kube.WaitWithDefaultTimeout()
Expect(kube).To(ExitWithError())
// The ugly format-error exited once in Podman. The test makes
// sure it's not coming back.
Expect(kube.ErrorToString()).To(Not(ContainSubstring("Error: %!s(<nil>)")))
})

It("podman kube play invalid yaml should clean up pod that was created before failure", func() {
podTemplate := `---
apiVersion: v1
Expand Down

0 comments on commit b2da34e

Please sign in to comment.