diff --git a/cmd/cluster/clusterDelete.go b/cmd/cluster/clusterDelete.go index d93d55854..336743a42 100644 --- a/cmd/cluster/clusterDelete.go +++ b/cmd/cluster/clusterDelete.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 diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 118f751f8..1d7919555 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -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