From 45f625854536e45679bd0728ed6854befe58d9f2 Mon Sep 17 00:00:00 2001 From: Atanas Todorov Date: Fri, 10 Jan 2025 11:34:46 +0200 Subject: [PATCH] =?UTF-8?q?Handle=20the=20case=20when=20namespace=20do=20n?= =?UTF-8?q?ot=20exists=20as=20a=20resource=20in=20the=20clu=E2=80=A6=20(#2?= =?UTF-8?q?69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Handle the case when namespace do not exists as a resource in the cluster * code review comments * provide default namespace as ucp resources are namespaced ones --------- Co-authored-by: Atanas Todorov --- k8s/client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/k8s/client.go b/k8s/client.go index 44f83c1..057083f 100644 --- a/k8s/client.go +++ b/k8s/client.go @@ -6,6 +6,7 @@ package k8s import ( "context" "fmt" + "k8s.io/apimachinery/pkg/api/errors" "strings" "github.com/sirupsen/logrus" @@ -225,7 +226,12 @@ func (k8sc *Client) _search(ctx context.Context, groups, categories, kinds, name } else { nsNames, err := getNamespaces(ctx, k8sc) if err != nil { - return nil, err + if !errors.IsNotFound(err) { + return nil, err + } + //This is the case when namespace resource does not exist in the cluster.This is KCP case. + //Continue the execution of this function with emtpy namespace list + nsNames = append(nsNames, "default") } nsList = nsNames }