Skip to content

Commit ed06e7e

Browse files
committed
🐛 Fakeclient: Do not consider an apply patch to be a strategic merge patch
The fakeclient currently considers an apply patch to be a strategic merge patch. This is completely wrong, those are different things and apply patches are not supported in the fakeclientl, because in order to support them it would need the entire SSA logic which isn't implemented in upstream yet.
1 parent 7032a3c commit ed06e7e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pkg/client/fake/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ func dryPatch(action testing.PatchActionImpl, tracker testing.ObjectTracker) (ru
947947
if err := json.Unmarshal(modified, obj); err != nil {
948948
return nil, err
949949
}
950-
case types.StrategicMergePatchType, types.ApplyPatchType:
950+
case types.StrategicMergePatchType:
951951
mergedByte, err := strategicpatch.StrategicMergePatch(old, action.GetPatch(), obj)
952952
if err != nil {
953953
return nil, err
@@ -956,7 +956,7 @@ func dryPatch(action testing.PatchActionImpl, tracker testing.ObjectTracker) (ru
956956
return nil, err
957957
}
958958
default:
959-
return nil, fmt.Errorf("PatchType is not supported")
959+
return nil, fmt.Errorf("%s PatchType is not supported", action.GetPatchType())
960960
}
961961
return obj, nil
962962
}

pkg/client/fake/client_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,26 @@ var _ = Describe("Fake client", func() {
359359
Expect(list.Items).To(ConsistOf(*dep2))
360360
})
361361

362+
It("should reject apply patches, they are not supported in the fake client", func() {
363+
By("Creating a new configmap")
364+
cm := &corev1.ConfigMap{
365+
TypeMeta: metav1.TypeMeta{
366+
APIVersion: "v1",
367+
Kind: "ConfigMap",
368+
},
369+
ObjectMeta: metav1.ObjectMeta{
370+
Name: "new-test-cm",
371+
Namespace: "ns2",
372+
},
373+
}
374+
err := cl.Create(context.Background(), cm)
375+
Expect(err).ToNot(HaveOccurred())
376+
377+
cm.Data = map[string]string{"foo": "bar"}
378+
err = cl.Patch(context.Background(), cm, client.Apply, client.ForceOwnership)
379+
Expect(err).To(MatchError("application/apply-patch+yaml PatchType is not supported"))
380+
})
381+
362382
It("should be able to Create", func() {
363383
By("Creating a new configmap")
364384
newcm := &corev1.ConfigMap{

0 commit comments

Comments
 (0)