Skip to content
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

enter replicasets from deployments #3001

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions internal/view/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package view

import (
"errors"

"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/dao"
"github.com/derailed/k9s/internal/ui"
Expand Down Expand Up @@ -37,7 +36,7 @@ func NewDeploy(gvr client.GVR) ResourceViewer {
),
)
d.AddBindKeysFn(d.bindKeys)
d.GetTable().SetEnterFn(d.showPods)
d.GetTable().SetEnterFn(d.showReplicasets)

return &d
}
Expand All @@ -63,14 +62,14 @@ 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) showPods(app *App, model ui.Tabular, gvr client.GVR, fqn string) {
func (d *Deploy) showReplicasets(app *App, model ui.Tabular, gvr client.GVR, fqn string) {
dp, err := d.getInstance(fqn)
if err != nil {
app.Flash().Err(err)
return
}

showPodsFromSelector(app, fqn, dp.Spec.Selector)
showReplicasetsFromSelector(app, fqn, dp.Spec.Selector)
}

func (d *Deploy) getInstance(fqn string) (*appsv1.Deployment, error) {
Expand All @@ -92,3 +91,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 @@ -160,6 +160,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
Loading