github.com/sgoings/helm@v2.0.0-alpha.2.0.20170406211108-734e92851ac3+incompatible/cmd/helm/get_values.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/chartutil" 26 "k8s.io/helm/pkg/helm" 27 ) 28 29 var getValuesHelp = ` 30 This command downloads a values file for a given release. 31 ` 32 33 type getValuesCmd struct { 34 release string 35 allValues bool 36 out io.Writer 37 client helm.Interface 38 version int32 39 } 40 41 func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command { 42 get := &getValuesCmd{ 43 out: out, 44 client: client, 45 } 46 cmd := &cobra.Command{ 47 Use: "values [flags] RELEASE_NAME", 48 Short: "download the values file for a named release", 49 Long: getValuesHelp, 50 RunE: func(cmd *cobra.Command, args []string) error { 51 if len(args) == 0 { 52 return errReleaseRequired 53 } 54 get.release = args[0] 55 get.client = ensureHelmClient(get.client) 56 return get.run() 57 }, 58 } 59 60 cmd.Flags().Int32Var(&get.version, "revision", 0, "get the named release with revision") 61 cmd.Flags().BoolVarP(&get.allValues, "all", "a", false, "dump all (computed) values") 62 return cmd 63 } 64 65 // getValues implements 'helm get values' 66 func (g *getValuesCmd) run() error { 67 res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) 68 if err != nil { 69 return prettyError(err) 70 } 71 72 // If the user wants all values, compute the values and return. 73 if g.allValues { 74 cfg, err := chartutil.CoalesceValues(res.Release.Chart, res.Release.Config) 75 if err != nil { 76 return err 77 } 78 cfgStr, err := cfg.YAML() 79 if err != nil { 80 return err 81 } 82 fmt.Fprintln(g.out, cfgStr) 83 return nil 84 } 85 86 fmt.Fprintln(g.out, res.Release.Config.Raw) 87 return nil 88 }