Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix status subresource getting updated on Update when it is empty #2484

Merged
merged 1 commit into from Sep 9, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/client/fake/client.go
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
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