Skip to content

Commit bf7a308

Browse files
committed
PR-676 update code based on review
Signed-off-by: longquan0104 <longquan0104@gmail.com>
1 parent 45c9623 commit bf7a308

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ api-docs: gen-crd-api-reference-docs
8585

8686
# Run go mod tidy
8787
tidy:
88-
cd api; rm -f go.sum; go mod tidy -compat=1.19
89-
rm -f go.sum; go mod tidy -compat=1.19
88+
cd api; rm -f go.sum; go mod tidy -compat=1.20
89+
rm -f go.sum; go mod tidy -compat=1.20
9090

9191
# Run go fmt against code
9292
fmt:

internal/util/util.go

+18-27
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,25 @@ import (
2222
"sort"
2323

2424
goyaml "gopkg.in/yaml.v2"
25+
"helm.sh/helm/v3/pkg/chartutil"
2526
"helm.sh/helm/v3/pkg/release"
2627
"sigs.k8s.io/yaml"
2728
)
2829

2930
// ValuesChecksum calculates and returns the SHA1 checksum for the
3031
// given chartutil.Values.
31-
func ValuesChecksum(values map[string]interface{}) string {
32-
newValues := copyValues(values)
33-
var (
34-
s []byte
35-
err error
36-
)
37-
38-
if len(newValues) != 0 {
39-
// cleanUpInterfaceMap
40-
for i, value := range newValues {
41-
newValues[i] = cleanUpMapValue(value)
42-
}
32+
func ValuesChecksum(values chartutil.Values) string {
33+
var s []byte
34+
if len(values) != 0 {
35+
// Check sum on the formatted values
36+
newValues := copyValues(values)
4337
msValues := yaml.JSONObjectToYAMLObject(newValues)
4438
// Sort
4539
SortMapSlice(msValues)
4640
// Marshal
47-
s, err = goyaml.Marshal(msValues)
48-
if err != nil {
49-
panic(err)
50-
}
41+
s, _ = goyaml.Marshal(msValues)
5142
}
52-
// Gethash
43+
// Get hash
5344
return fmt.Sprintf("%x", sha1.Sum(s))
5445
}
5546

@@ -76,17 +67,15 @@ func cleanUpMapValue(v interface{}) interface{} {
7667
return cleanUpInterfaceArray(v)
7768
case map[interface{}]interface{}:
7869
return cleanUpInterfaceMap(v)
79-
case string:
80-
return v
8170
default:
82-
return fmt.Sprintf("%v", v)
71+
return v
8372
}
8473
}
8574

8675
func cleanUpInterfaceMap(in map[interface{}]interface{}) map[string]interface{} {
8776
result := make(map[string]interface{})
8877
for k, v := range in {
89-
result[fmt.Sprintf("%v", k)] = cleanUpMapValue(v)
78+
result[fmt.Sprintf("%T.%v", k, k)] = cleanUpMapValue(v)
9079
}
9180
return result
9281
}
@@ -101,14 +90,16 @@ func cleanUpInterfaceArray(in []interface{}) []interface{} {
10190

10291
func copyValues(in map[string]interface{}) map[string]interface{} {
10392
// Marshal
104-
coppiedValues, err := goyaml.Marshal(in)
105-
if err != nil {
106-
panic(err)
107-
}
93+
coppiedValues, _ := goyaml.Marshal(in)
10894
// Unmarshal
109-
newValues := make(map[string]interface{})
95+
newValues := make(map[interface{}]interface{})
11096
goyaml.Unmarshal(coppiedValues, newValues)
111-
return newValues
97+
formattedValues := make(map[string]interface{})
98+
// cleanUpInterfaceMap
99+
for i, value := range newValues {
100+
formattedValues[fmt.Sprintf("%T.%v", i, i)] = cleanUpMapValue(value)
101+
}
102+
return formattedValues
112103
}
113104

114105
// ReleaseRevision returns the revision of the given release.Release.

internal/util/util_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestValuesChecksum(t *testing.T) {
4444
"cool": "stuff",
4545
},
4646
},
47-
want: "7d487b668ca37fe68c42adfc06fa4d0e74443afd",
47+
want: "d76f7bd99c3dce0405da811625ed02624a0184d4",
4848
},
4949
}
5050
for _, tt := range tests {

0 commit comments

Comments
 (0)