Skip to content

Commit 1596e84

Browse files
pepovbaluchicken
authored andcommitted
Double check whether the patch actually makes a difference.
1 parent 14b441f commit 1596e84

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

integration_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ func TestIntegration(t *testing.T) {
4949
Name: "test-container", Image: "test-image",
5050
},
5151
},
52+
Volumes: []v1.Volume{
53+
{
54+
Name: "empty",
55+
VolumeSource: v1.VolumeSource{
56+
EmptyDir: &v1.EmptyDirVolumeSource{},
57+
},
58+
},
59+
},
5260
},
5361
}),
5462
NewTestDiff("pod does not match when a slice item gets removed",

patch/patch.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ func (p *PatchMaker) Calculate(currentObject, modifiedObject runtime.Object) (*P
7070
if err != nil {
7171
return nil, emperror.Wrap(err, "Failed to generate strategic merge patch")
7272
}
73+
// $setElementOrder can make it hard to decide whether there is an actual diff or not.
74+
// In cases like that trying to apply the patch locally on current will make it clear.
75+
if string(patch) != "{}" {
76+
patchCurrent, err := strategicpatch.StrategicMergePatch(current, patch, modifiedObject)
77+
if err != nil {
78+
return nil, emperror.Wrap(err, "Failed to apply patch again to check for an actual diff")
79+
}
80+
patch, err = strategicpatch.CreateTwoWayMergePatch(current, patchCurrent, modifiedObject)
81+
if err != nil {
82+
return nil, emperror.Wrap(err, "Failed to create patch again to check for an actual diff")
83+
}
84+
}
7385
case *unstructured.Unstructured:
7486
patch, err = jsonmergepatch.CreateThreeWayJSONMergePatch(original, modified, current)
7587
if err != nil {

0 commit comments

Comments
 (0)