Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that podman play kube actually reports errors #8917

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/podman/play/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/containers/podman/v2/cmd/podman/utils"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -130,6 +131,8 @@ func kube(cmd *cobra.Command, args []string) error {
}
}

ctrsFailed := 0

for _, pod := range report.Pods {
fmt.Printf("Pod:\n")
fmt.Println(pod.ID)
Expand All @@ -145,9 +148,21 @@ func kube(cmd *cobra.Command, args []string) error {
for _, ctr := range pod.Containers {
fmt.Println(ctr)
}
ctrsFailed += len(pod.ContainerErrors)
// If We have errors, add a newline
if len(pod.ContainerErrors) > 0 {
fmt.Println()
}
for _, err := range pod.ContainerErrors {
fmt.Fprintf(os.Stderr, err+"\n")
}
// Empty line for space for next block
fmt.Println()
}

if ctrsFailed > 0 {
return errors.Errorf("failed to start %d containers", ctrsFailed)
}

return nil
}
3 changes: 3 additions & 0 deletions pkg/domain/entities/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type PlayKubePod struct {
Containers []string
// Logs - non-fatal errors and log messages while processing.
Logs []string
// ContainerErrors - any errors that occurred while starting containers
// in the pod.
ContainerErrors []string
}

// PlayKubeReport contains the results of running play kube.
Expand Down
17 changes: 5 additions & 12 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/containers/image/v5/types"
"github.com/containers/podman/v2/libpod"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/libpod/image"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/specgen/generate"
Expand Down Expand Up @@ -251,21 +252,13 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
}

if options.Start != types.OptionalBoolFalse {
//start the containers
// Start the containers
podStartErrors, err := pod.Start(ctx)
if err != nil {
if err != nil && errors.Cause(err) != define.ErrPodPartialFail {
return nil, err
}

// Previous versions of playkube started containers individually and then
// looked for errors. Because we now use the uber-Pod start call, we should
// iterate the map of possible errors and return one if there is a problem. This
// keeps the behavior the same

for _, e := range podStartErrors {
if e != nil {
return nil, e
}
for id, err := range podStartErrors {
playKubePod.ContainerErrors = append(playKubePod.ContainerErrors, errors.Wrapf(err, "error starting container %s", id).Error())
}
}

Expand Down