From 7d1594dc1fd20532e9a798222d3252f2fe550a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Sat, 27 Jul 2019 00:10:49 +0200 Subject: [PATCH] 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" --- pkg/kn/commands/namespaced.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/kn/commands/namespaced.go b/pkg/kn/commands/namespaced.go index 414976b17..62b2a6303 100644 --- a/pkg/kn/commands/namespaced.go +++ b/pkg/kn/commands/namespaced.go @@ -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,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