From 05f71fe1b606dbcded0e9eb0f97fbc337958adee Mon Sep 17 00:00:00 2001 From: Horst Gutmann Date: Wed, 8 Nov 2023 14:33:17 +0100 Subject: [PATCH] fix(kubernetes-client): Match context & cluster names exactly (#948) --- pkg/kubernetes/client/context.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/kubernetes/client/context.go b/pkg/kubernetes/client/context.go index d565c0d48..4abb6dbf3 100644 --- a/pkg/kubernetes/client/context.go +++ b/pkg/kubernetes/client/context.go @@ -58,7 +58,7 @@ func ContextFromName(contextName string) (*Cluster, *Context, error) { return nil, nil, err } - err = find(contexts, "name", contextName, &context) + err = find(contexts, "name", fmt.Sprintf("^%s$", contextName), &context) if err == ErrorNoMatch { return nil, nil, ErrorNoContext(contextName) } else if err != nil { @@ -70,7 +70,7 @@ func ContextFromName(contextName string) (*Cluster, *Context, error) { return nil, nil, err } - err = find(clusters, "name", context.Context.Cluster, &cluster) + err = find(clusters, "name", fmt.Sprintf("^%s$", context.Context.Cluster), &cluster) if err == ErrorNoMatch { return nil, nil, ErrorNoCluster(contextName) } else if err != nil { @@ -161,7 +161,7 @@ func IPFromContext(name string) (ip string, err error) { return "", err } - err = find(contexts, "name", name, &context) + err = find(contexts, "name", fmt.Sprintf("^%s$", name), &context) if err == ErrorNoMatch { return "", ErrorNoContext(name) } else if err != nil { @@ -176,7 +176,7 @@ func IPFromContext(name string) (ip string, err error) { } clusterName := context.Context.Cluster - err = find(clusters, "name", clusterName, &cluster) + err = find(clusters, "name", fmt.Sprintf("^%s$", clusterName), &cluster) if err == ErrorNoMatch { return "", fmt.Errorf("no cluster named `%s` as required by context `%s` was found. Please check your $KUBECONFIG", clusterName, name) } else if err != nil {