Skip to content

Commit

Permalink
Cli: add the cluster name to the error message
Browse files Browse the repository at this point in the history
- When you ask for a kubeconfig file for a named
cluster (i..e not the default "kind"), instead of
getting the (cryptic) message:
"could not locate any control plane nodes",
also return the name of the cluster, and a hint
to what the user should maybe supply (the --name
option).
- Note: Did not find any existing tests for this file, nor which mock
libraries we should use to mock the dependencies?

Testing Done: Create a named cluster and tested the `get kubeconfig` option:
```
$ make build unit verify
$ ./bin/kind create cluster --name mytest

$ ./bin/kind get kubeconfig
ERROR: could not locate any control plane nodes for cluster named 'kind'. Use the --name option to select a different cluster

$ ./bin/kind get kubeconfig --name mytest
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS[...]
```

Bug Number: kubernetes-sigs#2205
  • Loading branch information
fstrudel committed Jul 13, 2021
1 parent 55a3f92 commit 766872c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/cluster/internal/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package kubeconfig

import (
"bytes"

"sigs.k8s.io/kind/pkg/cluster/nodeutils"
"sigs.k8s.io/kind/pkg/errors"

Expand Down Expand Up @@ -63,7 +62,7 @@ func Get(p providers.Provider, name string, external bool) (string, error) {
}

// ContextForCluster returns the context name for a kind cluster based on
// it's name. This key is used for all list entries of kind clusters
// its name. This key is used for all list entries of kind clusters
func ContextForCluster(kindClusterName string) string {
return kubeconfig.KINDClusterKey(kindClusterName)
}
Expand All @@ -80,7 +79,8 @@ func get(p providers.Provider, name string, external bool) (*kubeconfig.Config,
return nil, err
}
if len(nodes) < 1 {
return nil, errors.New("could not locate any control plane nodes")
return nil, errors.Errorf("could not locate any control plane nodes for cluster named '%s'. "+
"Use the --name option to select a different cluster", name)
}
node := nodes[0]

Expand Down

0 comments on commit 766872c

Please sign in to comment.