Helm go sdk install chart from external location

Viewed 1153

Im using the following code to install chart that is bounded in my source code (eg. in my app/chart/chart1 in my go bin app), Now I need to move the chart to git repository or to artifactory,

My question is how can I install the chart from outside my program?

This is the code I use which works for bundled chart

I use the helm3 loader package which works when I have the chart bundled in my app

chart, err := loader.Load(“chart/chart1”)

https://pkg.go.dev/helm.sh/helm/v3@v3.5.4/pkg/chart/loader

Should I load it somehow with an http call or helm have some built in functionality ? we need some efficient way to handle it

3 Answers

It seems that helm during its upgrade/install commands checks first a couple of different locations which you can see getting called here. The content of that function is here. And then continues here with loader.Load

You can use something like this for installing nginx chart


    myChart, err := loader.Load("https://charts.bitnami.com/bitnami/nginx-8.8.4.tgz")
...
    install := action.NewInstall(m.actionConfig)
    install.ReleaseName = "my-release"
...
    myRelease, err := install.Run(myChart, myValues)

It would be similar to:

helm install my-release https://charts.bitnami.com/bitnami/nginx-8.8.4.tgz

loader.load checks only for files and directories. If you want to use URL helm sdk provides LocateChart method in Install interface. Here is an example:

settings := cli.New()
actionConfig := new(action.Configuration)
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), log.Printf); err != nil {
        log.Printf("%+v", err)
        os.Exit(1)
        }

client := action.NewInstall(actionConfig)

chrt_path, err := client.LocateChart("https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-4.0.6/ingress-nginx-4.0.6.tgz", settings); if err != nil {
        panic(err)
}

myChart, err := loader.Load(chrt_path); if err != nil {
        panic(err)
}

Then you can simple setup install options and call client.Run method.

Related