-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Draft: Test that an object is updatable after updating its status. #2486
Closed
berlin-ab
wants to merge
2
commits into
kubernetes-sigs:main
from
berlin-ab:object-should-be-updateable-after-status-update
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1476,6 +1476,84 @@ var _ = Describe("Fake client", func() { | |
objOriginal.Status.NodeInfo.MachineID = "machine-id-from-status-update" | ||
Expect(cmp.Diff(objOriginal, actual)).To(BeEmpty()) | ||
}) | ||
|
||
It("should be able to update an object after updating an object's status", func() { | ||
obj := &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "node", | ||
}, | ||
Spec: corev1.NodeSpec{ | ||
PodCIDR: "old-cidr", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
NodeInfo: corev1.NodeSystemInfo{ | ||
MachineID: "machine-id", | ||
}, | ||
}, | ||
} | ||
cl := NewClientBuilder().WithStatusSubresource(obj).WithObjects(obj).Build() | ||
expectedObj := obj.DeepCopy() | ||
|
||
obj.Status.NodeInfo.MachineID = "machine-id-from-status-update" | ||
Expect(cl.Status().Update(context.Background(), obj)).NotTo(HaveOccurred()) | ||
|
||
obj.Annotations = map[string]string{ | ||
"some-annotation-key": "some", | ||
} | ||
expectedObj.Annotations = map[string]string{ | ||
"some-annotation-key": "some", | ||
} | ||
Expect(cl.Update(context.Background(), obj)).NotTo(HaveOccurred()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test fails. The test below was double checking that the reverse order also works. |
||
|
||
actual := &corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: obj.Name}} | ||
Expect(cl.Get(context.Background(), client.ObjectKeyFromObject(actual), actual)).NotTo(HaveOccurred()) | ||
|
||
expectedObj.APIVersion = actual.APIVersion | ||
expectedObj.Kind = actual.Kind | ||
expectedObj.ResourceVersion = actual.ResourceVersion | ||
expectedObj.Status.NodeInfo.MachineID = "machine-id-from-status-update" | ||
Expect(cmp.Diff(expectedObj, actual)).To(BeEmpty()) | ||
}) | ||
|
||
It("should be able to update an object's status after updating an object", func() { | ||
obj := &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "node", | ||
}, | ||
Spec: corev1.NodeSpec{ | ||
PodCIDR: "old-cidr", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
NodeInfo: corev1.NodeSystemInfo{ | ||
MachineID: "machine-id", | ||
}, | ||
}, | ||
} | ||
cl := NewClientBuilder().WithStatusSubresource(obj).WithObjects(obj).Build() | ||
expectedObj := obj.DeepCopy() | ||
|
||
obj.Annotations = map[string]string{ | ||
"some-annotation-key": "some", | ||
} | ||
expectedObj.Annotations = map[string]string{ | ||
"some-annotation-key": "some", | ||
} | ||
Expect(cl.Update(context.Background(), obj)).NotTo(HaveOccurred()) | ||
|
||
obj.Spec.PodCIDR = "cidr-from-status-update" | ||
obj.Status.NodeInfo.MachineID = "machine-id-from-status-update" | ||
Expect(cl.Status().Update(context.Background(), obj)).NotTo(HaveOccurred()) | ||
|
||
actual := &corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: obj.Name}} | ||
Expect(cl.Get(context.Background(), client.ObjectKeyFromObject(actual), actual)).NotTo(HaveOccurred()) | ||
|
||
expectedObj.APIVersion = actual.APIVersion | ||
expectedObj.Kind = actual.Kind | ||
expectedObj.ResourceVersion = actual.ResourceVersion | ||
expectedObj.Status.NodeInfo.MachineID = "machine-id-from-status-update" | ||
Expect(cmp.Diff(expectedObj, actual)).To(BeEmpty()) | ||
}) | ||
|
||
It("Should only override status fields of typed objects that have a status subresource on status update", func() { | ||
obj := &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for a cleaner way to do this, so maybe you can think of one. I don't like the distance between when we make the deep copy and when we need to handle the repercussions of doing so.