From 3fa3436c69f2d28d304609c5613875561a11abf9 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Wed, 3 Jan 2024 08:41:15 +0000 Subject: [PATCH] helmcli: add GetCli client Signed-off-by: Wei Fu --- helmcli/get.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 helmcli/get.go diff --git a/helmcli/get.go b/helmcli/get.go new file mode 100644 index 0000000..0d63f51 --- /dev/null +++ b/helmcli/get.go @@ -0,0 +1,41 @@ +package helmcli + +import ( + "fmt" + + "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/release" + "k8s.io/cli-runtime/pkg/genericclioptions" +) + +// GetCli is a client to get helm chart from secret storage. +type GetCli struct { + namespace string + + cfg *action.Configuration +} + +// NewGetCli returns new GetCli instance. +func NewGetCli(kubeconfigPath string, namespace string) (*GetCli, 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 &GetCli{ + namespace: namespace, + cfg: actionCfg, + }, nil +} + +// Get returns all the information about that given release. +func (cli *GetCli) Get(releaseName string) (*release.Release, error) { + getCli := action.NewGet(cli.cfg) + return getCli.Run(releaseName) +}