Skip to content

Commit c036d3f

Browse files
authored
fix: sort fields to correctly calculate diff in server-side apply (#456)
Signed-off-by: Leonardo Luz Almeida <[email protected]> Signed-off-by: Leonardo Luz Almeida <[email protected]>
1 parent ce2fb70 commit c036d3f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/diff/diff.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,19 @@ func patchDefaultValues(objBytes []byte, obj runtime.Object) ([]byte, error) {
386386
return nil, fmt.Errorf("error applying patch for default values: %w", err)
387387
}
388388

389+
// 3) Unmarshall into a map[string]interface{}, then back into byte[], to
390+
// ensure the fields are sorted in a consistent order (we do the same below,
391+
// so that they can be lexicographically compared with one another).
392+
var result map[string]interface{}
393+
err = json.Unmarshal([]byte(patchedBytes), &result)
394+
if err != nil {
395+
return nil, fmt.Errorf("error unmarshaling patched bytes: %w", err)
396+
}
397+
patchedBytes, err = json.Marshal(result)
398+
if err != nil {
399+
return nil, fmt.Errorf("error marshaling patched bytes: %w", err)
400+
}
401+
389402
return patchedBytes, nil
390403
}
391404

0 commit comments

Comments
 (0)