Skip to content

Commit

Permalink
Display error message when odo dev fails on podman and clean resources (
Browse files Browse the repository at this point in the history
#6522)

* Display error message when odo dev fails on podman and clean resources on error

Signed-off-by: Parthvi Vala <[email protected]>

* show complete podman output on error

Signed-off-by: Parthvi Vala <[email protected]>

* Only set deployedPod if it exists

Signed-off-by: Parthvi Vala <[email protected]>

Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi authored Jan 24, 2023
1 parent 5b49592 commit e3e8b34
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/dev/podmandev/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ func (o *DevClient) deployPod(ctx context.Context, options dev.StartOptions) (*c

err = o.podmanClient.PlayKube(pod)
if err != nil {
// there are cases when pod is created even if there is an error with the pod def; for e.g. incorrect image
if podMap, _ := o.podmanClient.PodLs(); podMap[pod.Name] {
o.deployedPod = &corev1.Pod{}
o.deployedPod.SetName(pod.Name)
}
return nil, nil, err
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ func (o *PodmanCli) PlayKube(pod *corev1.Pod) error {
return err
}
stdin.Close()

var podmanOut string
go func() {
for {
tmp := make([]byte, 1024)
_, err = stdout.Read(tmp)
podmanOut += string(tmp)
klog.V(4).Info(string(tmp))
if err != nil {
break
Expand All @@ -87,7 +88,7 @@ func (o *PodmanCli) PlayKube(pod *corev1.Pod) error {
}()
if err = cmd.Wait(); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
err = fmt.Errorf("%s: %s", err, string(exiterr.Stderr))
err = fmt.Errorf("%s: %s\nComplete Podman output:\n%s", err, string(exiterr.Stderr), podmanOut)
}
return err
}
Expand Down
18 changes: 17 additions & 1 deletion tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ CMD ["npm", "start"]
for _, podman := range []bool{false, true} {
podman := podman
When("creating nodejs component, doing odo dev and run command has dev.odo.push.path attribute", helper.LabelPodmanIf(podman, func() {
//TODO Not implemented yet on Podman
// TODO Not implemented yet on Podman
var session helper.DevSession
var devStarted bool
BeforeEach(func() {
Expand Down Expand Up @@ -3263,4 +3263,20 @@ CMD ["npm", "start"]
}))

}

Context("odo dev on podman with a devfile bound to fail", Label(helper.LabelPodman), func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"),
filepath.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(cmpName))
helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "registry.access.redhat.com/ubi8/nodejs", "registry.access.redhat.com/ubi8/nose")
})
It("should fail with an error and cleanup resources", func() {
errContents := helper.Cmd("odo", "dev", "--platform=podman").AddEnv("ODO_EXPERIMENTAL_MODE=true").ShouldFail().Err()
helper.MatchAllInOutput(errContents, []string{"Complete Podman output", "registry.access.redhat.com/ubi8/nose", "Repo not found"})
component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner)
component.ExpectIsNotDeployed()
})
})
})

0 comments on commit e3e8b34

Please sign in to comment.