Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kubernetes-client): Match context & cluster names exactly #948

Merged
merged 1 commit into from Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/kubernetes/client/context.go
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down