forked from opskumu/helm-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helm.go
42 lines (36 loc) · 1015 Bytes
/
helm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"os"
"github.com/golang/glog"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/kube"
)
type KubeInformation struct {
AimNamespace string
AimContext string
}
func InitKubeInformation(namespace, context string) *KubeInformation {
return &KubeInformation{
AimNamespace: namespace,
AimContext: context,
}
}
func actionConfigInit(kubeInfo *KubeInformation) (*action.Configuration, error) {
actionConfig := new(action.Configuration)
if kubeInfo.AimContext == "" {
kubeInfo.AimContext = settings.KubeContext
}
clientConfig := kube.GetConfig(settings.KubeConfig, kubeInfo.AimContext, kubeInfo.AimNamespace)
if settings.KubeToken != "" {
clientConfig.BearerToken = &settings.KubeToken
}
if settings.KubeAPIServer != "" {
clientConfig.APIServer = &settings.KubeAPIServer
}
err := actionConfig.Init(clientConfig, kubeInfo.AimNamespace, os.Getenv("HELM_DRIVER"), glog.Infof)
if err != nil {
glog.Errorf("%+v", err)
return nil, err
}
return actionConfig, nil
}