Skip to content

Commit

Permalink
enter replicasets from deployments
Browse files Browse the repository at this point in the history
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
  • Loading branch information
rudrakhp committed Nov 30, 2024
1 parent 4ef39f5 commit 22003ed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
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

0 comments on commit 22003ed

Please sign in to comment.