Skip to content

Commit

Permalink
feat(watch): Adding label-colums support
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <bob@vibioh.fr>
  • Loading branch information
ViBiOh committed May 4, 2024
1 parent 41dff6c commit 9ae4074
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Usage:
kmux watch [flags]
Flags:
-L, --label-columns strings Labels that are going to be presented as columns
-o, --output string Output format. One of: (wide)
-l, --selector stringToString Labels to filter pods (default [])
--show-annotations Show all annotations as the last column (after labels if both asked)
Expand Down
12 changes: 12 additions & 0 deletions cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"path"
"sort"
"strings"
"syscall"
Expand Down Expand Up @@ -31,6 +32,7 @@ var (
outputFormat string
showLabels bool
showAnnotations bool
labelColumns []string
)

func initWatch() {
Expand All @@ -40,6 +42,7 @@ func initWatch() {
flags.StringToStringVarP(&labelsSelector, "selector", "l", nil, "Labels to filter pods")
flags.BoolVarP(&showLabels, "show-labels", "", false, "Show all labels as the last column")
flags.BoolVarP(&showAnnotations, "show-annotations", "", false, "Show all annotations as the last column (after labels if both asked)")
flags.StringSliceVarP(&labelColumns, "label-columns", "L", nil, "Labels that are going to be presented as columns")
}

var watchCmd = &cobra.Command{
Expand Down Expand Up @@ -115,6 +118,11 @@ func initWatchTable() *table.Table {
)
}

for _, label := range labelColumns {
defaultWidths = append(defaultWidths, 12)
content = append(content, table.NewCell(strings.ToUpper(path.Base(label))))
}

if showLabels {
defaultWidths = append(defaultWidths, 12)
content = append(content, table.NewCell("LABELS"))
Expand Down Expand Up @@ -245,6 +253,10 @@ func outputWatch(watchTable *table.Table, contextName string, pod v1.Pod) {
)
}

for _, label := range labelColumns {
content = append(content, table.NewCell(pod.GetLabels()[label]))
}

if showLabels {
content = append(content, table.NewCell(mapAsString(pod.GetLabels())))
}
Expand Down

0 comments on commit 9ae4074

Please sign in to comment.