Fix WithOptimisticLock on object creation#118
Merged
Conversation
47af5b2 to
fe1c22d
Compare
WithOptimisticLock on object creation
df602b3 to
6d47c24
Compare
6d47c24 to
a4f6ad3
Compare
harveyxia
reviewed
Jun 4, 2026
harveyxia
left a comment
Collaborator
There was a problem hiding this comment.
Approach LGTM, a few comments
| } | ||
|
|
||
| // apply options to desired after confirming the object exists (or on the create path above). | ||
| if err := applyOpts(ctx, desired, requestOpts, opts); err != nil { |
Collaborator
There was a problem hiding this comment.
Can this, L132, and L246 apply only the object options so it's clear when the options need to be applied in the logical flow, and we don't redundantly apply request options?
Comment on lines
121
to
127
| func requestOption(fn func(*RequestOptions) error) ApplyOption { | ||
| return ApplyOption{configureRequest: fn} | ||
| } | ||
|
|
||
| func objectOption(fn func(context.Context, client.Object, *RequestOptions) error) ApplyOption { | ||
| return ApplyOption{configureObject: fn} | ||
| } |
Collaborator
There was a problem hiding this comment.
Move these to the top of the file, add a concise but descriptive docstring explaining the contract
Co-authored-by: Harvey Xia <harvey.xia@reddit.com>
harveyxia
approved these changes
Jun 4, 2026
Co-authored-by: Harvey Xia <harvey.xia@reddit.com>
Co-authored-by: Harvey Xia <harvey.xia@reddit.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
💸 TL;DR
There was a regression in #113 for SDK users of the
WithOptimisticLock()option on object creation. This PR fixes the regression.📜 Details
The problem:
WithOptimisticLock()is only valid for PUT requests, it doesn't make sense for server side apply. In #113 the logic was changed:v0.13.13 flow (correct):
v0.13.14 flow (broken):
This PR restores the v0.13.13 flow for the Get + Create codepath but also keeps the early options apply for the SSA codepath.
🧪 Testing Steps / Validation
Validated against failing internal envtests as well as the new test coverage added in this PR.
✅ Checks