show replicasets from deployment view (#3308)
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>mine
parent
516fe2ce19
commit
577a2fb7cc
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/derailed/k9s/internal/client"
|
||||
"github.com/derailed/k9s/internal/dao"
|
||||
"github.com/derailed/k9s/internal/ui"
|
||||
"github.com/derailed/tcell/v2"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
|
@ -47,6 +48,7 @@ func (d *Deploy) bindKeys(aa *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),
|
||||
ui.KeyZ: ui.NewKeyAction("ReplicaSets", d.replicaSetsCmd, true),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -63,6 +65,20 @@ func (d *Deploy) logOptions(prev bool) (*dao.LogOptions, error) {
|
|||
return podLogOptions(d.App(), path, prev, &dp.ObjectMeta, &dp.Spec.Template.Spec), nil
|
||||
}
|
||||
|
||||
func (d *Deploy) replicaSetsCmd(evt *tcell.EventKey) *tcell.EventKey {
|
||||
dName := d.GetTable().GetSelectedItem()
|
||||
if dName == "" {
|
||||
return evt
|
||||
}
|
||||
dp, err := d.getInstance(dName)
|
||||
if err != nil {
|
||||
d.App().Flash().Err(err)
|
||||
return nil
|
||||
}
|
||||
showReplicasetsFromSelector(d.App(), dName, dp.Spec.Selector)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Deploy) showPods(app *App, _ ui.Tabular, _ *client.GVR, fqn string) {
|
||||
dp, err := d.getInstance(fqn)
|
||||
if err != nil {
|
||||
|
|
@ -92,3 +108,13 @@ func showPodsFromSelector(app *App, path string, sel *metav1.LabelSelector) {
|
|||
|
||||
showPods(app, path, l, "")
|
||||
}
|
||||
|
||||
func showReplicasetsFromSelector(app *App, path string, sel *metav1.LabelSelector) {
|
||||
l, err := metav1.LabelSelectorAsSelector(sel)
|
||||
if err != nil {
|
||||
app.Flash().Err(err)
|
||||
return
|
||||
}
|
||||
|
||||
showReplicasets(app, path, l, "")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,5 +17,5 @@ func TestDeploy(t *testing.T) {
|
|||
|
||||
require.NoError(t, v.Init(makeCtx(t)))
|
||||
assert.Equal(t, "Deployments", v.Name())
|
||||
assert.Len(t, v.Hints(), 16)
|
||||
assert.Len(t, v.Hints(), 17)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,23 @@ func describeResource(app *App, _ ui.Tabular, gvr *client.GVR, path string) {
|
|||
}
|
||||
}
|
||||
|
||||
func showReplicasets(app *App, path string, labelSel labels.Selector, fieldSel string) {
|
||||
v := NewReplicaSet(client.RsGVR)
|
||||
v.SetContextFn(func(ctx context.Context) context.Context {
|
||||
ctx = context.WithValue(ctx, internal.KeyPath, path)
|
||||
return context.WithValue(ctx, internal.KeyFields, fieldSel)
|
||||
})
|
||||
v.SetLabelSelector(labelSel)
|
||||
|
||||
ns, _ := client.Namespaced(path)
|
||||
if err := app.Config.SetActiveNamespace(ns); err != nil {
|
||||
slog.Error("Unable to set active namespace during show replicasets", slogs.Error, err)
|
||||
}
|
||||
if err := app.inject(v, false); err != nil {
|
||||
app.Flash().Err(err)
|
||||
}
|
||||
}
|
||||
|
||||
func showPods(app *App, path string, labelSel labels.Selector, fieldSel string) {
|
||||
v := NewPod(client.PodGVR)
|
||||
v.SetContextFn(podCtx(app, path, fieldSel))
|
||||
|
|
|
|||
Loading…
Reference in New Issue