Skip to content

Commit

Permalink
Improve cognitive complexity of diff.NormalizeSecret
Browse files Browse the repository at this point in the history
  • Loading branch information
itmustbejj committed Nov 22, 2023
1 parent 8f716eb commit a43d2bc
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,16 +697,7 @@ func NormalizeSecret(un *unstructured.Unstructured) error {
return nil
}
if stringData, found, err := unstructured.NestedMap(un.Object, "stringData"); found && err == nil {
for k, v := range stringData {
switch v := v.(type) {
case int64:
stringData[k] = toString(v)
}
}
err := unstructured.SetNestedField(un.Object, stringData, "stringData")
if err != nil {
return fmt.Errorf("unstructured.SetNestedField error: %s", err)
}
stringifyNestedIntKeys(un, stringData)
}
var secret corev1.Secret
err := runtime.DefaultUnstructuredConverter.FromUnstructured(un.Object, &secret)
Expand Down Expand Up @@ -965,3 +956,18 @@ func remarshal(obj *unstructured.Unstructured, o options) *unstructured.Unstruct
unstrBody = jsonutil.RemoveMapFields(obj.Object, unstrBody)
return &unstructured.Unstructured{Object: unstrBody}
}

func stringifyNestedIntKeys(un *unstructured.Unstructured, stringData map[string]interface{}) error {
for k, v := range stringData {
switch v := v.(type) {
case int64:
stringData[k] = toString(v)
}
}
err := unstructured.SetNestedField(un.Object, stringData, "stringData")
if err != nil {
return fmt.Errorf("unstructured.SetNestedField error: %s", err)
} else {
return nil
}
}

0 comments on commit a43d2bc

Please sign in to comment.