Created
November 15, 2021 20:24
-
-
Save j-griffith/0dca04b678ac3d9a51924bf4b906fea8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"io/ioutil" | |
"log" | |
hgc "github.com/mittwald/go-helm-client" | |
"helm.sh/helm/v3/pkg/repo" | |
) | |
func main() { | |
hc := getclient() | |
//updatechartrepo(hc) | |
installChart(hc) | |
} | |
func updatechartrepo(hc hgc.Client) { | |
chartRepo := repo.Entry{ | |
Name: "longhorn", | |
URL: "https://charts.longhorn.io", | |
} | |
// Add a chart-repository to the client | |
if err := hc.AddOrUpdateChartRepo(chartRepo); err != nil { | |
fmt.Printf("failed update chart: %+v\n", err) | |
panic(err) | |
} | |
template(hc) | |
} | |
func getclient() hgc.Client { | |
data, err := ioutil.ReadFile("/home/jdg/k3s-kube-config") | |
if err != nil { | |
log.Fatalf("Failed to read in kubeconfig: %+v\n", err) | |
} | |
opt := &hgc.KubeConfClientOptions{ | |
Options: &hgc.Options{ | |
RepositoryCache: "/tmp/.helmcache", | |
RepositoryConfig: "/tmp/.helmrepo", | |
Debug: true, | |
Linting: true, | |
}, | |
KubeContext: "", | |
KubeConfig: data, | |
} | |
helmClient, err := hgc.NewClientFromKubeConf(opt) | |
if err != nil { | |
fmt.Printf("failed get client: %+v\n", err) | |
panic(err) | |
} | |
return helmClient | |
} | |
func template(hc hgc.Client) { | |
chartSpec := hgc.ChartSpec{ | |
ReleaseName: "longhorn", | |
ChartName: "https://github.com/longhorn/charts/releases/download/longhorn-1.0.0/longhorn-1.0.0.tgz", | |
Namespace: "longhorn-system", | |
UpgradeCRDs: true, | |
Wait: true, | |
} | |
out, err := hc.TemplateChart(&chartSpec) | |
if err != nil { | |
fmt.Printf("failed template: %+v\n", err) | |
panic(err) | |
} | |
fmt.Printf("Output:\n%v\n", string(out)) | |
} | |
func installChart(hc hgc.Client) { | |
chartSpec := hgc.ChartSpec{ | |
ReleaseName: "longhorn", | |
ChartName: "https://github.com/longhorn/charts/releases/download/longhorn-1.0.0/longhorn-1.0.0.tgz", | |
Namespace: "longhorn-system", | |
} | |
fmt.Println("Try the install...") | |
if err, _ := hc.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil { | |
fmt.Printf("failed install/upgrade: %+v\n", err) | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment