Created
February 2, 2019 23:54
-
-
Save ilackarms/143ae8fe012483232fece17c1f6da674 to your computer and use it in GitHub Desktop.
poc of helm without tiller or the helm cli. render charts in a go function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package helm | |
import ( | |
"fmt" | |
"github.com/solo-io/go-utils/errors" | |
"k8s.io/helm/pkg/chartutil" | |
"k8s.io/helm/pkg/proto/hapi/chart" | |
"k8s.io/helm/pkg/renderutil" | |
"k8s.io/helm/pkg/timeconv" | |
) | |
var defaultKubeVersion = fmt.Sprintf("%s.%s", chartutil.DefaultKubeVersion.Major, chartutil.DefaultKubeVersion.Minor) | |
func RenderTemplate(chartPath, values, releaseName, namespace, kubeVersion string, releaseIsInstall bool) (map[string]string, error) { | |
if kubeVersion == "" { | |
kubeVersion = defaultKubeVersion | |
} | |
renderOpts := renderutil.Options{ | |
ReleaseOptions: chartutil.ReleaseOptions{ | |
Name: releaseName, | |
IsInstall: releaseIsInstall, | |
IsUpgrade: !releaseIsInstall, | |
Time: timeconv.Now(), | |
Namespace: namespace, | |
}, | |
KubeVersion: kubeVersion, | |
} | |
// Check chart requirements to make sure all dependencies are present in /charts | |
c, err := chartutil.Load(chartPath) | |
if err != nil { | |
return nil, errors.Wrapf(err, "loading chart") | |
} | |
config := &chart.Config{Raw: values, Values: map[string]*chart.Value{}} | |
renderedTemplates, err := renderutil.Render(c, config, renderOpts) | |
if err != nil { | |
return nil, err | |
} | |
return renderedTemplates, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment