Skip to content

Commit

Permalink
Handle nil values in maps when normalizing Helm release values
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Apr 7, 2023
1 parent c9c8541 commit d46c537
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
30 changes: 20 additions & 10 deletions pkg/helm/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func getPathAndKey(path []string) ([]string, string) {
}

func normalize(value any) (any, error) {
if value == nil {
return nil, nil
}
t := reflect.TypeOf(value)
if t.Kind() == reflect.Pointer {
t = t.Elem()
Expand All @@ -158,24 +161,31 @@ func normalize(value any) (any, error) {

func normalizeMap(values map[string]any) (map[string]any, error) {
normalized := make(map[string]any)
if values == nil {
return normalized, nil
}
for key, value := range values {
v, err := normalize(value)
if err != nil {
return nil, err
if value != nil {
v, err := normalize(value)
if err != nil {
return nil, err
}
normalized[key] = v
}
normalized[key] = v
}
return normalized, nil
}

func normalizeSlice(values []any) ([]any, error) {
normalized := make([]any, len(values))
for i, value := range values {
v, err := normalize(value)
if err != nil {
return nil, err
normalized := make([]any, 0, len(values))
for _, value := range values {
if value != nil {
v, err := normalize(value)
if err != nil {
return nil, err
}
normalized = append(normalized, v)
}
normalized[i] = v
}
return normalized, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/helm/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestReleaseValues(t *testing.T) {
"a": "b",
"b": map[string]any{
"c": 1,
"d": nil,
},
}
defaultFiles := []string{
Expand Down

0 comments on commit d46c537

Please sign in to comment.