Skip to content

Conversation

@xstefank
Copy link
Collaborator

@xstefank xstefank commented Dec 1, 2025

Should help in cases like #3070

Copilot AI review requested due to automatic review settings December 1, 2025 14:31
@openshift-ci openshift-ci bot requested review from csviri and metacosm December 1, 2025 14:31
Copy link
Collaborator

@csviri csviri left a comment

Choose a reason for hiding this comment

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

would be nice to somehow verify this in an automated way, maybe using it in a test?

Copilot finished reviewing on behalf of xstefank December 1, 2025 14:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a client initialization issue in AbstractOperatorExtension where providing only a kubernetesClient (without an infrastructureKubernetesClient) would unnecessarily create a new client instance instead of reusing the provided one. The fix ensures both client references use the same instance when only one is provided, improving resource efficiency and addressing the issue discussed in the linked GitHub discussion.

Key Changes

  • Modified the infrastructureKubernetesClient initialization to fall back to kubernetesClient before creating a new instance
  • This prevents unnecessary client creation when kubernetesClient is provided but infrastructureKubernetesClient is not

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines 78 to +81
this.infrastructureKubernetesClient =
infrastructureKubernetesClient != null
? infrastructureKubernetesClient
: new KubernetesClientBuilder().build();
: kubernetesClient != null ? kubernetesClient : new KubernetesClientBuilder().build();
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The fix applied here should also be applied to ClusterDeployedOperatorExtension.Builder.build() for consistency. That builder has duplicate client initialization logic (lines 180-185) with the same issue - if only kubernetesClient is provided, it creates a new infrastructureKubernetesClient instead of reusing the provided client.

Consider applying the same ternary operator pattern:

infrastructureKubernetesClient =
    infrastructureKubernetesClient != null
        ? infrastructureKubernetesClient
        : kubernetesClient != null ? kubernetesClient : new KubernetesClientBuilder().build();

Copilot uses AI. Check for mistakes.
…nfrastructureKubernetesClient is not set

Signed-off-by: xstefank <xstefank122@gmail.com>
@xstefank xstefank force-pushed the infra-client-same-as-main-if-not-set branch from 3c07054 to 9dba403 Compare December 1, 2025 14:48

@Test
void getAdditionalCRDsFromFiles() {
System.out.println(Path.of("").toAbsolutePath());
Copy link
Collaborator

Choose a reason for hiding this comment

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

pls use a logger instead


import static org.junit.jupiter.api.Assertions.*;

class LocallyRunOperatorExtensionTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I remember correctly this was on purpose an integration tests since we use the client there that does some initial calls on an API server

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, it passes as unit test too so I saw no reason why to keep as IT

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, but it slows down the local build, especially if there is no local k8s server running

Copy link
Collaborator

Choose a reason for hiding this comment

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

see: #3028

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, but this doesn't run long and also it seems that failsafe is not configured at all, so I think this as IT doesn't run at all

Copy link
Collaborator

@csviri csviri left a comment

Choose a reason for hiding this comment

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

OK, we can try it this way

@xstefank xstefank merged commit 45ee569 into operator-framework:main Dec 2, 2025
25 checks passed
@xstefank xstefank deleted the infra-client-same-as-main-if-not-set branch December 2, 2025 06:37
metacosm pushed a commit that referenced this pull request Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants