Merge pull request #4920 from adamreese/ref/chart

ref(pkg/chart): rename files to be consistent with types
pull/4927/head
Adam Reese 7 years ago committed by GitHub
commit f9d3280841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,6 +15,9 @@ limitations under the License.
package chart package chart
// APIVersionv1 is the API version number for version 1.
const APIVersionv1 = "v1"
// Chart is a helm package that contains metadata, a default config, zero or more // Chart is a helm package that contains metadata, a default config, zero or more
// optionally parameterizable templates, and zero or more charts (dependencies). // optionally parameterizable templates, and zero or more charts (dependencies).
type Chart struct { type Chart struct {

@ -1,19 +0,0 @@
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package chart
// APIVersionv1 is the API version number for version 1.
const APIVersionv1 = "v1"

@ -205,29 +205,18 @@ func pathToMap(path string, data map[string]interface{}) map[string]interface{}
if path == "." { if path == "." {
return data return data
} }
ap := strings.Split(path, ".") return set(parsePath(path), data)
if len(ap) == 0 { }
func set(path []string, data map[string]interface{}) map[string]interface{} {
if len(path) == 0 {
return nil return nil
} }
n := []map[string]interface{}{} cur := data
// created nested map for each key, adding to slice for i := len(path) - 1; i >= 0; i-- {
for _, v := range ap { cur = map[string]interface{}{path[i]: cur}
nm := make(map[string]interface{})
nm[v] = make(map[string]interface{})
n = append(n, nm)
}
// find the last key (map) and set our data
for i, d := range n {
for k := range d {
z := i + 1
if z == len(n) {
n[i][k] = data
break
}
n[i][k] = n[z]
}
} }
return n[0] return cur
} }
// processImportValues merges values from child to parent based on the chart's dependencies' ImportValues field. // processImportValues merges values from child to parent based on the chart's dependencies' ImportValues field.
@ -247,27 +236,29 @@ func processImportValues(c *chart.Chart) error {
for _, riv := range r.ImportValues { for _, riv := range r.ImportValues {
switch iv := riv.(type) { switch iv := riv.(type) {
case map[string]interface{}: case map[string]interface{}:
nm := map[string]string{ child := iv["child"].(string)
"child": iv["child"].(string), parent := iv["parent"].(string)
"parent": iv["parent"].(string),
} outiv = append(outiv, map[string]string{
outiv = append(outiv, nm) "child": child,
"parent": parent,
})
// get child table // get child table
vv, err := cvals.Table(r.Name + "." + nm["child"]) vv, err := cvals.Table(r.Name + "." + child)
if err != nil { if err != nil {
log.Printf("Warning: ImportValues missing table: %v", err) log.Printf("Warning: ImportValues missing table: %v", err)
continue continue
} }
// create value map from child to be merged into parent // create value map from child to be merged into parent
vm := pathToMap(nm["parent"], vv.AsMap()) b = coalesceTables(cvals, pathToMap(parent, vv.AsMap()))
b = coalesceTables(cvals, vm)
case string: case string:
nm := map[string]string{ child := "exports." + iv
"child": "exports." + iv, outiv = append(outiv, map[string]string{
"child": child,
"parent": ".", "parent": ".",
} })
outiv = append(outiv, nm) vm, err := cvals.Table(r.Name + "." + child)
vm, err := cvals.Table(r.Name + "." + nm["child"])
if err != nil { if err != nil {
log.Printf("Warning: ImportValues missing table: %v", err) log.Printf("Warning: ImportValues missing table: %v", err)
continue continue

@ -62,7 +62,7 @@ func (v Values) Table(name string) (Values, error) {
table := v table := v
var err error var err error
for _, n := range strings.Split(name, ".") { for _, n := range parsePath(name) {
table, err = tableLookup(table, n) table, err = tableLookup(table, n)
if err != nil { if err != nil {
return table, err return table, err
@ -118,7 +118,7 @@ func ReadValues(data []byte) (vals Values, err error) {
if len(vals) == 0 { if len(vals) == 0 {
vals = Values{} vals = Values{}
} }
return return vals, err
} }
// ReadValuesFile will parse a YAML file into a map of values. // ReadValuesFile will parse a YAML file into a map of values.
@ -240,11 +240,11 @@ func coalesceGlobals(dest, src map[string]interface{}) {
} }
func copyMap(src map[string]interface{}) map[string]interface{} { func copyMap(src map[string]interface{}) map[string]interface{} {
dest := make(map[string]interface{}, len(src)) m := make(map[string]interface{}, len(src))
for k, v := range src { for k, v := range src {
dest[k] = v m[k] = v
} }
return dest return m
} }
// coalesceValues builds up a values map for a particular chart. // coalesceValues builds up a values map for a particular chart.
@ -350,40 +350,35 @@ func istable(v interface{}) bool {
// chapter: // chapter:
// one: // one:
// title: "Loomings" // title: "Loomings"
func (v Values) PathValue(ypath string) (interface{}, error) { func (v Values) PathValue(path string) (interface{}, error) {
if len(ypath) == 0 { if path == "" {
return nil, errors.New("YAML path string cannot be zero length") return nil, errors.New("YAML path cannot be empty")
} }
yps := strings.Split(ypath, ".") return v.pathValue(parsePath(path))
if len(yps) == 1 { }
func (v Values) pathValue(path []string) (interface{}, error) {
if len(path) == 1 {
// if exists must be root key not table // if exists must be root key not table
vals := v.AsMap() if _, ok := v[path[0]]; ok && !istable(v[path[0]]) {
k := yps[0] return v[path[0]], nil
if _, ok := vals[k]; ok && !istable(vals[k]) {
// key found
return vals[yps[0]], nil
} }
// key not found return nil, ErrNoValue(errors.Errorf("%v is not a value", path[0]))
return nil, ErrNoValue(errors.Errorf("%v is not a value", k))
} }
// join all elements of YAML path except last to get string table path
ypsLen := len(yps) key, path := path[len(path)-1], path[:len(path)-1]
table := yps[:ypsLen-1]
st := strings.Join(table, ".")
// get the last element as a string key
sk := yps[ypsLen-1:][0]
// get our table for table path // get our table for table path
t, err := v.Table(st) t, err := v.Table(joinPath(path...))
if err != nil { if err != nil {
//no table return nil, ErrNoValue(errors.Errorf("%v is not a value", key))
return nil, ErrNoValue(errors.Errorf("%v is not a value", sk))
} }
// check table for key and ensure value is not a table // check table for key and ensure value is not a table
if k, ok := t[sk]; ok && !istable(k) { if k, ok := t[key]; ok && !istable(k) {
// key found
return k, nil return k, nil
} }
return nil, ErrNoValue(errors.Errorf("key not found: %s", key))
// key not found
return nil, ErrNoValue(errors.Errorf("key not found: %s", sk))
} }
func parsePath(key string) []string { return strings.Split(key, ".") }
func joinPath(path ...string) string { return strings.Join(path, ".") }

Loading…
Cancel
Save