From dd6e73ec7ce1dd32dfb3778d1c07f238af7337de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Muzik=C3=A1=C5=99?= Date: Tue, 4 Apr 2023 13:04:15 +0200 Subject: [PATCH] Upgrade Operator SDK to 6.0.0.CR1 --- Quarkus3 branch sync no. 14 (24.4.2023) Resolved conflicts: keycloak/operator/pom.xml - Modified --- operator/pom.xml | 13 ++++-- .../kubernetes/client/HttpClientFactory.java | 42 +++++++++++++++++++ .../controllers/KeycloakController.java | 2 +- .../KeycloakRealmImportController.java | 2 +- .../realmimport/KeycloakRealmImportSpec.java | 2 +- ....kubernetes.client.http.HttpClient$Factory | 18 ++++++++ .../integration/BaseOperatorTest.java | 17 +++++--- .../integration/KeycloakDeploymentTest.java | 2 +- .../integration/KeycloakIngressTest.java | 4 +- .../integration/KeycloakServicesTest.java | 4 +- .../operator/testsuite/utils/K8sUtils.java | 5 ++- 11 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 operator/src/main/java/org/keycloak/kubernetes/client/HttpClientFactory.java create mode 100644 operator/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory diff --git a/operator/pom.xml b/operator/pom.xml index 77fa643d98..52d4d97bcf 100644 --- a/operator/pom.xml +++ b/operator/pom.xml @@ -21,9 +21,8 @@ See https://github.com/quarkusio/quarkus/blob//bom/application/pom.xml for reference --> - 4.7.7.Final + 6.5.1 1.5.4.Final-format-001 - 5.12.4 3.8.1 true @@ -32,8 +31,8 @@ 11 UTF-8 UTF-8 - 4.0.7 - 2.13.7.Final + 6.0.0.CR1 + 3.0.0.CR1 keycloak @@ -96,6 +95,12 @@ io.quarkus quarkus-container-image-docker + + + io.fabric8 + kubernetes-httpclient-okhttp + ${kubernetes-client.version} + diff --git a/operator/src/main/java/org/keycloak/kubernetes/client/HttpClientFactory.java b/operator/src/main/java/org/keycloak/kubernetes/client/HttpClientFactory.java new file mode 100644 index 0000000000..52abcc7b2a --- /dev/null +++ b/operator/src/main/java/org/keycloak/kubernetes/client/HttpClientFactory.java @@ -0,0 +1,42 @@ +/* + * Copyright 2023 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * 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 org.keycloak.kubernetes.client; + +import io.fabric8.kubernetes.client.okhttp.OkHttpClientFactory; + +/** + * FIXME: This Factory is meant to force Fabric8 to use OKHttp Client. We should not normally do that as it is not aligned with Quarkus. + * Remove once the following are resolved: + * https://github.com/fabric8io/kubernetes-client/issues/5036 + * https://github.com/fabric8io/kubernetes-client/issues/5033 (only needed by tests) + * + * Tracked by: https://github.com/keycloak/keycloak/issues/19573 + * + * @author Vaclav Muzikar + */ +public class HttpClientFactory extends OkHttpClientFactory { + @Override + public boolean isDefault() { + return false; + } + + @Override + public int priority() { + return 10000; + } +} diff --git a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakController.java b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakController.java index 057c60d650..c11920ea84 100644 --- a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakController.java +++ b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakController.java @@ -40,7 +40,7 @@ import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatus; import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatusBuilder; import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatusCondition; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.Map; import java.util.concurrent.TimeUnit; diff --git a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportController.java b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportController.java index 2bb59a1f42..cd49153d15 100644 --- a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportController.java +++ b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportController.java @@ -38,7 +38,7 @@ import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImportStatus import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImportStatusBuilder; import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImportStatusCondition; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.Map; import java.util.concurrent.TimeUnit; diff --git a/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/realmimport/KeycloakRealmImportSpec.java b/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/realmimport/KeycloakRealmImportSpec.java index 982cee7321..11a2a1846d 100644 --- a/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/realmimport/KeycloakRealmImportSpec.java +++ b/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/realmimport/KeycloakRealmImportSpec.java @@ -19,7 +19,7 @@ package org.keycloak.operator.crds.v2alpha1.realmimport; import com.fasterxml.jackson.annotation.JsonPropertyDescription; import org.keycloak.representations.idm.RealmRepresentation; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; public class KeycloakRealmImportSpec { diff --git a/operator/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory b/operator/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory new file mode 100644 index 0000000000..c38d28eb0a --- /dev/null +++ b/operator/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory @@ -0,0 +1,18 @@ +# +# Copyright 2023 Red Hat, Inc. and/or its affiliates +# and other contributors as indicated by the @author tags. +# +# 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. +# + +org.keycloak.kubernetes.client.HttpClientFactory \ No newline at end of file diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java index 70785add74..be3fc7bf85 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java @@ -25,10 +25,13 @@ import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.DefaultKubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.Operator; +import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.quarkiverse.operatorsdk.runtime.OperatorProducer; import io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService; import io.quarkus.logging.Log; +import jakarta.enterprise.inject.Instance; +import jakarta.enterprise.inject.spi.CDI; +import jakarta.enterprise.util.TypeLiteral; import org.awaitility.Awaitility; import org.eclipse.microprofile.config.ConfigProvider; import org.junit.jupiter.api.AfterAll; @@ -39,9 +42,6 @@ import org.junit.jupiter.api.TestInfo; import org.keycloak.operator.Constants; import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak; -import javax.enterprise.inject.Instance; -import javax.enterprise.inject.spi.CDI; -import javax.enterprise.util.TypeLiteral; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -147,12 +147,13 @@ public abstract class BaseOperatorTest { for (Reconciler reconciler : reconcilers) { Log.info("Register and apply : " + reconciler.getClass().getName()); - OperatorProducer.applyCRDAndRegister(operator, reconciler, configuration); + operator.register(reconciler); } } private static void createOperator() { configuration.getClientConfiguration().setNamespace(namespace); + ConfigurationServiceProvider.reset(); operator = new Operator(k8sclient, configuration); } @@ -254,7 +255,11 @@ public abstract class BaseOperatorTest { } Log.info("Deleting namespace : " + namespace); - assertThat(k8sclient.namespaces().withName(namespace).delete()).isTrue(); + assertThat(k8sclient.namespaces().withName(namespace).delete()).isNotNull(); k8sclient.close(); } + + public static String getCurrentNamespace() { + return namespace; + } } diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java index 28aa9c4182..b9031c6b22 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java @@ -193,7 +193,7 @@ public class KeycloakDeploymentTest extends BaseOperatorTest { deployKeycloak(k8sclient, kc, true); Log.info("Trying to delete deployment"); - assertThat(k8sclient.apps().statefulSets().withName(deploymentName).delete()).isTrue(); + assertThat(k8sclient.apps().statefulSets().withName(deploymentName).delete()).isNotNull(); Awaitility.await() .untilAsserted(() -> assertThat(k8sclient.apps().statefulSets().withName(deploymentName).get()).isNotNull()); diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakIngressTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakIngressTest.java index 6915cd7f8b..df6d186638 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakIngressTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakIngressTest.java @@ -157,7 +157,7 @@ public class KeycloakIngressTest extends BaseOperatorTest { .withName(ingress.getName()); Log.info("Trying to delete the ingress"); - assertThat(ingressSelector.delete()).isTrue(); + assertThat(ingressSelector.delete()).isNotNull(); Awaitility.await() .untilAsserted(() -> assertThat(ingressSelector.get()).isNotNull()); @@ -234,7 +234,7 @@ public class KeycloakIngressTest extends BaseOperatorTest { } finally { Log.info("Destroying the Custom Ingress created manually to avoid errors in others Tests methods"); if (customIngressDeployedManuallySelector != null && customIngressDeployedManuallySelector.isReady()) { - assertThat(customIngressDeployedManuallySelector.delete()).isTrue(); + assertThat(customIngressDeployedManuallySelector.delete()).isNotNull(); Awaitility.await().untilAsserted(() -> { assertThat(k8sclient.network().v1().ingresses().inNamespace(namespace).list().getItems().size()).isEqualTo(0); }); diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakServicesTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakServicesTest.java index f9885ec576..9fa246cfd2 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakServicesTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakServicesTest.java @@ -40,7 +40,7 @@ public class KeycloakServicesTest extends BaseOperatorTest { var serviceSelector = k8sclient.services().inNamespace(namespace).withName(service.getName()); Log.info("Trying to delete the service"); - assertThat(serviceSelector.delete()).isTrue(); + assertThat(serviceSelector.delete()).isNotNull(); Awaitility.await() .untilAsserted(() -> assertThat(serviceSelector.get()).isNotNull()); @@ -79,7 +79,7 @@ public class KeycloakServicesTest extends BaseOperatorTest { var discoveryServiceSelector = k8sclient.services().inNamespace(namespace).withName(discoveryService.getName()); Log.info("Trying to delete the discovery service"); - assertThat(discoveryServiceSelector.delete()).isTrue(); + assertThat(discoveryServiceSelector.delete()).isNotNull(); Awaitility.await() .untilAsserted(() -> assertThat(discoveryServiceSelector.get()).isNotNull()); diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/utils/K8sUtils.java b/operator/src/test/java/org/keycloak/operator/testsuite/utils/K8sUtils.java index 654c5c91c2..9dc5e98e99 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/utils/K8sUtils.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/utils/K8sUtils.java @@ -29,6 +29,7 @@ import io.quarkus.logging.Log; import org.awaitility.Awaitility; import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak; import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatusCondition; +import org.keycloak.operator.testsuite.integration.BaseOperatorTest; import java.util.Objects; import java.util.UUID; @@ -43,7 +44,9 @@ public final class K8sUtils { } public static Keycloak getDefaultKeycloakDeployment() { - return getResourceFromFile("example-keycloak.yaml", Keycloak.class); + Keycloak kc = getResourceFromFile("example-keycloak.yaml", Keycloak.class); + kc.getMetadata().setNamespace(BaseOperatorTest.getCurrentNamespace()); + return kc; } public static Secret getDefaultTlsSecret() {