github.com/koderover/helm@v2.17.0+incompatible/pkg/renderutil/render.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package renderutil 18 19 import ( 20 "fmt" 21 22 "github.com/Masterminds/semver" 23 24 "k8s.io/helm/pkg/chartutil" 25 "k8s.io/helm/pkg/engine" 26 "k8s.io/helm/pkg/proto/hapi/chart" 27 tversion "k8s.io/helm/pkg/version" 28 ) 29 30 // Options are options for this simple local render 31 type Options struct { 32 ReleaseOptions chartutil.ReleaseOptions 33 KubeVersion string 34 APIVersions []string 35 } 36 37 // Render chart templates locally and display the output. 38 // This does not require the Tiller. Any values that would normally be 39 // looked up or retrieved in-cluster will be faked locally. Additionally, none 40 // of the server-side testing of chart validity (e.g. whether an API is supported) 41 // is done. 42 // 43 // Note: a `nil` config passed here means "ignore the chart's default values"; 44 // if you want the normal behavior of merging the defaults with the new config, 45 // you should pass `&chart.Config{Raw: "{}"}, 46 func Render(c *chart.Chart, config *chart.Config, opts Options) (map[string]string, error) { 47 if req, err := chartutil.LoadRequirements(c); err == nil { 48 if err := CheckDependencies(c, req); err != nil { 49 return nil, err 50 } 51 } else if err != chartutil.ErrRequirementsNotFound { 52 return nil, fmt.Errorf("cannot load requirements: %v", err) 53 } 54 55 err := chartutil.ProcessRequirementsEnabled(c, config) 56 if err != nil { 57 return nil, err 58 } 59 err = chartutil.ProcessRequirementsImportValues(c) 60 if err != nil { 61 return nil, err 62 } 63 64 // Set up engine. 65 renderer := engine.New() 66 67 caps := &chartutil.Capabilities{ 68 APIVersions: chartutil.DefaultVersionSet, 69 KubeVersion: chartutil.DefaultKubeVersion, 70 TillerVersion: tversion.GetVersionProto(), 71 } 72 73 if opts.KubeVersion != "" { 74 kv, verErr := semver.NewVersion(opts.KubeVersion) 75 if verErr != nil { 76 return nil, fmt.Errorf("could not parse a kubernetes version: %v", verErr) 77 } 78 caps.KubeVersion.Major = fmt.Sprint(kv.Major()) 79 caps.KubeVersion.Minor = fmt.Sprint(kv.Minor()) 80 caps.KubeVersion.GitVersion = fmt.Sprintf("v%d.%d.0", kv.Major(), kv.Minor()) 81 } 82 83 if len(opts.APIVersions) > 0 { 84 caps.APIVersions = chartutil.NewVersionSet(append(opts.APIVersions, "v1")...) 85 } 86 87 vals, err := chartutil.ToRenderValuesCaps(c, config, opts.ReleaseOptions, caps) 88 if err != nil { 89 return nil, err 90 } 91 92 return renderer.Render(c, vals) 93 }