From a331018f9d67f2385f591234fd63ed5360d79edb Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Sun, 11 Sep 2022 19:04:35 -0400 Subject: [PATCH] Use exact match to find context from API server (#750) Currently, if you have two contexts: - my-cluster-dev - my-cluster and you try to apply to `my-cluster`, it will match the first one --- pkg/kubernetes/client/context.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/kubernetes/client/context.go b/pkg/kubernetes/client/context.go index b965c0b9f..12068450f 100644 --- a/pkg/kubernetes/client/context.go +++ b/pkg/kubernetes/client/context.go @@ -135,7 +135,8 @@ func ContextFromIP(apiServer string) (*Cluster, *Context, error) { return nil, nil, err } - err = find(contexts, "context.cluster", cluster.Name, &context) + // find the context that uses the cluster, it should be an exact match + err = find(contexts, "context.cluster", fmt.Sprintf("^%s$", cluster.Name), &context) if err == ErrorNoMatch { return nil, nil, ErrorNoContext(cluster.Name) } else if err != nil {