Skip to content

Commit

Permalink
working on printing data for list command
Browse files Browse the repository at this point in the history
  • Loading branch information
manasachi committed Jan 30, 2024
1 parent b18eae3 commit 787e75a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cmd/kperf/commands/virtualcluster/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ var nodepoolListCommand = cli.Command{
Name: "list",
Usage: "List virtual node pools",
Action: func(cliCtx *cli.Context) error {
return fmt.Errorf("nodepool list - not implemented")
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)

//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
},
}
40 changes: 40 additions & 0 deletions helmcli/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package helmcli

import (
"fmt"

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/release"
"k8s.io/cli-runtime/pkg/genericclioptions"
)

// ListCli is a client to get helm charts from secret storage.
type ListCli struct {
namespace string

cfg *action.Configuration
}

// NewGetCli returns new GetCli instance.
func NewListCli(kubeconfigPath string, namespace string) (*ListCli, error) {
actionCfg := new(action.Configuration)
if err := actionCfg.Init(
&genericclioptions.ConfigFlags{
KubeConfig: &kubeconfigPath,
},
namespace,
"secret",
noopLog,
); err != nil {
return nil, fmt.Errorf("failed to init action config: %w", err)
}
return &ListCli{
namespace: namespace,
cfg: actionCfg,
}, nil
}

func (cli *ListCli) List() ([]*release.Release, error) {
listCli := action.NewList(cli.cfg)
return listCli.Run()
}
21 changes: 21 additions & 0 deletions virtualcluster/node_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package virtualcluster

import (
"context"
"fmt"

"helm.sh/helm/v3/pkg/release"

"github.com/Azure/kperf/helmcli"
)

// ListNodeppol lists nodepools added by the vc nodeppool add command.
func ListNodepools(_ context.Context, kubeconfigPath string) ([]*release.Release, error) {
listCli, err := helmcli.NewListCli(kubeconfigPath, virtualnodeReleaseNamespace)
if err != nil {
return nil, fmt.Errorf("failed to create helm list client: %w", err)
}

nodepools, err := listCli.List()
return nodepools, err
}

0 comments on commit 787e75a

Please sign in to comment.