From ca41bc863da09aecc97e4e00bcfb33f72d191abd Mon Sep 17 00:00:00 2001 From: manasachi Date: Tue, 30 Jan 2024 17:11:35 -0500 Subject: [PATCH] adding back changes, addressing comments --- cmd/kperf/commands/virtualcluster/nodepool.go | 32 +++++++++---------- virtualcluster/node_list.go | 4 +-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/cmd/kperf/commands/virtualcluster/nodepool.go b/cmd/kperf/commands/virtualcluster/nodepool.go index 2e7d91d..bdeaf70 100644 --- a/cmd/kperf/commands/virtualcluster/nodepool.go +++ b/cmd/kperf/commands/virtualcluster/nodepool.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Azure/kperf/virtualcluster" + "helm.sh/helm/v3/pkg/release" "github.com/urfave/cli" ) @@ -92,28 +93,25 @@ var nodepoolListCommand = cli.Command{ Name: "list", Usage: "List virtual node pools", Action: func(cliCtx *cli.Context) error { - fmt.Println("In List command") kubeCfgPath := cliCtx.String("kubeconfig") nodepools, err := virtualcluster.ListNodepools(context.Background(), kubeCfgPath) - fmt.Println("after getting nodepools") if err != nil { return err } - fmt.Println("No error :)") - fmt.Println("Number of nodepools: \n", len(nodepools)) - fmt.Println() - for _, nodepool := range nodepools { - fmt.Println("Nodepool name: ", nodepool.Name) + return renderRunnerGroups(nodepools) - //fmt.Println("Nodepool Nodes: ", len(nodepool.Info.repli)) - - //fmt.Println("Nodepool Memory: ", nodepool.Info.memory) - fmt.Println("Nodepool Status: ", nodepool.Info.Status) - // fmt.Println("-------------------") - // fmt.Println(nodepool) - // fmt.Println("-------------------") - } - fmt.Println("after printing returned nodepools") - return nil }, } + +func renderRunnerGroups(nodepools []*release.Release) error { + if len(nodepools) > 0 { + fmt.Println("+-------------------+------------+-------------+-------------+------------+") + fmt.Printf("| %-17s | %-10s | %-9s | %-11s | %-9s |\n", "Name", "Nodes", "CPU (cores)", "Memory (GiB)", "Status") + fmt.Println("+-------------------+------------+-------------+-------------+------------+") + } + for _, nodepool := range nodepools { + fmt.Printf("| %-17s | %-10v | %-12v| %-12v| %-10v |\n", nodepool.Name, nodepool.Config["replicas"], nodepool.Config["cpu"], nodepool.Config["memory"], nodepool.Info.Status) + fmt.Println("+-------------------+------------+-------------+-------------+------------+") + } + return nil +} diff --git a/virtualcluster/node_list.go b/virtualcluster/node_list.go index a50a8a2..885a39e 100644 --- a/virtualcluster/node_list.go +++ b/virtualcluster/node_list.go @@ -16,6 +16,6 @@ func ListNodepools(_ context.Context, kubeconfigPath string) ([]*release.Release return nil, fmt.Errorf("failed to create helm list client: %w", err) } - nodepools, err := listCli.List() - return nodepools, err + return listCli.List() + }