Skip to content

Instantly share code, notes, and snippets.

@developer-guy
Created April 19, 2021 07:32
Show Gist options
  • Save developer-guy/9d0364979b596c6555d3f4a7d1483dfd to your computer and use it in GitHub Desktop.
Save developer-guy/9d0364979b596c6555d3f4a7d1483dfd to your computer and use it in GitHub Desktop.
Install Helm Chart using Go
package main
import (
"flag"
"log"
"os"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/cli"
)
func main() {
var dryRun bool
flag.BoolVar(&dryRun, "dry-run", false, "enable dryrun")
flag.Parse()
chartPath := "./nginx"
namespace := "default"
releaseName := "nginx"
settings := cli.New()
actionConfig := new(action.Configuration)
// You can pass an empty string instead of settings.Namespace() to list
// all namespaces
if err := actionConfig.Init(settings.RESTClientGetter(), namespace,
os.Getenv("HELM_DRIVER"), log.Printf); err != nil {
log.Printf("%+v", err)
os.Exit(1)
}
// define values
vals := map[string]interface{}{
"replicaCount": 3,
}
// load chart from the path
chart, err := loader.Load(chartPath)
if err != nil {
panic(err)
}
client := action.NewInstall(actionConfig)
client.Namespace = namespace
client.ReleaseName = releaseName
client.DryRun = dryRun
// install the chart here
rel, err := client.Run(chart, vals)
if err != nil {
panic(err)
}
log.Printf("Installed Chart from path: %s in namespace: %s\n", rel.Name, rel.Namespace)
// this will confirm the values set during installation
log.Println(rel.Config)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment