🌱 Consolidate client option wrappers behind a shared internal backend - #3577
🌱 Consolidate client option wrappers behind a shared internal backend#3577yindia wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yindia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @yindia! |
|
Hi @yindia. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What does this do, and why do we need it?
Fixes #2888.
#2888 asks for one scalable pattern to wrap clients instead of adding a new wrapper for every option. Today
NewDryRunClient,WithFieldOwner, andWithFieldValidationeach ship their own near-identicalClientandSubResourceClientimplementation: embed a reader, re-implement every write method to push a single option into the per-call slice, forward the rest of the interface. Three copies of the same plumbing that all need updating whenever theClientinterface grows a verb.This PR moves all three onto one internal backend and deletes the duplicated wrapper types.
pkg/client/defaultoptions.goaddswithInjectedOptions(c Client, defaults, forced writeOptions) Client, backed byclientWithOptionsandsubResourceClientWithOptions.writeOptionsholds the option slices per write verb, including the subresource verbs.Options apply in the order
defaults -> per-call -> forced, so a per-call option overrides a default and a forced option wins over whatever the caller passed. That keeps each wrapper's existing behavior:WithFieldOwnerandWithFieldValidationregister their option as a default, so callers can still override it per call.NewDryRunClientregistersDryRunAllas a forced option, so it cannot be overridden.Each write method is implemented explicitly rather than promoted through embedding. If a new write verb is added to the
Clientinterface, this file stops compiling until the verb is handled, instead of silently passing calls through without the configured options.No public API or behavior changes.
fieldowner.go,fieldvalidation.go, anddryrun.gonow just callwithInjectedOptions. Newpkg/client/defaultoptions_test.gocovers the default/forced precedence and subresource propagation;go test ./pkg/client/...passes.