forked from derailed/k9s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsa.go
61 lines (51 loc) · 1.42 KB
/
sa.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
package view
import (
"context"
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/dao"
"github.com/derailed/k9s/internal/ui"
"github.com/gdamore/tcell/v2"
)
// ServiceAccount represents a serviceaccount viewer.
type ServiceAccount struct {
ResourceViewer
}
// NewServiceAccount returns a new viewer.
func NewServiceAccount(gvr client.GVR) ResourceViewer {
s := ServiceAccount{
ResourceViewer: NewBrowser(gvr),
}
s.AddBindKeysFn(s.bindKeys)
return &s
}
func (s *ServiceAccount) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyU: ui.NewKeyAction("UsedBy", s.refCmd, true),
})
}
func (s *ServiceAccount) refCmd(evt *tcell.EventKey) *tcell.EventKey {
return scanSARefs(evt, s.App(), s.GetTable(), "v1/serviceaccounts")
}
func scanSARefs(evt *tcell.EventKey, a *App, t *Table, gvr string) *tcell.EventKey {
path := t.GetSelectedItem()
if path == "" {
return evt
}
ctx := context.Background()
refs, err := dao.ScanForSARefs(refContext(gvr, path, true)(ctx), a.factory)
if err != nil {
a.Flash().Err(err)
return nil
}
if len(refs) == 0 {
a.Flash().Warnf("No references found at this time for %s::%s. Check again later!", gvr, path)
return nil
}
a.Flash().Infof("Viewing references for %s::%s", gvr, path)
view := NewReference(client.NewGVR("references"))
view.SetContextFn(refContext(gvr, path, false))
if err := a.inject(view); err != nil {
a.Flash().Err(err)
}
return nil
}