diff --git a/k8s/nodes.go b/k8s/nodes.go index 7232192..a958cea 100644 --- a/k8s/nodes.go +++ b/k8s/nodes.go @@ -104,7 +104,8 @@ func Nodes(metric string) (NodeStatsList []Node) { // To fetch kubectl top nodes metrics nodeMetrics, err := mc.MetricsV1beta1().NodeMetricses().List(context.TODO(), v1.ListOptions{}) if err != nil { - panic(err.Error()) + fmt.Println("Unable to Get NodeMetrics. Is Metrics Server running ?") + os.Exit(2) } // To fetch kubectl get nodes information diff --git a/main.go b/main.go index ffe2a54..0953cb9 100644 --- a/main.go +++ b/main.go @@ -36,13 +36,13 @@ func usage() { // print in fine columns with fixed width displayfmt := "%-20s %-20s\n" fmt.Printf(displayfmt, " --help", "to display help") - fmt.Printf(displayfmt, " --sortby", "sort by ", utils.PrintValidSorts) + fmt.Printf(displayfmt, " --sortby", utils.PrintValidSorts()) fmt.Printf(displayfmt, " --filternodes", "filter based on node name") fmt.Printf(displayfmt, " --filtercolor", "filter based on color category <30 Green, >30 <70 Orange, >70 Red") fmt.Printf(displayfmt, " --filterlabels", "filter based on labels") fmt.Printf(displayfmt, " --desc", "to enable reverse sort") fmt.Printf(displayfmt, " --debug", "enable debug mode") - fmt.Printf(displayfmt, " --metrics", "choose which metrics", utils.PrintValidMetrics()) + fmt.Printf(displayfmt, " --metrics", utils.PrintValidMetrics()) os.Exit(1) } diff --git a/utils/validations.go b/utils/validations.go index 3ff4c04..b1aeb00 100644 --- a/utils/validations.go +++ b/utils/validations.go @@ -1,5 +1,7 @@ package utils +import "strings" + var ValidColors = map[string]bool{ "red": true, "green": true, @@ -45,18 +47,19 @@ func PrintValidColors() []string { return result } -func PrintValidMetrics() []string { +func PrintValidMetrics() string { var result []string for k := range ValidMetrics { result = append(result, k) } - return result + return "Choose one of ["+strings.Join(result, ", ")+"]" } -func PrintValidSorts() []string { +func PrintValidSorts() string { var result []string for k := range ValidSorts { result = append(result, k) } - return result + // return comma separated string + return "Choose one of ["+strings.Join(result, ", ")+"]" }