Skip to content

Commit 1cf5b88

Browse files
authored
Merge pull request #2485 from k8s-infra-cherrypick-robot/cherry-pick-2484-to-release-0.16
[release-0.16] 🐛 Fix status subresource getting updated on Update when it is empty
2 parents 580f203 + 319038d commit 1cf5b88

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

pkg/client/fake/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ func fromMapStringAny(u map[string]any, target runtime.Object) error {
995995
return fmt.Errorf("failed to serialize: %w", err)
996996
}
997997

998+
zero(target)
998999
if err := json.Unmarshal(serialized, &target); err != nil {
9991000
return fmt.Errorf("failed to deserialize: %w", err)
10001001
}

pkg/client/fake/client_test.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,22 +1409,19 @@ var _ = Describe("Fake client", func() {
14091409
})
14101410

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

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

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

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

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

15131510
It("should not change the status of typed objects that have a status subresource on patch", func() {
1514-
obj := &corev1.Node{
1511+
obj := &corev1.Pod{
15151512
ObjectMeta: metav1.ObjectMeta{
15161513
Name: "node",
15171514
},
1518-
Status: corev1.NodeStatus{
1519-
NodeInfo: corev1.NodeSystemInfo{
1520-
MachineID: "machine-id",
1521-
},
1522-
},
15231515
}
15241516
Expect(cl.Create(context.Background(), obj)).To(Succeed())
15251517
original := obj.DeepCopy()
15261518

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

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

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

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

0 commit comments

Comments
 (0)