-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
sts.go
65 lines (55 loc) · 1.53 KB
/
sts.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
package view
import (
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/render"
"github.com/derailed/k9s/internal/ui"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
)
// StatefulSet represents a statefulset viewer.
type StatefulSet struct {
ResourceViewer
}
// NewStatefulSet returns a new viewer.
func NewStatefulSet(gvr client.GVR) ResourceViewer {
s := StatefulSet{
ResourceViewer: NewPortForwardExtender(
NewRestartExtender(
NewScaleExtender(
NewLogsExtender(NewBrowser(gvr), nil),
),
),
),
}
s.SetBindKeysFn(s.bindKeys)
s.GetTable().SetEnterFn(s.showPods)
s.GetTable().SetColorerFn(render.StatefulSet{}.ColorerFunc())
return &s
}
func (s *StatefulSet) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftR: ui.NewKeyAction("Sort Ready", s.GetTable().SortColCmd(readyCol, true), false),
})
}
func (s *StatefulSet) showPods(app *App, _ ui.Tabular, _, path string) {
sts, err := s.sts(path)
if err != nil {
app.Flash().Err(err)
return
}
showPodsFromSelector(app, path, sts.Spec.Selector)
}
func (s *StatefulSet) sts(path string) (*appsv1.StatefulSet, error) {
o, err := s.App().factory.Get(s.GVR().String(), path, true, labels.Everything())
if err != nil {
return nil, err
}
var sts appsv1.StatefulSet
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &sts)
if err != nil {
return nil, err
}
return &sts, nil
}