Skip to content

Commit

Permalink
error exit if no clusters found
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Oct 21, 2019
1 parent e7b372f commit 6d771a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cli/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,13 @@ func getKubeConfig(cluster string) (string, error) {
}

// printClusters prints the names of existing clusters
func printClusters() {
func printClusters() error {
clusters, err := getClusters(true, "")
if err != nil {
log.Fatalf("Couldn't list clusters\n%+v", err)
}
if len(clusters) == 0 {
log.Printf("No clusters found!")
return
return fmt.Errorf("No clusters found")
}

table := tablewriter.NewWriter(os.Stdout)
Expand All @@ -226,6 +225,7 @@ func printClusters() {
}

table.Render()
return nil
}

// Classify cluster state: Running, Stopped or Abnormal
Expand Down
12 changes: 11 additions & 1 deletion cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ func DeleteCluster(c *cli.Context) error {
return err
}

if len(clusters) == 0 {
return fmt.Errorf("No cluster(s) found")
}

// remove clusters one by one instead of appending all names to the docker command
// this allows for more granular error handling and logging
for _, cluster := range clusters {
Expand Down Expand Up @@ -365,7 +369,9 @@ func ListClusters(c *cli.Context) error {
log.Info("--all is on by default, thus no longer required. This option will be removed in v2.0.0")

}
printClusters()
if err := printClusters(); err != nil {
return err
}
return nil
}

Expand All @@ -376,6 +382,10 @@ func GetKubeConfig(c *cli.Context) error {
return err
}

if len(clusters) == 0 {
return fmt.Errorf("No cluster(s) found")
}

for _, cluster := range clusters {
kubeConfigPath, err := getKubeConfig(cluster.name)
if err != nil {
Expand Down

0 comments on commit 6d771a2

Please sign in to comment.