github.com/sdbaiguanghe/helm@v2.16.7+incompatible/cmd/helm/get_manifest.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 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: func(_ *cobra.Command, _ []string) error { return 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 get.client = ensureHelmClient(get.client) 59 return get.run() 60 }, 61 } 62 63 f := cmd.Flags() 64 settings.AddFlagsTLS(f) 65 f.Int32Var(&get.version, "revision", 0, "Get the named release with revision") 66 67 // set defaults from environment 68 settings.InitTLS(f) 69 70 return cmd 71 } 72 73 // getManifest implements 'helm get manifest' 74 func (g *getManifestCmd) run() error { 75 res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) 76 if err != nil { 77 return prettyError(err) 78 } 79 fmt.Fprintln(g.out, res.Release.Manifest) 80 return nil 81 }