Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected AbstractOperatorExtension(
this.infrastructureKubernetesClient =
infrastructureKubernetesClient != null
? infrastructureKubernetesClient
: new KubernetesClientBuilder().build();
: kubernetesClient != null ? kubernetesClient : new KubernetesClientBuilder().build();
Comment on lines 78 to +81
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.
this.kubernetesClient =
kubernetesClient != null ? kubernetesClient : this.infrastructureKubernetesClient;
this.infrastructure = infrastructure;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright Java Operator SDK Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.javaoperatorsdk.operator.junit;

import java.nio.file.Path;
import java.util.List;

import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.client.KubernetesClientBuilder;

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


@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

System.out.println(Path.of("src/test/crd/test.crd").toAbsolutePath());
final var crds =
LocallyRunOperatorExtension.getAdditionalCRDsFromFiles(
List.of("src/test/resources/crd/test.crd", "src/test/crd/test.crd"),
new KubernetesClientBuilder().build());
assertNotNull(crds);
assertEquals(2, crds.size());
assertEquals("src/test/crd/test.crd", crds.get("externals.crd.example"));
assertEquals("src/test/resources/crd/test.crd", crds.get("tests.crd.example"));
}

@Test
void overrideInfrastructureAndUserKubernetesClient() {
var infrastructureClient = new KubernetesClientBuilder().build();
var userKubernetesClient = new KubernetesClientBuilder().build();

LocallyRunOperatorExtension extension =
LocallyRunOperatorExtension.builder()
.withInfrastructureKubernetesClient(infrastructureClient)
.withKubernetesClient(userKubernetesClient)
.build();

assertEquals(infrastructureClient, extension.getInfrastructureKubernetesClient());
assertEquals(userKubernetesClient, extension.getKubernetesClient());
assertNotEquals(extension.getInfrastructureKubernetesClient(), extension.getKubernetesClient());
}

@Test
void overrideInfrastructureAndVerifyUserKubernetesClientIsTheSame() {
var infrastructureClient = new KubernetesClientBuilder().build();

LocallyRunOperatorExtension extension =
LocallyRunOperatorExtension.builder()
.withInfrastructureKubernetesClient(infrastructureClient)
.build();

assertEquals(infrastructureClient, extension.getInfrastructureKubernetesClient());
assertEquals(infrastructureClient, extension.getKubernetesClient());
assertEquals(extension.getInfrastructureKubernetesClient(), extension.getKubernetesClient());
}

@Test
void overrideKubernetesClientAndVerifyInfrastructureClientIsTheSame() {
var userKubernetesClient = new KubernetesClientBuilder().build();

LocallyRunOperatorExtension extension =
LocallyRunOperatorExtension.builder().withKubernetesClient(userKubernetesClient).build();

assertEquals(userKubernetesClient, extension.getKubernetesClient());
assertEquals(userKubernetesClient, extension.getInfrastructureKubernetesClient());
assertEquals(extension.getKubernetesClient(), extension.getInfrastructureKubernetesClient());
}
}