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

odo logs: Do not panic when no access to cluster/podman #6561

Merged
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 pkg/odo/cli/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import (

"github.com/fatih/color"

"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/podman"

"github.com/redhat-developer/odo/pkg/log"

"github.com/redhat-developer/odo/pkg/devfile/location"
"github.com/redhat-developer/odo/pkg/odo/commonflags"
fcontext "github.com/redhat-developer/odo/pkg/odo/commonflags/context"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"

Expand Down Expand Up @@ -89,6 +92,18 @@ func (o *LogsOptions) Complete(ctx context.Context, cmdline cmdline.Cmdline, _ [
}

func (o *LogsOptions) Validate(ctx context.Context) error {

switch fcontext.GetPlatform(ctx, commonflags.PlatformCluster) {
case commonflags.PlatformCluster:
if o.clientset.KubernetesClient == nil {
return kclient.NewNoConnectionError()
}
case commonflags.PlatformPodman:
if o.clientset.PodmanClient == nil {
return podman.NewPodmanNotFoundError(nil)
}
}

if o.devMode && o.deployMode {
return errors.New("pass only one of --dev or --deploy flags; pass no flag to see logs for both modes")
}
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/cmd_logs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"os"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -54,6 +55,29 @@ var _ = Describe("odo logs command tests", func() {
helper.CommonAfterEach(commonVar)
})

When("in a devfile directory", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
helper.Cmd("odo", "init", "--name", componentName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()
})
When("not connected to any cluster or podman", Label(helper.LabelNoCluster), func() {
It("odo logs should fail with an error message", func() {
cmd := helper.Cmd("odo", "logs")
stderr := cmd.ShouldFail().Err()
Expect(stderr).To(ContainSubstring("unable to access the cluster"))
})

It("odo logs --platform podman should fail with an error message", func() {
rm3l marked this conversation as resolved.
Show resolved Hide resolved
os.Setenv("PODMAN_CMD", "false")
defer os.Unsetenv("PODMAN_CMD")
cmd := getLogCommand(true)
stderr := cmd.ShouldFail().Err()
Expect(stderr).To(ContainSubstring("unable to access podman"))
})
})

})

for _, podman := range []bool{false, true} {
podman := podman
When("directory is empty", helper.LabelPodmanIf(podman, func() {
Expand Down