-
Notifications
You must be signed in to change notification settings - Fork 84
/
helm.go
50 lines (44 loc) · 1.27 KB
/
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
43
44
45
46
47
48
49
50
package main
import (
"os"
"github.com/golang/glog"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/kube"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
type KubeInformation struct {
AimNamespace string
AimContext string
AimConfig string
}
func InitKubeInformation(namespace, context, config string) *KubeInformation {
return &KubeInformation{
AimNamespace: namespace,
AimContext: context,
AimConfig: config,
}
}
func actionConfigInit(kubeInfo *KubeInformation) (*action.Configuration, error) {
actionConfig := new(action.Configuration)
if kubeInfo.AimContext == "" {
kubeInfo.AimContext = settings.KubeContext
}
clientConfig := new(genericclioptions.ConfigFlags)
if kubeInfo.AimConfig == "" {
clientConfig = kube.GetConfig(settings.KubeConfig, kubeInfo.AimContext, kubeInfo.AimNamespace)
} else {
clientConfig = kube.GetConfig(kubeInfo.AimConfig, 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
}