Skip to content

Commit

Permalink
Use exact match to find context from API server (#750)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
julienduchesne committed Sep 11, 2022
1 parent cfe9627 commit a331018
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/kubernetes/client/context.go
Expand Up @@ -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 {
Expand Down

0 comments on commit a331018

Please sign in to comment.