github.com/darkowlzz/helm@v2.5.1-0.20171213183701-6707fe0468d4+incompatible/cmd/helm/get_manifest.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     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  
    23  	"github.com/spf13/cobra"
    24  
    25  	"k8s.io/helm/pkg/helm"
    26  )
    27  
    28  var getManifestHelp = `
    29  This command fetches the generated manifest for a given release.
    30  
    31  A manifest is a YAML-encoded representation of the Kubernetes resources that
    32  were generated from this release's chart(s). If a chart is dependent on other
    33  charts, those resources will also be included in the manifest.
    34  `
    35  
    36  type getManifestCmd struct {
    37  	release string
    38  	out     io.Writer
    39  	client  helm.Interface
    40  	version int32
    41  }
    42  
    43  func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command {
    44  	get := &getManifestCmd{
    45  		out:    out,
    46  		client: client,
    47  	}
    48  	cmd := &cobra.Command{
    49  		Use:     "manifest [flags] RELEASE_NAME",
    50  		Short:   "download the manifest for a named release",
    51  		Long:    getManifestHelp,
    52  		PreRunE: setupConnection,
    53  		RunE: func(cmd *cobra.Command, args []string) error {
    54  			if len(args) == 0 {
    55  				return errReleaseRequired
    56  			}
    57  			get.release = args[0]
    58  			if get.client == nil {
    59  				get.client = helm.NewClient(helm.Host(settings.TillerHost))
    60  			}
    61  			return get.run()
    62  		},
    63  	}
    64  
    65  	cmd.Flags().Int32Var(&get.version, "revision", 0, "get the named release with revision")
    66  	return cmd
    67  }
    68  
    69  // getManifest implements 'helm get manifest'
    70  func (g *getManifestCmd) run() error {
    71  	res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version))
    72  	if err != nil {
    73  		return prettyError(err)
    74  	}
    75  	fmt.Fprintln(g.out, res.Release.Manifest)
    76  	return nil
    77  }