Skip to content

Commit 39a413a

Browse files
committed
enter replicasets from deployments with r
Signed-off-by: Rudrakh Panigrahi <[email protected]>
1 parent 61f0f80 commit 39a413a

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

internal/view/dp.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ package view
55

66
import (
77
"errors"
8-
98
"github.com/derailed/k9s/internal/client"
109
"github.com/derailed/k9s/internal/dao"
1110
"github.com/derailed/k9s/internal/ui"
11+
"github.com/derailed/tcell/v2"
1212
appsv1 "k8s.io/api/apps/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414
)
@@ -47,6 +47,7 @@ func (d *Deploy) bindKeys(aa *ui.KeyActions) {
4747
ui.KeyShiftR: ui.NewKeyAction("Sort Ready", d.GetTable().SortColCmd(readyCol, true), false),
4848
ui.KeyShiftU: ui.NewKeyAction("Sort UpToDate", d.GetTable().SortColCmd(uptodateCol, true), false),
4949
ui.KeyShiftL: ui.NewKeyAction("Sort Available", d.GetTable().SortColCmd(availCol, true), false),
50+
ui.KeyZ: ui.NewKeyAction("Show Replicasets", d.replicaSetsCmd, true),
5051
})
5152
}
5253

@@ -63,6 +64,20 @@ func (d *Deploy) logOptions(prev bool) (*dao.LogOptions, error) {
6364
return podLogOptions(d.App(), path, prev, dp.ObjectMeta, dp.Spec.Template.Spec), nil
6465
}
6566

67+
func (d *Deploy) replicaSetsCmd(evt *tcell.EventKey) *tcell.EventKey {
68+
dName := d.GetTable().GetSelectedItem()
69+
if dName == "" {
70+
return evt
71+
}
72+
dp, err := d.getInstance(dName)
73+
if err != nil {
74+
d.App().Flash().Err(err)
75+
return nil
76+
}
77+
showReplicasetsFromSelector(d.App(), dName, dp.Spec.Selector)
78+
return nil
79+
}
80+
6681
func (d *Deploy) showPods(app *App, model ui.Tabular, gvr client.GVR, fqn string) {
6782
dp, err := d.getInstance(fqn)
6883
if err != nil {
@@ -92,3 +107,13 @@ func showPodsFromSelector(app *App, path string, sel *metav1.LabelSelector) {
92107

93108
showPods(app, path, l.String(), "")
94109
}
110+
111+
func showReplicasetsFromSelector(app *App, path string, sel *metav1.LabelSelector) {
112+
l, err := metav1.LabelSelectorAsSelector(sel)
113+
if err != nil {
114+
app.Flash().Err(err)
115+
return
116+
}
117+
118+
showReplicasets(app, path, l.String(), "")
119+
}

internal/view/helpers.go

+21
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ func podCtx(_ *App, path, fieldSel string) ContextFunc {
163163
}
164164
}
165165

166+
func showReplicasets(app *App, path, labelSel, fieldSel string) {
167+
v := NewReplicaSet(client.NewGVR("apps/v1/replicasets"))
168+
v.SetContextFn(replicasetCtx(app, path, fieldSel))
169+
v.SetLabelFilter(cmd.ToLabels(labelSel))
170+
171+
ns, _ := client.Namespaced(path)
172+
if err := app.Config.SetActiveNamespace(ns); err != nil {
173+
log.Error().Err(err).Msg("Config NS set failed!")
174+
}
175+
if err := app.inject(v, false); err != nil {
176+
app.Flash().Err(err)
177+
}
178+
}
179+
180+
func replicasetCtx(_ *App, path, fieldSel string) ContextFunc {
181+
return func(ctx context.Context) context.Context {
182+
ctx = context.WithValue(ctx, internal.KeyPath, path)
183+
return context.WithValue(ctx, internal.KeyFields, fieldSel)
184+
}
185+
}
186+
166187
func extractApp(ctx context.Context) (*App, error) {
167188
app, ok := ctx.Value(internal.KeyApp).(*App)
168189
if !ok {

0 commit comments

Comments
 (0)