From 1a34a70ef30b1aa9070efcdde6f3324a8fe08c80 Mon Sep 17 00:00:00 2001 From: hulizhe Date: Thu, 29 Aug 2024 10:50:06 +0800 Subject: [PATCH] enhance top pod command Signed-off-by: hulizhe --- pkg/karmadactl/top/top_pods.go | 6 ++++++ test/e2e/karmadactl_test.go | 36 ++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/pkg/karmadactl/top/top_pods.go b/pkg/karmadactl/top/top_pods.go index f9501542abce..e53e5df954c7 100644 --- a/pkg/karmadactl/top/top_pods.go +++ b/pkg/karmadactl/top/top_pods.go @@ -84,6 +84,12 @@ var ( # Show metrics for all pods in the default namespace %[1]s top pod + # Show metrics for all pods in the default namespace in member1 cluster + %[1]s top pod --clusters=member1 + + # Show metrics for all pods in the default namespace in member1 and member2 cluster + %[1]s top pod --clusters=member1,member2 + # Show metrics for all pods in the given namespace %[1]s top pod --namespace=NAMESPACE diff --git a/test/e2e/karmadactl_test.go b/test/e2e/karmadactl_test.go index a340d8e86660..fd61e336dc17 100644 --- a/test/e2e/karmadactl_test.go +++ b/test/e2e/karmadactl_test.go @@ -589,28 +589,30 @@ var _ = ginkgo.Describe("Karmadactl top testing", func() { }) ginkgo.It("Karmadactl top existing pod", func() { - for _, clusterName := range framework.ClusterNames() { - cmd := framework.NewKarmadactlCommand(kubeconfig, karmadaContext, karmadactlPath, pod.Namespace, karmadactlTimeout, "top", "pod", pod.Name, "-n", pod.Namespace, "-C", clusterName) + ginkgo.By("Karmadactl top existing pod", func() { + for _, clusterName := range framework.ClusterNames() { + cmd := framework.NewKarmadactlCommand(kubeconfig, karmadaContext, karmadactlPath, pod.Namespace, karmadactlTimeout, "top", "pod", pod.Name, "-n", pod.Namespace, "-C", clusterName) + _, err := cmd.ExecOrDie() + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + } + }) + + ginkgo.By("Karmadactl top existing pod without setting cluster flag", func() { + cmd := framework.NewKarmadactlCommand(kubeconfig, karmadaContext, karmadactlPath, pod.Namespace, karmadactlTimeout, "top", "pod", pod.Name, "-n", pod.Namespace) _, err := cmd.ExecOrDie() gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - } - }) - - ginkgo.It("Karmadactl top existing pod without setting cluster flag", func() { - cmd := framework.NewKarmadactlCommand(kubeconfig, karmadaContext, karmadactlPath, pod.Namespace, karmadactlTimeout, "top", "pod", pod.Name, "-n", pod.Namespace) - _, err := cmd.ExecOrDie() - gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - }) + }) - ginkgo.It("Karmadactl top pod without specific podName", func() { - cmd := framework.NewKarmadactlCommand(kubeconfig, karmadaContext, karmadactlPath, pod.Namespace, karmadactlTimeout, "top", "pod", "-A") - _, err := cmd.ExecOrDie() - gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - for _, clusterName := range framework.ClusterNames() { - cmd := framework.NewKarmadactlCommand(kubeconfig, karmadaContext, karmadactlPath, pod.Namespace, karmadactlTimeout, "top", "pod", "-A", "-C", clusterName) + ginkgo.By("Karmadactl top pod without specific podName", func() { + cmd := framework.NewKarmadactlCommand(kubeconfig, karmadaContext, karmadactlPath, pod.Namespace, karmadactlTimeout, "top", "pod", "-A") _, err := cmd.ExecOrDie() gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - } + for _, clusterName := range framework.ClusterNames() { + cmd := framework.NewKarmadactlCommand(kubeconfig, karmadaContext, karmadactlPath, pod.Namespace, karmadactlTimeout, "top", "pod", "-A", "-C", clusterName) + _, err := cmd.ExecOrDie() + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + } + }) }) }) })