Skip to content

Commit b56b772

Browse files
authored
Merge pull request #220 from arbourd/update-runtime
Use `MergeMaps` from pkg/runtime v0.8.2
2 parents 8f117d5 + 368ca98 commit b56b772

File tree

5 files changed

+6
-85
lines changed

5 files changed

+6
-85
lines changed

controllers/helmrelease_controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
"github.com/fluxcd/pkg/runtime/events"
5353
"github.com/fluxcd/pkg/runtime/metrics"
5454
"github.com/fluxcd/pkg/runtime/predicates"
55+
"github.com/fluxcd/pkg/runtime/transform"
5556
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
5657

5758
v2 "github.com/fluxcd/helm-controller/api/v2beta1"
@@ -588,7 +589,7 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
588589
if err != nil {
589590
return nil, fmt.Errorf("unable to read values from key '%s' in %s '%s': %w", v.GetValuesKey(), v.Kind, namespacedName, err)
590591
}
591-
result = util.MergeMaps(result, values)
592+
result = transform.MergeMaps(result, values)
592593
default:
593594
// TODO(hidde): this is a bit of hack, as it mimics the way the option string is passed
594595
// to Helm from a CLI perspective. Given the parser is however not publicly accessible
@@ -599,7 +600,7 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
599600
}
600601
}
601602
}
602-
return util.MergeMaps(result, hr.GetValues()), nil
603+
return transform.MergeMaps(result, hr.GetValues()), nil
603604
}
604605

605606
// reconcileDelete deletes the v1beta1.HelmChart of the v2beta1.HelmRelease,

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/fluxcd/helm-controller/api v0.7.0
99
github.com/fluxcd/pkg/apis/kustomize v0.0.1
1010
github.com/fluxcd/pkg/apis/meta v0.8.0
11-
github.com/fluxcd/pkg/runtime v0.8.1
11+
github.com/fluxcd/pkg/runtime v0.8.2
1212
github.com/fluxcd/source-controller/api v0.8.0
1313
github.com/go-logr/logr v0.3.0
1414
github.com/onsi/ginkgo v1.14.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ github.com/fluxcd/pkg/apis/meta v0.7.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/
248248
github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci/XOdk=
249249
github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po=
250250
github.com/fluxcd/pkg/runtime v0.6.2/go.mod h1:RuqYOYCvBJwo4rg83d28WOt2vfSaemuZCVpUagAjWQc=
251-
github.com/fluxcd/pkg/runtime v0.8.1 h1:8UxNz7GeI/HC3U5tpNCfrjRx2V7UjUegQOwCsd+EWxk=
252-
github.com/fluxcd/pkg/runtime v0.8.1/go.mod h1:tQwEN+RESjJmtwSSv7I+6bkNM9raIXpGsCjruaIVX6A=
251+
github.com/fluxcd/pkg/runtime v0.8.2 h1:NeQPw9srRH4zmu2eM+NJ9QdJMd0RcyOr4j5WiWQU8as=
252+
github.com/fluxcd/pkg/runtime v0.8.2/go.mod h1:tQwEN+RESjJmtwSSv7I+6bkNM9raIXpGsCjruaIVX6A=
253253
github.com/fluxcd/source-controller/api v0.8.0 h1:jOgeOwCLXzmjinRiDT7e/IuSB7WNZMgrUwMLJm09K/o=
254254
github.com/fluxcd/source-controller/api v0.8.0/go.mod h1:u2sdc/QDm0tzXHL7mZVj928hc3MMU+4mKCuAQg+94Bk=
255255
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=

internal/util/util.go

-24
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,6 @@ import (
2626
"sigs.k8s.io/controller-runtime/pkg/client"
2727
)
2828

29-
// MergeMaps merges map b into given map a and returns the result.
30-
// It allows overwrites of map values with flat values, and vice versa.
31-
// This is copied from https://github.com/helm/helm/blob/v3.3.0/pkg/cli/values/options.go#L88,
32-
// as the public chartutil.CoalesceTables function does not allow
33-
// overwriting maps with flat values.
34-
func MergeMaps(a, b map[string]interface{}) map[string]interface{} {
35-
out := make(map[string]interface{}, len(a))
36-
for k, v := range a {
37-
out[k] = v
38-
}
39-
for k, v := range b {
40-
if v, ok := v.(map[string]interface{}); ok {
41-
if bv, ok := out[k]; ok {
42-
if bv, ok := bv.(map[string]interface{}); ok {
43-
out[k] = MergeMaps(bv, v)
44-
continue
45-
}
46-
}
47-
}
48-
out[k] = v
49-
}
50-
return out
51-
}
52-
5329
// ValuesChecksum calculates and returns the SHA1 checksum for the
5430
// given chartutil.Values.
5531
func ValuesChecksum(values chartutil.Values) string {

internal/util/util_test.go

-56
Original file line numberDiff line numberDiff line change
@@ -17,68 +17,12 @@ limitations under the License.
1717
package util
1818

1919
import (
20-
"reflect"
2120
"testing"
2221

2322
"helm.sh/helm/v3/pkg/chartutil"
2423
"helm.sh/helm/v3/pkg/release"
2524
)
2625

27-
func TestMergeMaps(t *testing.T) {
28-
nestedMap := map[string]interface{}{
29-
"foo": "bar",
30-
"baz": map[string]string{
31-
"cool": "stuff",
32-
},
33-
}
34-
anotherNestedMap := map[string]interface{}{
35-
"foo": "bar",
36-
"baz": map[string]string{
37-
"cool": "things",
38-
"awesome": "stuff",
39-
},
40-
}
41-
flatMap := map[string]interface{}{
42-
"foo": "bar",
43-
"baz": "stuff",
44-
}
45-
anotherFlatMap := map[string]interface{}{
46-
"testing": "fun",
47-
}
48-
49-
testMap := MergeMaps(flatMap, nestedMap)
50-
equal := reflect.DeepEqual(testMap, nestedMap)
51-
if !equal {
52-
t.Errorf("Expected a nested map to overwrite a flat value. Expected: %v, got %v", nestedMap, testMap)
53-
}
54-
55-
testMap = MergeMaps(nestedMap, flatMap)
56-
equal = reflect.DeepEqual(testMap, flatMap)
57-
if !equal {
58-
t.Errorf("Expected a flat value to overwrite a map. Expected: %v, got %v", flatMap, testMap)
59-
}
60-
61-
testMap = MergeMaps(nestedMap, anotherNestedMap)
62-
equal = reflect.DeepEqual(testMap, anotherNestedMap)
63-
if !equal {
64-
t.Errorf("Expected a nested map to overwrite another nested map. Expected: %v, got %v", anotherNestedMap, testMap)
65-
}
66-
67-
testMap = MergeMaps(anotherFlatMap, anotherNestedMap)
68-
expectedMap := map[string]interface{}{
69-
"testing": "fun",
70-
"foo": "bar",
71-
"baz": map[string]string{
72-
"cool": "things",
73-
"awesome": "stuff",
74-
},
75-
}
76-
equal = reflect.DeepEqual(testMap, expectedMap)
77-
if !equal {
78-
t.Errorf("Expected a map with different keys to merge properly with another map. Expected: %v, got %v", expectedMap, testMap)
79-
}
80-
}
81-
8226
func TestValuesChecksum(t *testing.T) {
8327
tests := []struct {
8428
name string

0 commit comments

Comments
 (0)