@@ -11,6 +11,7 @@ import (
11
11
// "github.com/gookit/color"
12
12
// . "github.com/logrusorgru/aurora"
13
13
// "k8s.io/cli-runtime/pkg/printers"
14
+ // "github.com/olekukonko/tablewriter"
14
15
"github.com/jedib0t/go-pretty/table"
15
16
"github.com/jedib0t/go-pretty/text"
16
17
"github.com/pkg/errors"
@@ -71,15 +72,24 @@ func runRootCommand(flags *flagpole) error {
71
72
return errors .Cause (err )
72
73
}
73
74
74
- PrintUsingGoPretty (sliceOfOutputRowPVC )
75
+ if nil == sliceOfOutputRowPVC || 0 > len (sliceOfOutputRowPVC ) {
76
+ ns := flags .namespace
77
+ if 0 == len (ns ) {
78
+ ns = "all"
79
+ }
80
+ log .Infof ("Either no volumes found in namespace/s: '%s' or the storage provisioner used for the volumes does not publish metrics to kubelet" , ns )
81
+ } else {
82
+ PrintUsingGoPretty (sliceOfOutputRowPVC )
83
+ }
84
+
75
85
return nil
76
86
}
77
87
78
88
func PrintUsingGoPretty (sliceOfOutputRowPVC []* OutputRowPVC ) {
89
+ // https://github.com/jedib0t/go-pretty/tree/master/table#table
79
90
t := table .NewWriter ()
80
- t .SetOutputMirror (os .Stdout )
81
- t .AppendHeader (table.Row {"PVC" , "Namespace" , "Pod" , "Size" , "Used" , "Available" , "%Used" , "iused" , "ifree" , "%iused" })
82
91
92
+ t .AppendHeader (table.Row {"PVC" , "Namespace" , "Pod" , "Size" , "Used" , "Available" , "%Used" , "iused" , "ifree" , "%iused" })
83
93
for _ , pvcRow := range sliceOfOutputRowPVC {
84
94
percentageUsedColor := GetColorFromPercentageUsed (pvcRow .PercentageUsed )
85
95
percentageIUsedColor := GetColorFromPercentageUsed (pvcRow .PercentageIUsed )
@@ -97,12 +107,14 @@ func PrintUsingGoPretty(sliceOfOutputRowPVC []*OutputRowPVC) {
97
107
})
98
108
}
99
109
100
- // t.SetAutoIndex(true)
110
+ // https://github.com/jedib0t/go-pretty/blob/master/table/style.go
101
111
styleBold := table .StyleBold
102
112
styleBold .Options = table .OptionsNoBordersAndSeparators
103
113
t .SetStyle (styleBold )
104
114
// t.Style().Options.SeparateRows = true
105
- t .Render ()
115
+ // t.SetAutoIndex(true)
116
+ // t.SetOutputMirror(os.Stdout)
117
+ fmt .Printf ("\n %s\n \n " , t .Render ())
106
118
}
107
119
108
120
func GetColorFromPercentageUsed (percentageUsed float64 ) text.Color {
@@ -457,8 +469,9 @@ func GetSliceOfOutputRowPVC(flags *flagpole) ([]*OutputRowPVC, error) {
457
469
458
470
func GetOutputRowPVCFromNodeChan (ctx context.Context , clientset * kubernetes.Clientset , nodeChan <- chan corev1.Node , desiredNamespace string , outputRowPVCChan chan <- * OutputRowPVC ) error {
459
471
for node := range nodeChan {
472
+ log .Tracef ("connecting to node: %s" , node .Name )
460
473
request := clientset .CoreV1 ().RESTClient ().Get ().Resource ("nodes" ).Name (node .Name ).SubResource ("proxy" ).Suffix ("stats/summary" )
461
- responseRawArrayOfBytes , err := request .DoRaw (context . Background () )
474
+ responseRawArrayOfBytes , err := request .DoRaw (ctx )
462
475
if err != nil {
463
476
return errors .Wrapf (err , "failed to get stats from node" )
464
477
}
@@ -473,6 +486,7 @@ func GetOutputRowPVCFromNodeChan(ctx context.Context, clientset *kubernetes.Clie
473
486
for _ , vol := range pod .ListOfVolumes {
474
487
outputRowPVC := GetOutputRowPVCFromPodAndVolume (pod , vol , desiredNamespace )
475
488
if nil == outputRowPVC {
489
+ log .Tracef ("no pvc found for pod: '%s', vol: '%s', desiredNamespace: '%s'; continuing..." , pod .PodRef .Name , vol .PvcRef .PvcName , desiredNamespace )
476
490
continue
477
491
}
478
492
select {
@@ -493,6 +507,8 @@ func GetOutputRowPVCFromPodAndVolume(pod *Pod, vol *Volume, desiredNamespace str
493
507
if 0 < len (desiredNamespace ) {
494
508
if vol .PvcRef .PvcNamespace != desiredNamespace {
495
509
return nil
510
+ } else {
511
+ log .Debugf ("restricting findings to namespace: '%s'" , desiredNamespace )
496
512
}
497
513
}
498
514
@@ -524,10 +540,12 @@ func GetOutputRowPVCFromPodAndVolume(pod *Pod, vol *Volume, desiredNamespace str
524
540
// }
525
541
526
542
func ListNodes (ctx context.Context , clientset * kubernetes.Clientset ) (* corev1.NodeList , error ) {
543
+ log .Tracef ("getting a list of all nodes" )
527
544
return clientset .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {})
528
545
}
529
546
530
547
func KubeConfigPath () (string , error ) {
548
+ log .Debugf ("getting kubeconfig path based on user's home dir" )
531
549
home , err := os .UserHomeDir ()
532
550
if err != nil {
533
551
return "" , errors .Wrapf (err , "unable to get home dir" )
0 commit comments