@@ -6,18 +6,8 @@ package cmd
66import (
77 "errors"
88 "fmt"
9- "io/ioutil"
109 "os"
11- "path/filepath"
1210 "strings"
13-
14- "github.com/ghodss/yaml"
15- "google.golang.org/grpc"
16- "k8s.io/helm/pkg/downloader"
17- "k8s.io/helm/pkg/getter"
18- "k8s.io/helm/pkg/helm/environment"
19- "k8s.io/helm/pkg/helm/helmpath"
20- "k8s.io/helm/pkg/strvals"
2111)
2212
2313/////////////// Source: cmd/helm/install.go /////////////////////////
@@ -57,143 +47,6 @@ func (v *valueFiles) Set(value string) error {
5747 return nil
5848}
5949
60- func locateChartPath (name , version string , verify bool , keyring string ) (string , error ) {
61- name = strings .TrimSpace (name )
62- version = strings .TrimSpace (version )
63- if fi , err := os .Stat (name ); err == nil {
64- abs , err := filepath .Abs (name )
65- if err != nil {
66- return abs , err
67- }
68- if verify {
69- if fi .IsDir () {
70- return "" , errors .New ("cannot verify a directory" )
71- }
72- if _ , err := downloader .VerifyChart (abs , keyring ); err != nil {
73- return "" , err
74- }
75- }
76- return abs , nil
77- }
78- if filepath .IsAbs (name ) || strings .HasPrefix (name , "." ) {
79- return name , fmt .Errorf ("path %q not found" , name )
80- }
81-
82- crepo := filepath .Join (helmpath .Home (homePath ()).Repository (), name )
83- if _ , err := os .Stat (crepo ); err == nil {
84- return filepath .Abs (crepo )
85- }
86-
87- dl := downloader.ChartDownloader {
88- HelmHome : helmpath .Home (homePath ()),
89- Out : os .Stdout ,
90- Keyring : keyring ,
91- Getters : getter .All (environment.EnvSettings {}),
92- }
93- if verify {
94- dl .Verify = downloader .VerifyAlways
95- }
96-
97- filename , _ , err := dl .DownloadTo (name , version , helmpath .Home (homePath ()).Archive ())
98- if err == nil {
99- lname , err := filepath .Abs (filename )
100- if err != nil {
101- return filename , err
102- }
103- return lname , nil
104- }
105-
106- return filename , err
107- }
108-
109- // Merges source and destination map, preferring values from the source map
110- func mergeValues (dest map [string ]interface {}, src map [string ]interface {}) map [string ]interface {} {
111- for k , v := range src {
112- // If the key doesn't exist already, then just set the key to that value
113- if _ , exists := dest [k ]; ! exists {
114- dest [k ] = v
115- continue
116- }
117- nextMap , ok := v .(map [string ]interface {})
118- // If it isn't another map, overwrite the value
119- if ! ok {
120- dest [k ] = v
121- continue
122- }
123- // If the key doesn't exist already, then just set the key to that value
124- if _ , exists := dest [k ]; ! exists {
125- dest [k ] = nextMap
126- continue
127- }
128- // Edge case: If the key exists in the destination, but isn't a map
129- destMap , isMap := dest [k ].(map [string ]interface {})
130- // If the source map has a map for this key, prefer it
131- if ! isMap {
132- dest [k ] = v
133- continue
134- }
135- // If we got to this point, it is a map in both, so merge them
136- dest [k ] = mergeValues (destMap , nextMap )
137- }
138- return dest
139- }
140-
141- /////////////// Source: cmd/helm/upgrade.go /////////////////////////
142-
143- func (d * diffCmd ) vals () ([]byte , error ) {
144- base := map [string ]interface {}{}
145-
146- // User specified a values files via -f/--values
147- for _ , filePath := range d .valueFiles {
148- currentMap := map [string ]interface {}{}
149-
150- var bytes []byte
151- var err error
152- if strings .TrimSpace (filePath ) == "-" {
153- bytes , err = ioutil .ReadAll (os .Stdin )
154- } else {
155- bytes , err = ioutil .ReadFile (filePath )
156- }
157- if err != nil {
158- return []byte {}, err
159- }
160-
161- if err := yaml .Unmarshal (bytes , & currentMap ); err != nil {
162- return []byte {}, fmt .Errorf ("failed to parse %s: %s" , filePath , err )
163- }
164- // Merge with the previous map
165- base = mergeValues (base , currentMap )
166- }
167-
168- // User specified a value via --set
169- for _ , value := range d .values {
170- if err := strvals .ParseInto (value , base ); err != nil {
171- return []byte {}, fmt .Errorf ("failed parsing --set data: %s" , err )
172- }
173- }
174-
175- // User specified a value via --set-string
176- for _ , value := range d .stringValues {
177- if err := strvals .ParseIntoString (value , base ); err != nil {
178- return []byte {}, fmt .Errorf ("failed parsing --set-string data: %s" , err )
179- }
180- }
181-
182- // User specified a value via --set-file
183- for _ , value := range d .fileValues {
184- reader := func (rs []rune ) (interface {}, error ) {
185- bytes , err := ioutil .ReadFile (string (rs ))
186- return string (bytes ), err
187- }
188-
189- if err := strvals .ParseIntoFile (value , base , reader ); err != nil {
190- return []byte {}, fmt .Errorf ("failed parsing --set-file data: %s" , err )
191- }
192- }
193-
194- return yaml .Marshal (base )
195- }
196-
19750/////////////// Source: cmd/helm/helm.go ////////////////////////////
19851
19952func checkArgsLength (argsReceived int , requiredArgs ... string ) error {
@@ -207,17 +60,3 @@ func checkArgsLength(argsReceived int, requiredArgs ...string) error {
20760 }
20861 return nil
20962}
210-
211- func homePath () string {
212- return os .Getenv ("HELM_HOME" )
213- }
214-
215- func prettyError (err error ) error {
216- if err == nil {
217- return nil
218- }
219- // This is ridiculous. Why is 'grpc.rpcError' not exported? The least they
220- // could do is throw an interface on the lib that would let us get back
221- // the desc. Instead, we have to pass ALL errors through this.
222- return errors .New (grpc .ErrorDesc (err ))
223- }
0 commit comments