Skip to content

enter replicasets from deployments #3001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion internal/view/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package view

import (
"errors"

"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"
)
Expand Down Expand Up @@ -47,6 +47,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("Show Replicasets", d.replicaSetsCmd, true),
})
}

Expand All @@ -63,6 +64,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, model ui.Tabular, gvr client.GVR, fqn string) {
dp, err := d.getInstance(fqn)
if err != nil {
Expand Down Expand Up @@ -92,3 +107,13 @@ func showPodsFromSelector(app *App, path string, sel *metav1.LabelSelector) {

showPods(app, path, l.String(), "")
}

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.String(), "")
}
21 changes: 21 additions & 0 deletions internal/view/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ func podCtx(_ *App, path, fieldSel string) ContextFunc {
}
}

func showReplicasets(app *App, path, labelSel, fieldSel string) {
v := NewReplicaSet(client.NewGVR("apps/v1/replicasets"))
v.SetContextFn(replicasetCtx(app, path, fieldSel))
v.SetLabelFilter(cmd.ToLabels(labelSel))

ns, _ := client.Namespaced(path)
if err := app.Config.SetActiveNamespace(ns); err != nil {
log.Error().Err(err).Msg("Config NS set failed!")
}
if err := app.inject(v, false); err != nil {
app.Flash().Err(err)
}
}

func replicasetCtx(_ *App, path, fieldSel string) ContextFunc {
return func(ctx context.Context) context.Context {
ctx = context.WithValue(ctx, internal.KeyPath, path)
return context.WithValue(ctx, internal.KeyFields, fieldSel)
}
}

func extractApp(ctx context.Context) (*App, error) {
app, ok := ctx.Value(internal.KeyApp).(*App)
if !ok {
Expand Down