Skip to content

Commit

Permalink
ignore configuration provided to cluster delete command if it doesnt …
Browse files Browse the repository at this point in the history
…provide a name
  • Loading branch information
dprunier committed Jul 15, 2024
1 parent c50308f commit de42f1d
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions cmd/cluster/clusterDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,26 @@ func parseDeleteClusterCmd(cmd *cobra.Command, args []string) []*k3d.Cluster {

// --config
if clusterDeletePpViper.GetString("config") != "" {
// not allowed with --all or more args
if len(args) > 0 || all {
l.Log().Fatalln("failed to delete cluster: cannot use `--config` flag with additional arguments or `--all`")
}

cfg, err := config.SimpleConfigFromViper(clusterDeleteCfgViper)
if err != nil {
l.Log().Fatalln(err)
}

if cfg.Name == "" {
l.Log().Fatalln("failed to delete cluster via config file: no name in config file")
}
if cfg.Name != "" {
// not allowed with --all or more args
if len(args) > 0 || all {
l.Log().Fatalln("failed to delete cluster: cannot use name from `--config` flag with additional arguments or `--all`")
}

c, err := client.ClusterGet(cmd.Context(), runtimes.SelectedRuntime, &k3d.Cluster{Name: cfg.Name})
if errors.Is(err, client.ClusterGetNoNodesFoundError) {
l.Log().Infof("No nodes found for cluster '%s', nothing to delete.", cfg.Name)
return nil
}
c, err := client.ClusterGet(cmd.Context(), runtimes.SelectedRuntime, &k3d.Cluster{Name: cfg.Name})
if errors.Is(err, client.ClusterGetNoNodesFoundError) {
l.Log().Infof("No nodes found for cluster '%s', nothing to delete.", cfg.Name)
return nil
}

clusters = append(clusters, c)
return clusters
clusters = append(clusters, c)
return clusters
}
}

// --all was set
Expand Down

0 comments on commit de42f1d

Please sign in to comment.