Skip to content

Commit

Permalink
fix: Fix error when no current namespace is set (#305)
Browse files Browse the repository at this point in the history
When no current namespace is set in the config file, then using `kn` without -n fails:

```
invalid configuration: no configuration has been provided
```

Instead of failing in this case, assume the default namespace "namespace"
  • Loading branch information
rhuss authored and knative-prow-robot committed Jul 26, 2019
1 parent 59b2855 commit 7d1594d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/kn/commands/namespaced.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package commands
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/client-go/tools/clientcmd"
)

// AddNamespaceFlags adds the namespace-related flags:
Expand Down Expand Up @@ -57,7 +58,11 @@ func (params *KnParams) GetNamespace(cmd *cobra.Command) (string, error) {
var err error
namespace, err = params.CurrentNamespace()
if err != nil {
return "", err
if !clientcmd.IsEmptyConfig(err) {
return "", err
}
// If no current namespace is set use "default"
namespace = "default"
}
}
return namespace, nil
Expand Down

0 comments on commit 7d1594d

Please sign in to comment.