mirror of https://github.com/kubernetes/kops.git
Fix `kops get clusters` to support filtering by name
We were using it in the upgrade docs, but it wasn't actually implemented.
This commit is contained in:
parent
591a85056a
commit
b614cbd130
|
|
@ -48,9 +48,27 @@ func (c *GetClustersCmd) Run(args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var clusters []*api.Cluster
|
var clusters []*api.Cluster
|
||||||
for i := range clusterList.Items {
|
if len(args) != 0 {
|
||||||
clusters = append(clusters, &clusterList.Items[i])
|
m := make(map[string]*api.Cluster)
|
||||||
|
for i := range clusterList.Items {
|
||||||
|
c := &clusterList.Items[i]
|
||||||
|
m[c.Name] = c
|
||||||
|
}
|
||||||
|
for _, arg := range args {
|
||||||
|
ig := m[arg]
|
||||||
|
if ig == nil {
|
||||||
|
return fmt.Errorf("cluster not found %q", arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
clusters = append(clusters, ig)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i := range clusterList.Items {
|
||||||
|
c := &clusterList.Items[i]
|
||||||
|
clusters = append(clusters, c)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(clusters) == 0 {
|
if len(clusters) == 0 {
|
||||||
fmt.Fprintf(os.Stderr, "No clusters found\n")
|
fmt.Fprintf(os.Stderr, "No clusters found\n")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue