generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 94
/
helm.go
45 lines (40 loc) · 1.13 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
package kubernetes
import (
"bytes"
"fmt"
"strings"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
)
// Though we are using the same config that is used for installing/uninstalling helm charts.
// We will only make use of URL/ChartLocation/LocalPath to get and load the helm chart
func ConvertHelmChartToK8sManifest(cfg ApplyHelmChartConfig) (manifest []byte, err error) {
setupDefaults(&cfg)
if err := setupChartVersion(&cfg); err != nil {
return nil, ErrApplyHelmChart(err)
}
localPath, err := getHelmLocalPath(cfg)
if err != nil {
return nil, ErrApplyHelmChart(err)
}
helmChart, err := loader.Load(localPath)
if err != nil {
return nil, ErrApplyHelmChart(err)
}
actconfig := new(action.Configuration)
act := action.NewInstall(actconfig)
act.ReleaseName = "test-release"
act.CreateNamespace = true
act.Namespace = "default"
act.DryRun = true
act.IncludeCRDs = true
act.ClientOnly = true
rel, err := act.Run(helmChart, nil)
if err != nil {
return nil, ErrApplyHelmChart(err)
}
var manifests bytes.Buffer
fmt.Fprintln(&manifests, strings.TrimSpace(rel.Manifest))
manifest = manifests.Bytes()
return
}