feat(helm): allow templating remote charts

The 'helm template' command can now process charts from remote
repositories.

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
pull/5809/head
Arash Deshmeh 6 years ago
parent ed2373629b
commit 4a3147f958

@ -76,6 +76,18 @@ type templateCmd struct {
renderFiles []string renderFiles []string
kubeVersion string kubeVersion string
outputDir string outputDir string
verify bool
keyring string
version string
repoURL string
username string
password string
devel bool
certFile string
keyFile string
caFile string
} }
func newTemplateCmd(out io.Writer) *cobra.Command { func newTemplateCmd(out io.Writer) *cobra.Command {
@ -104,6 +116,16 @@ func newTemplateCmd(out io.Writer) *cobra.Command {
f.StringVar(&t.nameTemplate, "name-template", "", "specify template used to name the release") f.StringVar(&t.nameTemplate, "name-template", "", "specify template used to name the release")
f.StringVar(&t.kubeVersion, "kube-version", defaultKubeVersion, "kubernetes version used as Capabilities.KubeVersion.Major/Minor") f.StringVar(&t.kubeVersion, "kube-version", defaultKubeVersion, "kubernetes version used as Capabilities.KubeVersion.Major/Minor")
f.StringVar(&t.outputDir, "output-dir", "", "writes the executed templates to files in output-dir instead of stdout") f.StringVar(&t.outputDir, "output-dir", "", "writes the executed templates to files in output-dir instead of stdout")
f.StringVar(&t.version, "version", "", "version of the chart. By default, the newest chart is selected")
f.BoolVar(&t.verify, "verify", false, "verify the provenance data for this chart")
f.StringVar(&t.keyring, "keyring", defaultKeyring(), "location of public keys used for verification")
f.StringVar(&t.repoURL, "repo", "", "chart repository url where to locate the requested chart")
f.StringVar(&t.username, "username", "", "chart repository username where to locate the requested chart")
f.StringVar(&t.password, "password", "", "chart repository password where to locate the requested chart")
f.BoolVar(&t.devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.")
f.StringVar(&t.certFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")
f.StringVar(&t.keyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.StringVar(&t.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
return cmd return cmd
} }
@ -112,12 +134,8 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
if len(args) < 1 { if len(args) < 1 {
return errors.New("chart is required") return errors.New("chart is required")
} }
// verify chart path exists
if _, err := os.Stat(args[0]); err == nil { if err := t.prepareChart(args[0]); err != nil {
if t.chartPath, err = filepath.Abs(args[0]); err != nil {
return err
}
} else {
return err return err
} }
@ -253,6 +271,30 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
return nil return nil
} }
func (t *templateCmd) prepareChart(chart string) error {
// verify chart path exists or can be fetched from remote repo
if _, err := os.Stat(chart); err == nil {
if t.chartPath, err = filepath.Abs(chart); err != nil {
return err
}
return nil
}
debug("Original chart version: %q", t.version)
if t.version == "" && t.devel {
debug("setting version to >0.0.0-0")
t.version = ">0.0.0-0"
}
cp, err := locateChartPath(t.repoURL, t.username, t.password, chart, t.version, false, t.keyring,
t.certFile, t.keyFile, t.caFile)
if err != nil {
return err
}
t.chartPath = cp
return nil
}
// write the <data> to <output-dir>/<name> // write the <data> to <output-dir>/<name>
func writeToFile(outputDir string, name string, data string) error { func writeToFile(outputDir string, name string, data string) error {
outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator)) outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator))

@ -24,19 +24,29 @@ helm template [flags] CHART
### Options ### Options
``` ```
--ca-file string verify certificates of HTTPS-enabled servers using this CA bundle
--cert-file string identify HTTPS client using this SSL certificate file
--devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
-x, --execute stringArray only execute the given templates -x, --execute stringArray only execute the given templates
-h, --help help for template -h, --help help for template
--is-upgrade set .Release.IsUpgrade instead of .Release.IsInstall --is-upgrade set .Release.IsUpgrade instead of .Release.IsInstall
--key-file string identify HTTPS client using this SSL key file
--keyring string location of public keys used for verification (default "~/.gnupg/pubring.gpg")
--kube-version string kubernetes version used as Capabilities.KubeVersion.Major/Minor (default "1.9") --kube-version string kubernetes version used as Capabilities.KubeVersion.Major/Minor (default "1.9")
-n, --name string release name (default "release-name") -n, --name string release name (default "release-name")
--name-template string specify template used to name the release --name-template string specify template used to name the release
--namespace string namespace to install the release into --namespace string namespace to install the release into
--notes show the computed NOTES.txt file as well --notes show the computed NOTES.txt file as well
--output-dir string writes the executed templates to files in output-dir instead of stdout --output-dir string writes the executed templates to files in output-dir instead of stdout
--password string chart repository password where to locate the requested chart
--repo string chart repository url where to locate the requested chart
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) --set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--set-file stringArray set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2) --set-file stringArray set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)
--set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) --set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--username string chart repository username where to locate the requested chart
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default []) -f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
--verify verify the provenance data for this chart
--version string version of the chart. By default, the newest chart is selected
``` ```
### Options inherited from parent commands ### Options inherited from parent commands
@ -55,4 +65,4 @@ helm template [flags] CHART
* [helm](helm.md) - The Helm package manager for Kubernetes. * [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 1-Aug-2018 ###### Auto generated by spf13/cobra on 28-May-2019

Loading…
Cancel
Save