forked from derailed/k9s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkload.go
86 lines (72 loc) · 2 KB
/
workload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of K9s
package render
import (
"fmt"
"strings"
"github.com/derailed/k9s/internal/model1"
"github.com/derailed/tcell/v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// Workload renders a workload to screen.
type Workload struct {
Base
}
// ColorerFunc colors a resource row.
func (n Workload) ColorerFunc() model1.ColorerFunc {
return func(ns string, h model1.Header, re *model1.RowEvent) tcell.Color {
c := model1.DefaultColorer(ns, h, re)
idx, ok := h.IndexOf("STATUS", true)
if !ok {
return c
}
status := strings.TrimSpace(re.Row.Fields[idx])
if status == "DEGRADED" {
c = model1.PendingColor
}
return c
}
}
// Header returns a header rbw.
func (Workload) Header(string) model1.Header {
return model1.Header{
model1.HeaderColumn{Name: "KIND"},
model1.HeaderColumn{Name: "NAMESPACE"},
model1.HeaderColumn{Name: "NAME"},
model1.HeaderColumn{Name: "STATUS"},
model1.HeaderColumn{Name: "READY"},
model1.HeaderColumn{Name: "VALID", Wide: true},
model1.HeaderColumn{Name: "AGE", Time: true},
}
}
// Render renders a K8s resource to screen.
func (n Workload) Render(o interface{}, _ string, r *model1.Row) error {
res, ok := o.(*WorkloadRes)
if !ok {
return fmt.Errorf("expected allRes but got %T", o)
}
r.ID = fmt.Sprintf("%s|%s|%s", res.Row.Cells[0].(string), res.Row.Cells[1].(string), res.Row.Cells[2].(string))
r.Fields = model1.Fields{
res.Row.Cells[0].(string),
res.Row.Cells[1].(string),
res.Row.Cells[2].(string),
res.Row.Cells[3].(string),
res.Row.Cells[4].(string),
res.Row.Cells[5].(string),
ToAge(res.Row.Cells[6].(metav1.Time)),
}
return nil
}
type WorkloadRes struct {
Row metav1.TableRow
}
// GetObjectKind returns a schema object.
func (a *WorkloadRes) GetObjectKind() schema.ObjectKind {
return nil
}
// DeepCopyObject returns a container copy.
func (a *WorkloadRes) DeepCopyObject() runtime.Object {
return a
}