Skip to content

Instantly share code, notes, and snippets.

@ilackarms
Created February 2, 2019 23:54
Show Gist options
  • Save ilackarms/143ae8fe012483232fece17c1f6da674 to your computer and use it in GitHub Desktop.
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
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