Skip to content

Commit

Permalink
Merge pull request #18 from AKSarav/develop
Browse files Browse the repository at this point in the history
Help Message Fix and Metrics Server Validation
  • Loading branch information
AKSarav authored Mar 29, 2024
2 parents 560097e + 3488b4a commit 2d3a776
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion k8s/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
11 changes: 7 additions & 4 deletions utils/validations.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package utils

import "strings"

var ValidColors = map[string]bool{
"red": true,
"green": true,
Expand Down Expand Up @@ -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, ", ")+"]"
}

0 comments on commit 2d3a776

Please sign in to comment.