Skip to content

Commit

Permalink
Merge pull request #10426 from olemarkus/bump-helm-v3
Browse files Browse the repository at this point in the history
Bump helm to v3
  • Loading branch information
k8s-ci-robot committed Dec 17, 2020
2 parents 78ea629 + 24c9d03 commit d248e3e
Show file tree
Hide file tree
Showing 283 changed files with 45,143 additions and 660 deletions.
4 changes: 3 additions & 1 deletion cmd/kops/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ go_library(
"//vendor/github.com/spf13/cobra/doc:go_default_library",
"//vendor/github.com/spf13/viper:go_default_library",
"//vendor/golang.org/x/crypto/ssh:go_default_library",
"//vendor/helm.sh/helm/pkg/strvals:go_default_library",
"//vendor/helm.sh/helm/v3/pkg/cli/values:go_default_library",
"//vendor/helm.sh/helm/v3/pkg/strvals:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
Expand Down Expand Up @@ -156,6 +157,7 @@ go_test(
"//channels:channeldata", # keep
"//tests/integration/create_cluster:exported_testdata", # keep
"//tests/integration/update_cluster:exported_testdata", # keep
"test/values.yaml",
],
embed = [":go_default_library"],
shard_count = 10,
Expand Down
4 changes: 4 additions & 0 deletions cmd/kops/test/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Foo: "bar"
Bar:
Foo:
Bar: "foo"
44 changes: 13 additions & 31 deletions cmd/kops/toolbox_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import (
"strings"

"github.com/spf13/cobra"
"helm.sh/helm/pkg/strvals"
"helm.sh/helm/v3/pkg/strvals"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"sigs.k8s.io/yaml"

helmvalues "helm.sh/helm/v3/pkg/cli/values"

"k8s.io/kops/cmd/kops/util"
kopsapi "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/try"
Expand Down Expand Up @@ -250,7 +252,16 @@ func newTemplateContext(files []string, values []string, stringValues []string)
return nil, fmt.Errorf("unable decode the configuration file: %s, error: %v", j, err)
}

context = mergeValues(context, ctx)
valueOpts := &helmvalues.Options{
Values: values,
ValueFiles: files,
StringValues: stringValues,
}

context, err = valueOpts.MergeValues(nil)
if err != nil {
return nil, err
}
}
}

Expand All @@ -271,35 +282,6 @@ func newTemplateContext(files []string, values []string, stringValues []string)
return context, nil
}

// Merges source and destination map, preferring values from the source map
// Copied from the Helm (https://github.com/kubernetes/helm) project:
// https://github.com/kubernetes/helm/blob/282984e75fd115a0765730efe09d8257c72fa56d/cmd/helm/install.go#L302
func mergeValues(dest map[string]interface{}, src map[string]interface{}) map[string]interface{} {
for k, v := range src {
// If the key doesn't exist already, then just set the key to that value
if _, exists := dest[k]; !exists {
dest[k] = v
continue
}
nextMap, ok := v.(map[string]interface{})
// If it isn't another map, overwrite the value
if !ok {
dest[k] = v
continue
}
// Edge case: If the key exists in the destination, but isn't a map
destMap, isMap := dest[k].(map[string]interface{})
// If the source map has a map for this key, prefer it
if !isMap {
dest[k] = v
continue
}
// If we got to this point, it is a map in both, so merge them
dest[k] = mergeValues(destMap, nextMap)
}
return dest
}

// expandFiles is responsible for resolving any references to directories
func expandFiles(path string) ([]string, error) {
// @check if the path is a directory, if not we can return straight away
Expand Down
59 changes: 4 additions & 55 deletions cmd/kops/toolbox_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,12 @@ limitations under the License.
package main

import (
"reflect"
"testing"
)

// Copied from the Helm (https://github.com/kubernetes/helm) project:
// https://github.com/kubernetes/helm/blob/282984e75fd115a0765730efe09d8257c72fa56d/cmd/helm/install_test.go#L230
func TestMergeValues(t *testing.T) {
nestedMap := map[string]interface{}{
"foo": "bar",
"baz": map[string]string{
"cool": "stuff",
},
}
anotherNestedMap := map[string]interface{}{
"foo": "bar",
"baz": map[string]string{
"cool": "things",
"awesome": "stuff",
},
}
flatMap := map[string]interface{}{
"foo": "bar",
"baz": "stuff",
}
anotherFlatMap := map[string]interface{}{
"testing": "fun",
}

testMap := mergeValues(flatMap, nestedMap)
equal := reflect.DeepEqual(testMap, nestedMap)
if !equal {
t.Errorf("Expected a nested map to overwrite a flat value. Expected: %v, got %v", nestedMap, testMap)
}

testMap = mergeValues(nestedMap, flatMap)
equal = reflect.DeepEqual(testMap, flatMap)
if !equal {
t.Errorf("Expected a flat value to overwrite a map. Expected: %v, got %v", flatMap, testMap)
}

testMap = mergeValues(nestedMap, anotherNestedMap)
equal = reflect.DeepEqual(testMap, anotherNestedMap)
if !equal {
t.Errorf("Expected a nested map to overwrite another nested map. Expected: %v, got %v", anotherNestedMap, testMap)
}

testMap = mergeValues(anotherFlatMap, anotherNestedMap)
expectedMap := map[string]interface{}{
"testing": "fun",
"foo": "bar",
"baz": map[string]string{
"cool": "things",
"awesome": "stuff",
},
}
equal = reflect.DeepEqual(testMap, expectedMap)
if !equal {
t.Errorf("Expected a map with different keys to merge properly with another map. Expected: %v, got %v", expectedMap, testMap)
func TestNewTemplateContext(t *testing.T) {
context, _ := newTemplateContext([]string{"test/values.yaml"}, []string{"Foo=baz"}, []string{})
if context["Foo"] != "baz" {
t.Errorf("Got %v, expected baz", context["foo"])
}
}
2 changes: 2 additions & 0 deletions docs/releases/1.20-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Added [template funtions](https://kops.sigs.k8s.io/operations/cluster_template/#template-functions) for kubernetes version based on channel data.

* kOps now use helm3 functions for merging template `--set` and `--values` arguments. This has slightly different behaviour than previous helm2-like logic.

# Breaking changes

* Support for Kubernetes 1.11 and 1.12 has been removed.
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ require (
github.com/weaveworks/mesh v0.0.0-20170419100114-1f158d31de55
github.com/zclconf/go-cty v1.3.1
go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489
go.uber.org/zap v1.10.0
go.uber.org/zap v1.13.0
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
Expand All @@ -101,7 +101,7 @@ require (
gopkg.in/gcfg.v1 v1.2.3
gopkg.in/inf.v0 v0.9.1
gopkg.in/yaml.v2 v2.3.0
helm.sh/helm v2.17.0+incompatible
helm.sh/helm/v3 v3.4.2
k8s.io/api v0.20.0
k8s.io/apimachinery v0.20.0
k8s.io/cli-runtime v0.20.0
Expand All @@ -110,7 +110,7 @@ require (
k8s.io/component-base v0.20.0
k8s.io/gengo v0.0.0-20201113003025-83324d819ded
k8s.io/klog/v2 v2.4.0
k8s.io/kubectl v0.0.0
k8s.io/kubectl v0.19.4
k8s.io/legacy-cloud-providers v0.0.0
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
sigs.k8s.io/controller-runtime v0.6.1
Expand Down
Loading

0 comments on commit d248e3e

Please sign in to comment.