Skip to content

Commit

Permalink
Revert "feat: add basic for labels in tables derailed#3050"
Browse files Browse the repository at this point in the history
This reverts commit a63b480.
  • Loading branch information
KevinGimbel committed Jan 22, 2025
1 parent a4782a1 commit ab6cfc6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 42 deletions.
9 changes: 1 addition & 8 deletions internal/config/json/schemas/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
"sortColumn": { "type": "string" },
"columns": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": { "type": "string"},
"key": { "type": "string" }
}
}
"items": { "type": "string" }
}
},
"required": ["columns"]
Expand Down
20 changes: 2 additions & 18 deletions internal/config/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ type ViewConfigListener interface {

// ViewSetting represents a view configuration.
type ViewSetting struct {
Columns []Column `yaml:"columns"`
Columns []string `yaml:"columns"`
SortColumn string `yaml:"sortColumn"`
}

type Column struct {
Name string `yaml:"name"`
Key string `yaml:"key"`
}

func (v *ViewSetting) HasCols() bool {
return len(v.Columns) > 0
}
Expand All @@ -59,18 +54,7 @@ func (v *ViewSetting) Equals(vs *ViewSetting) bool {
if v == nil || vs == nil {
return v == nil && vs == nil
}

var vkeys []string
var vskeys []string

for idx := range v.Columns {
vkeys = append(vkeys, v.Columns[idx].Name)
}
for idx := range vs.Columns {
vskeys = append(vskeys, vs.Columns[idx].Name)
}

if c := slices.Compare(vkeys, vskeys); c != 0 {
if c := slices.Compare(v.Columns, vs.Columns); c != 0 {
return false
}
return cmp.Compare(v.SortColumn, vs.SortColumn) == 0
Expand Down
14 changes: 6 additions & 8 deletions internal/model1/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package model1
import (
"reflect"

"github.com/derailed/k9s/internal/config"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -65,11 +64,11 @@ func (h Header) Labelize(cols []int, labelCol int, rr *RowEvents) Header {
}

// MapIndices returns a collection of mapped column indices based of the requested columns.
func (h Header) MapIndices(cols []config.Column, wide bool) []int {
func (h Header) MapIndices(cols []string, wide bool) []int {
ii := make([]int, 0, len(cols))
cc := make(map[int]struct{}, len(cols))
for _, col := range cols {
idx, ok := h.IndexOf(col.Name, true)
idx, ok := h.IndexOf(col, true)
if !ok {
log.Warn().Msgf("Column %q not found on resource", col)
}
Expand All @@ -89,23 +88,22 @@ func (h Header) MapIndices(cols []config.Column, wide bool) []int {
}

// Customize builds a header from custom col definitions.
func (h Header) Customize(cols []config.Column, wide bool) Header {
func (h Header) Customize(cols []string, wide bool) Header {
if len(cols) == 0 {
return h
}
cc := make(Header, 0, len(h))
xx := make(map[int]struct{}, len(h))
for _, c := range cols {
idx, ok := h.IndexOf(c.Name, true)
idx, ok := h.IndexOf(c, true)
if !ok {
log.Warn().Msgf("Column %s is not available on this resource", c.Name)
cc = append(cc, HeaderColumn{Name: c.Name})
log.Warn().Msgf("Column %s is not available on this resource", c)
cc = append(cc, HeaderColumn{Name: c})
continue
}
xx[idx] = struct{}{}
col := h[idx].Clone()
col.Wide = false

cc = append(cc, col)
}

Expand Down
7 changes: 0 additions & 7 deletions internal/render/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (p Pod) Header(ns string) model1.Header {
model1.HeaderColumn{Name: "LABELS", Wide: true},
model1.HeaderColumn{Name: "VALID", Wide: true},
model1.HeaderColumn{Name: "AGE", Time: true},
model1.HeaderColumn{Name: "LABEL"},
}
}

Expand Down Expand Up @@ -167,17 +166,11 @@ func (p Pod) Render(o interface{}, ns string, row *model1.Row) error {
mapToStr(po.Labels),
AsStatus(p.diagnose(phase, cr, len(cs))),
ToAge(po.GetCreationTimestamp()),
ExtractLabel(po),
}

return nil
}

func ExtractLabel(pod v1.Pod) string {
// Need to get the "key" from the views.yaml config here
return pod.Labels["k8s-app"]
}

func (p Pod) diagnose(phase string, cr, ct int) error {
if phase == Completed {
return nil
Expand Down
1 change: 0 additions & 1 deletion internal/ui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ func (t *Table) buildRow(r int, re, ore model1.RowEvent, h model1.Header, pads M
if h[c].Decorator != nil {
field = h[c].Decorator(field)
}

if h[c].Align == tview.AlignLeft {
field = formatCell(field, pads[c])
}
Expand Down

0 comments on commit ab6cfc6

Please sign in to comment.