-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
dp.go
71 lines (60 loc) · 1.69 KB
/
dp.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
package view
import (
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/dao"
"github.com/derailed/k9s/internal/render"
"github.com/derailed/k9s/internal/ui"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const scaleDialogKey = "scale"
// Deploy represents a deployment view.
type Deploy struct {
ResourceViewer
}
// NewDeploy returns a new deployment view.
func NewDeploy(gvr client.GVR) ResourceViewer {
d := Deploy{
ResourceViewer: NewPortForwardExtender(
NewRestartExtender(
NewScaleExtender(
NewImageExtender(
NewLogsExtender(
NewBrowser(gvr),
nil,
),
),
),
),
),
}
d.AddBindKeysFn(d.bindKeys)
d.GetTable().SetEnterFn(d.showPods)
d.GetTable().SetColorerFn(render.Deployment{}.ColorerFunc())
return &d
}
func (d *Deploy) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftR: ui.NewKeyAction("Sort Ready", d.GetTable().SortColCmd(readyCol, true), false),
ui.KeyShiftU: ui.NewKeyAction("Sort UpToDate", d.GetTable().SortColCmd(uptodateCol, true), false),
ui.KeyShiftL: ui.NewKeyAction("Sort Available", d.GetTable().SortColCmd(availCol, true), false),
})
}
func (d *Deploy) showPods(app *App, model ui.Tabular, gvr, path string) {
var ddp dao.Deployment
dp, err := ddp.Load(app.factory, path)
if err != nil {
app.Flash().Err(err)
return
}
showPodsFromSelector(app, path, dp.Spec.Selector)
}
// ----------------------------------------------------------------------------
// Helpers...
func showPodsFromSelector(app *App, path string, sel *metav1.LabelSelector) {
l, err := metav1.LabelSelectorAsSelector(sel)
if err != nil {
app.Flash().Err(err)
return
}
showPods(app, path, l.String(), "")
}