From dbd21531817fb828b5eca02933e458ad95ceb5fa Mon Sep 17 00:00:00 2001 From: Shubham Bansal <62992590+shubham-bansal96@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:39:49 +0530 Subject: [PATCH] Fission failed to list resources if namespace flag is not provided (#2585) * use default namespace if no namespace is available * remove the current-context namespace from push_pr GitHub workflow --- .github/workflows/push_pr.yaml | 1 - pkg/fission-cli/util/util.go | 10 +++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/push_pr.yaml b/.github/workflows/push_pr.yaml index 9f7ca4b0..af01f262 100644 --- a/.github/workflows/push_pr.yaml +++ b/.github/workflows/push_pr.yaml @@ -69,7 +69,6 @@ jobs: kubectl get nodes sudo apt-get install -y apache2-utils kubectl config use-context kind-kind - kubectl config set-context --current --namespace=default kubectl config view - name: Helm chart lint diff --git a/pkg/fission-cli/util/util.go b/pkg/fission-cli/util/util.go index 01c1e91f..1215c557 100644 --- a/pkg/fission-cli/util/util.go +++ b/pkg/fission-cli/util/util.go @@ -166,14 +166,13 @@ func GetKubernetesNamespace(kubeContext string) (currentNS string, err error) { return "", err } - config1, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - loadingRules, &clientcmd.ConfigOverrides{CurrentContext: kubeContext}).RawConfig() + namespace, _, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( + loadingRules, &clientcmd.ConfigOverrides{CurrentContext: kubeContext}).Namespace() if err != nil { return "", errors.Wrap(err, "Failed to build Kubernetes config") } - currentNS = config1.Contexts[config1.CurrentContext].Namespace - return currentNS, nil + return namespace, nil } // given a list of functions, this checks if the functions actually exist on the cluster @@ -508,9 +507,6 @@ func GetResourceNamespace(input cli.Input, deprecatedFlag string) (namespace, cu return namespace, currentNS, err } } - if currentNS == "" { - return namespace, currentNS, errors.Errorf("either set current-context or provide namespace with --namespace flag") - } } console.Verbose(2, "Namespace for resource %s ", currentNS)