Skip to content

Commit 43929d1

Browse files
committed
use sigs.k8s.io/json to unmarshal in fakeclient
Signed-off-by: Troy Connor <[email protected]>
1 parent b6c5897 commit 43929d1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pkg/client/fake/client.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import (
6666
"k8s.io/client-go/kubernetes/scheme"
6767
"k8s.io/client-go/testing"
6868
"k8s.io/utils/ptr"
69+
kjson "sigs.k8s.io/json"
6970

7071
"sigs.k8s.io/controller-runtime/pkg/client"
7172
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
@@ -377,7 +378,7 @@ func convertFromUnstructuredIfNecessary(s *runtime.Scheme, o runtime.Object) (ru
377378
if err != nil {
378379
return nil, fmt.Errorf("failed to serialize %T: %w", unstructuredSerialized, err)
379380
}
380-
if err := json.Unmarshal(unstructuredSerialized, typed); err != nil {
381+
if err := kjson.UnmarshalCaseSensitivePreserveInts(unstructuredSerialized, typed); err != nil {
381382
return nil, fmt.Errorf("failed to unmarshal the content of %T into %T: %w", u, typed, err)
382383
}
383384

@@ -556,7 +557,7 @@ func (c *fakeClient) Get(ctx context.Context, key client.ObjectKey, obj client.O
556557
return err
557558
}
558559
zero(obj)
559-
return json.Unmarshal(j, obj)
560+
return kjson.UnmarshalCaseSensitivePreserveInts(j, obj)
560561
}
561562

562563
func (c *fakeClient) Watch(ctx context.Context, list client.ObjectList, opts ...client.ListOption) (watch.Interface, error) {
@@ -620,7 +621,7 @@ func (c *fakeClient) List(ctx context.Context, obj client.ObjectList, opts ...cl
620621
}
621622
zero(obj)
622623
objCopy := obj.DeepCopyObject().(client.ObjectList)
623-
if err := json.Unmarshal(j, objCopy); err != nil {
624+
if err := kjson.UnmarshalCaseSensitivePreserveInts(j, objCopy); err != nil {
624625
return err
625626
}
626627

@@ -995,7 +996,7 @@ func (c *fakeClient) patch(obj client.Object, patch client.Patch, opts ...client
995996
return err
996997
}
997998
zero(obj)
998-
return json.Unmarshal(j, obj)
999+
return kjson.UnmarshalCaseSensitivePreserveInts(j, obj)
9991000
}
10001001

10011002
// Applying a patch results in a deletionTimestamp that is truncated to the nearest second.
@@ -1047,7 +1048,7 @@ func dryPatch(action testing.PatchActionImpl, tracker testing.ObjectTracker) (ru
10471048
return nil, err
10481049
}
10491050

1050-
if err = json.Unmarshal(modified, obj); err != nil {
1051+
if err = kjson.UnmarshalCaseSensitivePreserveInts(modified, obj); err != nil {
10511052
return nil, err
10521053
}
10531054
case types.MergePatchType:
@@ -1056,15 +1057,15 @@ func dryPatch(action testing.PatchActionImpl, tracker testing.ObjectTracker) (ru
10561057
return nil, err
10571058
}
10581059

1059-
if err := json.Unmarshal(modified, obj); err != nil {
1060+
if err := kjson.UnmarshalCaseSensitivePreserveInts(modified, obj); err != nil {
10601061
return nil, err
10611062
}
10621063
case types.StrategicMergePatchType:
10631064
mergedByte, err := strategicpatch.StrategicMergePatch(old, action.GetPatch(), obj)
10641065
if err != nil {
10651066
return nil, err
10661067
}
1067-
if err = json.Unmarshal(mergedByte, obj); err != nil {
1068+
if err = kjson.UnmarshalCaseSensitivePreserveInts(mergedByte, obj); err != nil {
10681069
return nil, err
10691070
}
10701071
case types.ApplyPatchType:
@@ -1121,7 +1122,7 @@ func toMapStringAny(obj runtime.Object) (map[string]any, error) {
11211122
}
11221123

11231124
u := map[string]any{}
1124-
return u, json.Unmarshal(serialized, &u)
1125+
return u, kjson.UnmarshalCaseSensitivePreserveInts(serialized, &u)
11251126
}
11261127

11271128
func fromMapStringAny(u map[string]any, target runtime.Object) error {
@@ -1136,7 +1137,7 @@ func fromMapStringAny(u map[string]any, target runtime.Object) error {
11361137
}
11371138

11381139
zero(target)
1139-
if err := json.Unmarshal(serialized, &target); err != nil {
1140+
if err := kjson.UnmarshalCaseSensitivePreserveInts(serialized, &target); err != nil {
11401141
return fmt.Errorf("failed to deserialize: %w", err)
11411142
}
11421143

0 commit comments

Comments
 (0)