Skip to content

Commit e632c07

Browse files
authored
Merge pull request kubernetes-sigs#10525 from sbueringer/pr-improve-patch-test
🌱 Improve SSA patch test
2 parents 9a94459 + 499869e commit e632c07

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

internal/util/ssa/patch_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,6 @@ func TestPatch(t *testing.T) {
127127
g.Expect(Patch(ctx, env.GetClient(), fieldManager, createObject)).To(Succeed())
128128
// Verify that gvk is still set
129129
g.Expect(createObject.GroupVersionKind()).To(Equal(initialObject.GroupVersionKind()))
130-
// Note: We have to patch the status here to explicitly set these two status fields.
131-
// If we don't do it the Machine defaulting webhook will try to set the two fields to false.
132-
// For an unknown reason this will happen with the 2nd update call (3.) below and not before.
133-
// This means that this call would unexpectedly not cache the object because the resourceVersion
134-
// is changed because the fields are set.
135-
// It's unclear why those status fields are not already set during create (1.) or the first update (2.)
136-
// (the webhook is returning patches for the two fields in those requests as well).
137-
// To further investigate this behavior it would be necessary to debug the kube-apiserver.
138-
// Fortunately, in reality this is not an issue as the fields will be set sooner or later and then
139-
// the requests are cached.
140-
createObjectWithStatus := createObject.DeepCopy()
141-
createObjectWithStatus.Status.BootstrapReady = false
142-
createObjectWithStatus.Status.InfrastructureReady = false
143-
g.Expect(env.Status().Patch(ctx, createObjectWithStatus, client.MergeFrom(createObject))).To(Succeed())
144130

145131
// 2. Update the object and verify that the request was not cached as the object was changed.
146132
// Get the original object.
@@ -161,6 +147,14 @@ func TestPatch(t *testing.T) {
161147
// Verify that request was not cached (as it changed the object)
162148
g.Expect(ssaCache.Has(requestIdentifier)).To(BeFalse())
163149

150+
// Wait for 1 second. We are also trying to verify in this test that the resourceVersion of the Machine
151+
// is not increased. Under some circumstances this would only happen if the timestamp in managedFields would
152+
// be increased by 1 second.
153+
// Please see the following issues for more context:
154+
// * https://github.com/kubernetes-sigs/cluster-api/issues/10533
155+
// * https://github.com/kubernetes/kubernetes/issues/124605
156+
time.Sleep(1 * time.Second)
157+
164158
// 3. Repeat the same update and verify that the request was cached as the object was not changed.
165159
// Get the original object.
166160
originalObject = initialObject.DeepCopy()

0 commit comments

Comments
 (0)