Skip to content

Commit

Permalink
Merge pull request #73 from Azure/mchinta/nodepoolList
Browse files Browse the repository at this point in the history
Adding vc nodepool list command
  • Loading branch information
fuweid authored Jan 31, 2024
2 parents 313a9c2 + 6277412 commit 9c17a2a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cmd/kperf/commands/virtualcluster/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/Azure/kperf/cmd/kperf/commands/utils"
"github.com/Azure/kperf/virtualcluster"
"helm.sh/helm/v3/pkg/release"

"github.com/urfave/cli"
)
Expand Down Expand Up @@ -104,6 +105,25 @@ var nodepoolListCommand = cli.Command{
Name: "list",
Usage: "List virtual node pools",
Action: func(cliCtx *cli.Context) error {
return fmt.Errorf("nodepool list - not implemented")
kubeCfgPath := cliCtx.String("kubeconfig")
nodepools, err := virtualcluster.ListNodepools(context.Background(), kubeCfgPath)
if err != nil {
return err
}
return renderRunnerGroups(nodepools)

},
}

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
}
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)
}

return listCli.List()

}

0 comments on commit 9c17a2a

Please sign in to comment.