Skip to content

Commit

Permalink
clusterDelete: no error if no cluster was found (fixes #379)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Oct 19, 2020
1 parent 425b9b7 commit a385241
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cmd/cluster/clusterDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package cluster
import (
"bytes"
"context"
"errors"
"fmt"
"sort"
"strconv"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a385241

Please sign in to comment.