[shell-operator] fix: patch CRD conversion without overwriting fields - #930
Merged
Merged
Conversation
Signed-off-by: Ruslan Gorbunov <ruslan.gorbunov@flant.com>
Signed-off-by: Ruslan Gorbunov <ruslan.gorbunov@flant.com>
Merged
4 tasks
fuldaxxx
marked this pull request as ready for review
September 5, 2026 17:09
ldmonster
approved these changes
Sep 7, 2026
4 tasks
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.
Description
Replace the read-modify-write update of the CRD in the conversion webhook manager with a JSON Patch that touches only
spec.conversion.CrdClientConfig.Update()used toGet()the wholeCustomResourceDefinition, mutatespec.conversionin memory andUpdate()the entire object back. It is nowCrdClientConfig.PatchConversion(), which marshals the desiredCustomResourceConversion(webhook strategy, service reference, CA bundle, supported review versions) and sends a single[{"op":"add","path":"/spec/conversion","value":{…}}]patch.Other changes that come with it:
Get, so a CRD that does not exist yet when a hook registers its conversion binding is still picked up once it appears.select-based onctx.Done()instead of a blockingtime.Sleep(), so the loop stops on context cancellation instead of holding startup for up to 15 minutes.update CRD→patch CRD conversion).Why do we need it, and what problem does it solve?
Sending the full CRD back on
Update()makes shell-operator a last-write-wins writer for the entire object. Anything written to that CRD between ourGet()and ourUpdate()— by Helm, by another controller, by an operator that owns the same CRD, or by a parallel shell-operator instance — is silently reverted to the snapshot we read, and the change is not limited tospec.conversion: schema edits, versions, labels and annotations all travel in that request. On a busy cluster this shows up as CRD fields mysteriously rolling back right after the operator starts, and asthe object has been modifiedconflicts on startup.A JSON Patch scoped to
/spec/conversionstates the actual intent — "point this CRD's conversion at my webhook, leave everything else alone" — so the operator can no longer clobber fields it does not own, and concurrent writers to other parts of the CRD stop conflicting with it.The second problem was retry placement: only the
Getwas retried, so a CRD that appeared during startup was fetched successfully but the very first failing write abortedWebhookManager.Start(). Retrying the write instead covers the real race (the CRD being created around the same time as the operator), and making the waitcontext-aware means a shutdown during that window no longer blocks for minutes.