github.com/appscode/helm@v3.0.0-alpha.1+incompatible/cmd/helm/template.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 main 18 19 import ( 20 "fmt" 21 "io" 22 "io/ioutil" 23 "strings" 24 25 "github.com/spf13/cobra" 26 27 "helm.sh/helm/cmd/helm/require" 28 "helm.sh/helm/pkg/action" 29 "helm.sh/helm/pkg/chartutil" 30 "helm.sh/helm/pkg/kube" 31 "helm.sh/helm/pkg/storage" 32 "helm.sh/helm/pkg/storage/driver" 33 ) 34 35 const templateDesc = ` 36 Render chart templates locally and display the output. 37 38 This does not require Helm. However, 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 To render just one template in a chart, use '-x': 44 45 $ helm template foo mychart -x templates/deployment.yaml 46 ` 47 48 func newTemplateCmd(out io.Writer) *cobra.Command { 49 customConfig := &action.Configuration{ 50 // Add mock objects in here so it doesn't use Kube API server 51 Releases: storage.Init(driver.NewMemory()), 52 KubeClient: &kube.PrintingKubeClient{Out: ioutil.Discard}, 53 Capabilities: chartutil.DefaultCapabilities, 54 Log: func(format string, v ...interface{}) { 55 fmt.Fprintf(out, format, v...) 56 }, 57 } 58 59 client := action.NewInstall(customConfig) 60 61 cmd := &cobra.Command{ 62 Use: "template [NAME] [CHART]", 63 Short: fmt.Sprintf("locally render templates"), 64 Long: templateDesc, 65 Args: require.MinimumNArgs(1), 66 RunE: func(_ *cobra.Command, args []string) error { 67 client.DryRun = true 68 client.ReleaseName = "RELEASE-NAME" 69 client.Replace = true // Skip the name check 70 rel, err := runInstall(args, client, out) 71 if err != nil { 72 return err 73 } 74 fmt.Fprintln(out, strings.TrimSpace(rel.Manifest)) 75 return nil 76 }, 77 } 78 79 addInstallFlags(cmd.Flags(), client) 80 81 return cmd 82 }