6 "helm.sh/helm/v3/pkg/action"
7 "helm.sh/helm/v3/pkg/chart/loader"
8 "helm.sh/helm/v3/pkg/kube"
13 const releaseNamespace = "default"
14 const chartPath = "/go/release/charts/"
15 const kubeconfigPath = "/go/release/kubeconfig/"
17 //const chartPath = "/home/root1/code/mecm/mepm/applcm/k8shelm/pkg/plugin/"
18 //const kubeconfigPath = "/home/root1/"
20 func installChart(helmPkg bytes.Buffer, hostIP string) string {
21 logger := log.New(os.Stdout, "helmplugin ", log.LstdFlags|log.Lshortfile)
22 logger.Println("Inside helm client")
24 file, err := os.Create(chartPath + "temp.tar.gz")
26 logger.Printf("unable to create file")
29 _, err = helmPkg.WriteTo(file)
31 logger.Printf("uanble to write to file")
34 chart, err := loader.Load(chartPath + "temp.tar.gz")
40 releaseName := chart.Metadata.Name
42 kubeconfig := kubeconfigPath + hostIP
44 actionConfig := new(action.Configuration)
45 if err := actionConfig.Init(kube.GetConfig(kubeconfig, "", releaseNamespace), releaseNamespace, os.Getenv("HELM_DRIVER"), func(format string, v ...interface{}) {
46 fmt.Sprintf(format, v)
51 iCli := action.NewInstall(actionConfig)
52 iCli.Namespace = releaseNamespace
53 iCli.ReleaseName = releaseName
54 rel, err := iCli.Run(chart, nil)
58 fmt.Println("Successfully installed release: ", rel.Name)
62 func uninstallChart(relName string, hostIP string) {
63 kubeconfig := kubeconfigPath + hostIP
64 actionConfig := new(action.Configuration)
65 if err := actionConfig.Init(kube.GetConfig(kubeconfig, "", releaseNamespace), releaseNamespace, os.Getenv("HELM_DRIVER"), func(format string, v ...interface{}) {
66 fmt.Sprintf(format, v)
70 iCli := action.NewUninstall(actionConfig)
71 res, err := iCli.Run(relName);
75 fmt.Println("Successfully uninstalled release: ", res.Info)
78 func queryChart(relName string, hostIP string) string {
79 kubeconfig := kubeconfigPath + hostIP
80 actionConfig := new(action.Configuration)
81 if err := actionConfig.Init(kube.GetConfig(kubeconfig, "", releaseNamespace), releaseNamespace, os.Getenv("HELM_DRIVER"), func(format string, v ...interface{}) {
82 fmt.Sprintf(format, v)
86 iCli := action.NewStatus(actionConfig)
87 res, err := iCli.Run(relName)
91 return res.Info.Status.String()