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

Retry on conflict during CRD dry-run updates in XRD validation webhook #5868

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

ulucinar
Copy link
Contributor

@ulucinar ulucinar commented Aug 6, 2024

Description of your changes

The XRD validation webhook's ValidateUpdate does not currently retry on HTTP 409 errors. We've observed this in e2e tests, causing sporadic failures. This PR proposes to introduce a retry mechanism for the CRD dry-run updates on conflicts.

I have:

  • Read and followed Crossplane's contribution process.
  • Run earthly +reviewable to ensure this PR is ready for review.
    - [ ] Added or updated unit tests.
    - [ ] Added or updated e2e tests.
    - [ ] Linked a PR or a docs tracking issue to document this change.
    - [ ] Added backport release-x.y labels to auto-backport this PR.

Need help with this checklist? See the cheat sheet.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
@ulucinar ulucinar requested review from phisco and a team as code owners August 6, 2024 10:10
@ulucinar ulucinar requested a review from negz August 6, 2024 10:10
Comment on lines +156 to +158
if kerrors.IsNotFound(err) {
return v.client.Create(ctx, crd, client.DryRunAll)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be outside of the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, correct. Keeping it in the retry function is more concise though, as in the retry function we still need to try to get the CRD to retry an update.

got := crd.DeepCopy()
err := v.client.Get(ctx, client.ObjectKey{Name: crd.Name}, got)
if err == nil {
got.Spec = crd.Spec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preexisting: doesn't this mean that Update below can mutate crd? The json unmarshaller under the hood might reuse referenced data structures.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics of this function are fishy. crd might get some changes on update, but not all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of scope of the PR, just saying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the deep copy is preserving the original object. We pass a pointer to the deep copied object in the Update call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object got is fresh, but crd.Spec is not. The DeepCopy does not help for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC that's the point, I was getting some error due to something else being updated, so I only switched in the part I care validating, the spec. Happy to drop it if that's not needed.

@jbw976 jbw976 added this to the v1.17 milestone Aug 6, 2024
@phisco phisco modified the milestones: v1.17, v1.18 Aug 29, 2024
@phisco phisco merged commit 1efa54c into crossplane:main Sep 11, 2024
16 of 17 checks passed
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants