fix: invoke ConfigurationServiceOverrider consumer only once in Operator constructor#3353
Open
Dennis-Mircea wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors Operator#initConfigurationService to compose the provided KubernetesClient into the configuration overrider only when a client is explicitly supplied, simplifying initialization.
Changes:
- Augments the
overriderto bind a providedKubernetesClient(when non-null). - Removes the previous two-step creation of a
ConfigurationServiceused only to obtain a client instance. - Simplifies the control flow around client binding.
8ec8b10 to
1ff1043
Compare
Contributor
Author
|
Please re-run the workflow. It was previously failing the Spotless check because I committed the GitHub Copilot suggestion as-is, assuming it was already formatted correctly. |
csviri
approved these changes
May 15, 2026
Collaborator
csviri
left a comment
There was a problem hiding this comment.
LGTM!
thank you @Dennis-Mircea !
…tor constructor Signed-off-by: Dennis-Mircea Ciupitu <[email protected]>
1ff1043 to
b3b5fd2
Compare
Collaborator
|
@metacosm please take a look. thx! |
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.
Summary
Operator.initConfigurationServiceinvokes the caller-suppliedConsumer<ConfigurationServiceOverrider>twice when theOperator(Consumer<ConfigurationServiceOverrider>)constructor is used. Any side-effecting code inside that consumer (e.g. logging) is therefore emitted twice on startup.Observed in downstream operators such as Apache Flink Kubernetes Operator, which configures the operator via
new Operator(this::overrideOperatorConfigs)and ends up logging each startup line twice:Root cause
Today's
initConfigurationServicedoes a two-pass build whenclient == null:Each
newOverriddenConfigurationService(overrider)call invokes the user'soverrideronce, so it runs twice in theclient == nullpath. TheOperator(KubernetesClient)path is unaffected and it skips the first pass.The second pass exists to "pin" the resolved
KubernetesClientback onto the configuration service viawithKubernetesClient(...). That pinning is redundant:AbstractConfigurationService#getKubernetesClient()already memoizes the client lazily on first read, so any consumer asking the service for its client gets the same instance whether it was set explicitly or constructed lazily.Fix
Collapse to a single pass:
KubernetesClient, the overrider is augmented to pin it (same behavior as before).AbstractConfigurationService.java:177-// lazy init to avoid needing initializing a client when not needed).Compatibility
protectedvisibility for subclass overrides (OperatorIT.OperatorExtensionstill overrides it; verified).KubernetesClientis passed, the client is constructed lazily on firstgetKubernetesClient()call instead of eagerly duringinitConfigurationService. This matches the already-documented intent of the lazy initialization inAbstractConfigurationService.Test plan
./mvnw -pl operator-framework-core -am compile- succeeds, no new warnings../mvnw -pl operator-framework-core -am spotless:check- passes../mvnw -pl operator-framework-core -am test -Dtest='ConfigurationServiceOverriderTest,LeaderElectionManagerTest,ControllerTest,ReconciliationDispatcherTest,EventProcessorTest'- 77/77 pass.