clusterDelete: no error if no cluster was found (fixes #379)

pull/382/head
iwilltry42 4 years ago
parent 425b9b709e
commit a385241c77
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 7
      cmd/cluster/clusterDelete.go
  2. 5
      pkg/cluster/cluster.go

@ -113,11 +113,14 @@ func parseDeleteClusterCmd(cmd *cobra.Command, args []string) []*k3d.Cluster {
}
for _, name := range clusternames {
cluster, err := cluster.ClusterGet(cmd.Context(), runtimes.SelectedRuntime, &k3d.Cluster{Name: name})
c, err := cluster.ClusterGet(cmd.Context(), runtimes.SelectedRuntime, &k3d.Cluster{Name: name})
if err != nil {
if err == cluster.ClusterGetNoNodesFoundError {
continue
}
log.Fatalln(err)
}
clusters = append(clusters, cluster)
clusters = append(clusters, c)
}
return clusters

@ -24,6 +24,7 @@ package cluster
import (
"bytes"
"context"
"errors"
"fmt"
"sort"
"strconv"
@ -488,6 +489,8 @@ func populateClusterFieldsFromLabels(cluster *k3d.Cluster) error {
return nil
}
var ClusterGetNoNodesFoundError = errors.New("No nodes found for given cluster")
// ClusterGet returns an existing cluster with all fields and node lists populated
func ClusterGet(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Cluster) (*k3d.Cluster, error) {
// get nodes that belong to the selected cluster
@ -497,7 +500,7 @@ func ClusterGet(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Cluster
}
if len(nodes) == 0 {
return nil, fmt.Errorf("No nodes found for cluster '%s'", cluster.Name)
return nil, ClusterGetNoNodesFoundError
}
// append nodes

Loading…
Cancel
Save