Skip to content

Commit

Permalink
Fixed --all-namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
applejag committed Aug 5, 2023
1 parent 1ee03e1 commit fd3b165
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 11 additions & 6 deletions pkg/klock/klock.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func NewWatcher(options Options, program *tea.Program, printer Printer, printNam
Printer: printer,
Args: args,

printNamespace: printNamespace,
errorChan: make(chan error, 3),
}
}
Expand Down Expand Up @@ -361,6 +362,10 @@ func (p *Printer) addObjectToTable(objTable *metav1.Table, printNamespace bool,
if !ok {
return nil, fmt.Errorf("metadata.uid: want string, got %T", metadata["uid"])
}
name, ok := metadata["name"].(string)
if !ok {
return nil, fmt.Errorf("metadata.name: want string, got %T", metadata["name"])
}
creationTimestamp, ok := metadata["creationTimestamp"].(string)
if !ok {
return nil, fmt.Errorf("metadata.creationTimestamp: want string, got %T", metadata["creationTimestamp"])
Expand All @@ -370,20 +375,20 @@ func (p *Printer) addObjectToTable(objTable *metav1.Table, printNamespace bool,
return nil, fmt.Errorf("metadata.creationTimestamp: %w", err)
}
tableRow := table.Row{
ID: uid,
Fields: make([]any, 0, len(p.colDefs)),
ID: uid,
Fields: make([]any, 0, len(p.colDefs)),
SortField: name,
}
if printNamespace {
tableRow.Fields = append(tableRow.Fields, metadata["namespace"])
namespace := metadata["namespace"]
tableRow.Fields = append(tableRow.Fields, namespace)
tableRow.SortField = fmt.Sprintf("%s/%s", namespace, name)
}
for i, cell := range row.Cells {
if i >= len(p.colDefs) {
return nil, fmt.Errorf("cant find index %d (%v) in column defs: %v", i, cell, p.colDefs)
}
colDef := p.colDefs[i]
if printNamespace {
colDef = p.colDefs[i+1]
}
if colDef.Priority != 0 && !p.WideOutput {
continue
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/table/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ type StyledColumn struct {
}

type Row struct {
ID string
Fields []any
Status Status
ID string
Fields []any
Status Status
SortField string

renderedFields []string
}
Expand All @@ -61,6 +62,9 @@ const (

// SortValue value is the value we use when sorting the list.
func (r Row) SortValue() string {
if r.SortField != "" {
return r.SortField
}
if len(r.Fields) == 0 {
return ""
}
Expand Down

0 comments on commit fd3b165

Please sign in to comment.