Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ func fromMapStringAny(u map[string]any, target runtime.Object) error {
return fmt.Errorf("failed to serialize: %w", err)
}

zero(target)
if err := json.Unmarshal(serialized, &target); err != nil {
return fmt.Errorf("failed to deserialize: %w", err)
}
Expand Down
22 changes: 7 additions & 15 deletions pkg/client/fake/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,22 +1409,19 @@ var _ = Describe("Fake client", func() {
})

It("should not change the status of typed objects that have a status subresource on update", func() {
obj := &corev1.Node{
obj := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "node",
},
Status: corev1.NodeStatus{
NodeInfo: corev1.NodeSystemInfo{MachineID: "machine-id"},
Name: "pod",
},
}
cl := NewClientBuilder().WithStatusSubresource(obj).WithObjects(obj).Build()

obj.Status.NodeInfo.MachineID = "updated-machine-id"
obj.Status.Phase = "Running"
Expect(cl.Update(context.Background(), obj)).To(Succeed())

Expect(cl.Get(context.Background(), client.ObjectKeyFromObject(obj), obj)).To(Succeed())

Expect(obj.Status).To(BeEquivalentTo(corev1.NodeStatus{NodeInfo: corev1.NodeSystemInfo{MachineID: "machine-id"}}))
Expect(obj.Status).To(BeEquivalentTo(corev1.PodStatus{}))
})

It("should return a conflict error when an incorrect RV is used on status update", func() {
Expand Down Expand Up @@ -1511,25 +1508,20 @@ var _ = Describe("Fake client", func() {
})

It("should not change the status of typed objects that have a status subresource on patch", func() {
obj := &corev1.Node{
obj := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "node",
},
Status: corev1.NodeStatus{
NodeInfo: corev1.NodeSystemInfo{
MachineID: "machine-id",
},
},
}
Expect(cl.Create(context.Background(), obj)).To(Succeed())
original := obj.DeepCopy()

obj.Status.NodeInfo.MachineID = "machine-id-from-patch"
obj.Status.Phase = "Running"
Expect(cl.Patch(context.Background(), obj, client.MergeFrom(original))).To(Succeed())

Expect(cl.Get(context.Background(), client.ObjectKeyFromObject(obj), obj)).To(Succeed())

Expect(obj.Status).To(BeEquivalentTo(corev1.NodeStatus{NodeInfo: corev1.NodeSystemInfo{MachineID: "machine-id"}}))
Expect(obj.Status).To(BeEquivalentTo(corev1.PodStatus{}))
})

It("should not change non-status field of typed objects that have a status subresource on status patch", func() {
Expand Down