github.com/gridai/helm@v3.0.0-beta.3+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  	"strings"
    23  
    24  	"github.com/spf13/cobra"
    25  
    26  	"helm.sh/helm/cmd/helm/require"
    27  	"helm.sh/helm/pkg/action"
    28  	"helm.sh/helm/pkg/cli/values"
    29  )
    30  
    31  const templateDesc = `
    32  Render chart templates locally and display the output.
    33  
    34  Any values that would normally be looked up or retrieved in-cluster will be
    35  faked locally. Additionally, none of the server-side testing of chart validity
    36  (e.g. whether an API is supported) is done.
    37  `
    38  
    39  func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
    40  	var validate bool
    41  	client := action.NewInstall(cfg)
    42  	valueOpts := &values.Options{}
    43  
    44  	cmd := &cobra.Command{
    45  		Use:   "template [NAME] [CHART]",
    46  		Short: fmt.Sprintf("locally render templates"),
    47  		Long:  templateDesc,
    48  		Args:  require.MinimumNArgs(1),
    49  		RunE: func(_ *cobra.Command, args []string) error {
    50  			client.DryRun = true
    51  			client.ReleaseName = "RELEASE-NAME"
    52  			client.Replace = true // Skip the name check
    53  			client.ClientOnly = !validate
    54  			rel, err := runInstall(args, client, valueOpts, out)
    55  			if err != nil {
    56  				return err
    57  			}
    58  			fmt.Fprintln(out, strings.TrimSpace(rel.Manifest))
    59  			return nil
    60  		},
    61  	}
    62  
    63  	f := cmd.Flags()
    64  	addInstallFlags(f, client, valueOpts)
    65  	f.StringVar(&client.OutputDir, "output-dir", "", "writes the executed templates to files in output-dir instead of stdout")
    66  	f.BoolVar(&validate, "validate", false, "establish a connection to Kubernetes for schema validation")
    67  
    68  	return cmd
    69  }