-
Notifications
You must be signed in to change notification settings - Fork 2
/
helm.go
60 lines (47 loc) · 1.32 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
51
52
53
54
55
56
57
58
59
60
package itest
import (
"context"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/rest"
)
type InstallationConfig struct {
ReleaseName string
Namespace string
ChartDir string
Values map[string]any
RESTConfig *rest.Config
Log action.DebugLog
}
func InstallHelmChart(ctx context.Context, config InstallationConfig) (CleanupFunc, error) {
var (
helmCliConfig = genericclioptions.NewConfigFlags(false)
actionConfig action.Configuration
restConf = config.RESTConfig
)
helmCliConfig.APIServer = &restConf.Host
helmCliConfig.BearerToken = &restConf.BearerToken
helmCliConfig.CAFile = &restConf.CAFile
helmCliConfig.Namespace = &config.Namespace
err := actionConfig.Init(helmCliConfig, config.Namespace, "", config.Log)
if err != nil {
return nil, err
}
chart, err := loader.LoadDir(config.ChartDir)
if err != nil {
return nil, err
}
install := action.NewInstall(&actionConfig)
install.ReleaseName = config.ReleaseName
install.Namespace = config.Namespace
install.CreateNamespace = true
release, err := install.RunWithContext(ctx, chart, config.Values)
if err != nil {
return nil, err
}
return func(_ context.Context) error {
_, err := action.NewUninstall(&actionConfig).Run(release.Name)
return err
}, nil
}