diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index b6743a6ac6..db6dc5ec21 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -59,7 +59,6 @@ jobs: strategy: matrix: java: [ 11, 17 ] - kubernetes: [ 'v1.23.15', 'v1.24.9', 'v1.25.5' ] steps: - uses: actions/checkout@v3 - name: Set up Java and Maven @@ -68,13 +67,5 @@ jobs: distribution: temurin java-version: ${{ matrix.java }} cache: 'maven' - - name: Minikube Min Request Timeout Setting - uses: manusa/actions-setup-minikube@v2.7.2 - with: - minikube version: 'v1.28.0' - kubernetes version: ${{ matrix.kubernetes }} - driver: 'docker' - start args: '--extra-config=apiserver.min-request-timeout=3' - github token: ${{ secrets.GITHUB_TOKEN }} - name: Run Special Integration Tests run: ./mvnw ${MAVEN_ARGS} -B package -P minimal-watch-timeout-dependent-it --file pom.xml \ No newline at end of file diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index 88ee911692..1d0f8307e0 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -55,6 +55,12 @@ com.google.testing.compile compile-testing test + + + com.google.guava + guava + + io.fabric8 @@ -79,6 +85,11 @@ ${project.version} test + + io.javaoperatorsdk + jenvtest + test + diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java index 7bc96912b4..8fa0186bba 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -14,6 +14,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; +import io.javaoperatorsdk.jenvtest.junit.EnableKubeAPIServer; import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider; import io.javaoperatorsdk.operator.health.InformerHealthIndicator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; @@ -30,7 +31,8 @@ /** * The test relies on a special api server configuration: "min-request-timeout" to have a very low - * value, use: "minikube start --extra-config=apiserver.min-request-timeout=3" + * value (in case want to try with minikube use: "minikube start + * --extra-config=apiserver.min-request-timeout=3") * *

* This is important when tests are affected by permission changes, since the watch permissions are @@ -41,14 +43,16 @@ * The test ends with "ITS" (Special) since it needs to run separately from other ITs *

*/ +@EnableKubeAPIServer(apiServerFlags = {"--min-request-timeout", "3"}) class InformerRelatedBehaviorITS { public static final String TEST_RESOURCE_NAME = "test1"; - public static final String ADDITIONAL_NAMESPACE_NAME = "additionalns"; + public static final String ADDITIONAL_NAMESPACE_SUFFIX = "-additional"; KubernetesClient adminClient = new KubernetesClientBuilder().build(); InformerRelatedBehaviorTestReconciler reconciler; String actualNamespace; + String additionalNamespace; volatile boolean replacementStopHandlerCalled = false; @BeforeEach @@ -57,6 +61,7 @@ void beforeEach(TestInfo testInfo) { adminClient); testInfo.getTestMethod().ifPresent(method -> { actualNamespace = KubernetesResourceUtil.sanitizeName(method.getName()); + additionalNamespace = actualNamespace + ADDITIONAL_NAMESPACE_SUFFIX; adminClient.resource(namespace()).createOrReplace(); }); // cleans up binding before test, not all test cases use cluster role @@ -66,7 +71,6 @@ void beforeEach(TestInfo testInfo) { @AfterEach void cleanup() { adminClient.resource(testCustomResource()).delete(); - adminClient.resource(namespace()).delete(); } @Test @@ -110,24 +114,15 @@ void startsUpWhenNoPermissionToSecondaryResource() { @Test void startsUpIfNoPermissionToOneOfTwoNamespaces() { - var otherNamespace = - adminClient.resource(namespace(ADDITIONAL_NAMESPACE_NAME)).createOrReplace(); - try { - addRoleBindingsToTestNamespaces(); - var operator = startOperator(false, false, actualNamespace, ADDITIONAL_NAMESPACE_NAME); - assertInformerNotWatchingForAdditionalNamespace(operator); - - adminClient.resource(testCustomResource()).createOrReplace(); - waitForWatchReconnect(); - assertReconciled(); - - } finally { - adminClient.resource(otherNamespace).delete(); - await().untilAsserted(() -> { - var ns = adminClient.namespaces().resource(otherNamespace).fromServer().get(); - assertThat(ns).isNull(); - }); - } + adminClient.resource(namespace(additionalNamespace)).createOrReplace(); + + addRoleBindingsToTestNamespaces(); + var operator = startOperator(false, false, actualNamespace, additionalNamespace); + assertInformerNotWatchingForAdditionalNamespace(operator); + + adminClient.resource(testCustomResource()).createOrReplace(); + waitForWatchReconnect(); + assertReconciled(); } private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) { @@ -139,17 +134,17 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) InformerHealthIndicator controllerHealthIndicator = (InformerHealthIndicator) unhealthyEventSources .get(ControllerResourceEventSource.class.getSimpleName()) - .informerHealthIndicators().get(ADDITIONAL_NAMESPACE_NAME); + .informerHealthIndicators().get(additionalNamespace); assertThat(controllerHealthIndicator).isNotNull(); - assertThat(controllerHealthIndicator.getTargetNamespace()).isEqualTo(ADDITIONAL_NAMESPACE_NAME); + assertThat(controllerHealthIndicator.getTargetNamespace()).isEqualTo(additionalNamespace); assertThat(controllerHealthIndicator.isWatching()).isFalse(); InformerHealthIndicator configMapHealthIndicator = (InformerHealthIndicator) unhealthyEventSources .get(ConfigMapDependentResource.class.getSimpleName()) - .informerHealthIndicators().get(ADDITIONAL_NAMESPACE_NAME); + .informerHealthIndicators().get(additionalNamespace); assertThat(configMapHealthIndicator).isNotNull(); - assertThat(configMapHealthIndicator.getTargetNamespace()).isEqualTo(ADDITIONAL_NAMESPACE_NAME); + assertThat(configMapHealthIndicator.getTargetNamespace()).isEqualTo(additionalNamespace); assertThat(configMapHealthIndicator.isWatching()).isFalse(); } diff --git a/pom.xml b/pom.xml index 7fdb593dc4..6bccd6bf96 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ 1.0 1.8.0 4.10.0 + 0.4.0 @@ -193,6 +194,12 @@ mockwebserver ${okhttp.version} + + io.javaoperatorsdk + jenvtest + ${jenvtest.version} + test +