fix: Fix error when no current namespace is set (#305)

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"
This commit is contained in:
Roland Huß 2019-07-27 00:10:49 +02:00 committed by Knative Prow Robot
parent 59b2855d04
commit 7d1594dc1f
1 changed files with 6 additions and 1 deletions

View File

@ -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:
@ -57,8 +58,12 @@ func (params *KnParams) GetNamespace(cmd *cobra.Command) (string, error) {
var err error
namespace, err = params.CurrentNamespace()
if err != nil {
if !clientcmd.IsEmptyConfig(err) {
return "", err
}
// If no current namespace is set use "default"
namespace = "default"
}
}
return namespace, nil
}