Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Helm #129

Open
dylanratcliffe opened this issue Sep 16, 2023 · 0 comments
Open

Support Helm #129

dylanratcliffe opened this issue Sep 16, 2023 · 0 comments

Comments

@dylanratcliffe
Copy link
Member

Helm is built on top of kubernetes and doesn't actually create kubernetes objects. In order to read helm info we will need to use the helm Go libraries: https://pkg.go.dev/helm.sh/helm

GPT-4 suggests that we can query helm releases as follows:

package main

import (
    "log"
	"os"
	"helm.sh/helm/v3/pkg/action"
	"helm.sh/helm/v3/pkg/cli"
	"k8s.io/client-go/tools/clientcmd"
	"fmt"
)

func main() {
	helmDriver := os.Getenv("HELM_DRIVER")
	settings := cli.New()

	actionConfig := new(action.Configuration)
	kubeconfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
		clientcmd.NewDefaultClientConfigLoadingRules(),
		&clientcmd.ConfigOverrides{},
	)
	namespace, _, _ := kubeconfig.Namespace()
	err := actionConfig.Init(settings.RESTClientGetter(), namespace, helmDriver, func(format string, v ...interface{}) {
		fmt.Sprintf(format, v)
	})

	if err != nil {
		log.Fatalf("Failed to connect to Kubernetes: %v", err)
	}

	// create a new List action
	listAction := action.NewList(actionConfig)
	
    // set the namespace if needed - default it's "", which lists releases across all namespaces
    listAction.AllNamespaces = true
	
    // retrieve releases
	releases, err := listAction.Run()
	if err != nil {
		log.Fatalf("Failed to retrieve releases: %v", err)
	}

	// print release name
	for _, rls := range releases {
		fmt.Println(rls.Name)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant