From dda7d625bb87857810c069d2eb72c5e302a29417 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Thu, 23 Feb 2023 08:42:23 -0800 Subject: [PATCH] update --- .gitignore | 2 +- internal/metrics/pod.go | 4 ++-- internal/ui/app.go | 2 +- internal/ui/items.go | 13 +++++++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 8cb0efb..9405043 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ kubectl-topui out/ -demo.tape +topui.tape demos/ .DS_Store diff --git a/internal/metrics/pod.go b/internal/metrics/pod.go index 3270cec..1c7328f 100644 --- a/internal/metrics/pod.go +++ b/internal/metrics/pod.go @@ -136,8 +136,8 @@ func (m *MetricsClient) GetPodMetrics(o *top.TopPodOptions) ([]MetricValue, erro return values, nil } -func (m MetricsClient) GetPod(name string) (string, error) { - pod, err := m.k.CoreV1().Pods(m.ns).Get(context.Background(), name, metav1.GetOptions{}) +func (m MetricsClient) GetPod(name, ns string) (string, error) { + pod, err := m.k.CoreV1().Pods(ns).Get(context.Background(), name, metav1.GetOptions{}) if err != nil { return "", err } diff --git a/internal/ui/app.go b/internal/ui/app.go index da99379..2a9ffe1 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -108,7 +108,7 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var output string var err error if a.resource == metrics.POD { - output, err = a.client.GetPod(a.itemsPane.GetSelected()) + output, err = a.client.GetPod(a.itemsPane.GetSelected(), a.itemsPane.GetNamespace()) } else { output, err = a.client.GetNode(a.itemsPane.GetSelected()) } diff --git a/internal/ui/items.go b/internal/ui/items.go index 143e4a8..5ccbb9b 100644 --- a/internal/ui/items.go +++ b/internal/ui/items.go @@ -106,11 +106,20 @@ func (l *List) SetSize(width, height int) { } func (l List) GetSelected() string { - current := l.content.SelectedItem().(listItem) - sections := strings.Fields(string(current)) + sections := l.getSections() x := 0 if l.resource == metrics.POD { x = 1 } return sections[x] } + +func (l List) GetNamespace() string { + sections := l.getSections() + return sections[0] +} + +func (l List) getSections() []string { + current := l.content.SelectedItem().(listItem) + return strings.Fields(string(current)) +}