-
Notifications
You must be signed in to change notification settings - Fork 216
/
template.go
42 lines (32 loc) · 1.09 KB
/
template.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 helmdeployer
import (
"io"
"github.com/rancher/fleet/internal/manifest"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chartutil"
kubefake "helm.sh/helm/v3/pkg/kube/fake"
"helm.sh/helm/v3/pkg/storage"
"helm.sh/helm/v3/pkg/storage/driver"
"k8s.io/apimachinery/pkg/runtime"
)
// Template runs helm template and returns the resources as a list of objects, without applying them.
func Template(bundleID string, manifest *manifest.Manifest, options fleet.BundleDeploymentOptions) ([]runtime.Object, error) {
h := &Helm{
globalCfg: action.Configuration{},
useGlobalCfg: true,
template: true,
}
mem := driver.NewMemory()
mem.SetNamespace("default")
h.globalCfg.Capabilities = chartutil.DefaultCapabilities
h.globalCfg.KubeClient = &kubefake.PrintingKubeClient{Out: io.Discard}
h.globalCfg.Log = logrus.Infof
h.globalCfg.Releases = storage.Init(mem)
resources, err := h.Deploy(bundleID, manifest, options)
if err != nil {
return nil, err
}
return resources.Objects, nil
}