-
Notifications
You must be signed in to change notification settings - Fork 237
fix: Make AbstractOperatorExtension use the kubernetesClient if the infrastructureKubernetesClient is not set #3077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see: #3028
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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 onlykubernetesClientis provided, it creates a newinfrastructureKubernetesClientinstead of reusing the provided client.Consider applying the same ternary operator pattern: