From 334da3339bb7d176d5f99653499c55af905c0243 Mon Sep 17 00:00:00 2001 From: ebma16 <102992049+ebma16@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:27:33 +0100 Subject: [PATCH] chore: update to josdk v5.0.0-beta1 and fabric8-client v7.0.0 and related fixes (#191) * chore: update to josdk v5.0.0-beta1 and fabric8 kubernetes-client v7.0.0 and related fixes * fix: apply spotless plugin to reformat code * fix: remove dependency jetbrains-annotations from pom files * fix: remove unnecessary jetbrain-annotation from CRDApplier.java --- pom.xml | 4 ++-- ...e.java => ConfigMapDependentResource.java} | 8 +++++--- .../sample/CustomServiceReconciler.java | 7 ++++--- .../starter/test/TestConfiguration.java | 3 +-- .../springboot/starter/CRDApplier.java | 3 +-- .../starter/OperatorAutoConfiguration.java | 19 +++++++++---------- .../starter/AutoConfigurationTest.java | 6 ++++-- .../starter/model/TestResourceList.java | 4 ++-- 8 files changed, 28 insertions(+), 26 deletions(-) rename samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/{ConfigMapDpendentResource.java => ConfigMapDependentResource.java} (79%) diff --git a/pom.xml b/pom.xml index bbd3d78..9181b54 100644 --- a/pom.xml +++ b/pom.xml @@ -59,9 +59,9 @@ 17 2.43.0 3.3.6 - 4.9.7 + 5.0.0-beta1 3.5.2 - 6.13.4 + 7.0.0 0.9.7 1.7.0 3.11.2 diff --git a/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDpendentResource.java b/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDependentResource.java similarity index 79% rename from samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDpendentResource.java rename to samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDependentResource.java index f662bd3..557408b 100644 --- a/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDpendentResource.java +++ b/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDependentResource.java @@ -5,14 +5,16 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(labelSelector = "app.kubernetes.io/managed-by=custom-service-operator") -public class ConfigMapDpendentResource +@KubernetesDependent( + informer = @Informer(labelSelector = "app.kubernetes.io/managed-by=custom-service-operator")) +public class ConfigMapDependentResource extends CRUDKubernetesDependentResource { - public ConfigMapDpendentResource() { + public ConfigMapDependentResource() { super(ConfigMap.class); } diff --git a/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/CustomServiceReconciler.java b/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/CustomServiceReconciler.java index 2edbae0..56bf56b 100644 --- a/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/CustomServiceReconciler.java +++ b/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/CustomServiceReconciler.java @@ -15,9 +15,10 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; /** A very simple sample controller that creates a service with a label. */ -@ControllerConfiguration(dependents = { - @Dependent(name = "config", type = ConfigMapDpendentResource.class) +@Workflow(dependents = { + @Dependent(name = "config", type = ConfigMapDependentResource.class) }) +@ControllerConfiguration public class CustomServiceReconciler implements Reconciler { private static final Logger log = LoggerFactory.getLogger(CustomServiceReconciler.class); @@ -57,6 +58,6 @@ public UpdateControl reconcile( .inNamespace(resource.getMetadata().getNamespace()) .createOrReplace(service); - return UpdateControl.updateResource(resource); + return UpdateControl.patchResource(resource); } } diff --git a/starter-test/src/main/java/io/javaoperatorsdk/operator/springboot/starter/test/TestConfiguration.java b/starter-test/src/main/java/io/javaoperatorsdk/operator/springboot/starter/test/TestConfiguration.java index 2eea2b8..d5d9427 100644 --- a/starter-test/src/main/java/io/javaoperatorsdk/operator/springboot/starter/test/TestConfiguration.java +++ b/starter-test/src/main/java/io/javaoperatorsdk/operator/springboot/starter/test/TestConfiguration.java @@ -20,10 +20,9 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.mockwebserver.Context; +import io.fabric8.mockwebserver.MockWebServer; import io.javaoperatorsdk.operator.springboot.starter.OperatorAutoConfiguration; -import okhttp3.mockwebserver.MockWebServer; - @Configuration @ImportAutoConfiguration(OperatorAutoConfiguration.class) @EnableConfigurationProperties(TestConfigurationProperties.class) diff --git a/starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/CRDApplier.java b/starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/CRDApplier.java index f9cfdf7..cd2becf 100644 --- a/starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/CRDApplier.java +++ b/starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/CRDApplier.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.function.UnaryOperator; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -27,7 +26,7 @@ public interface CRDApplier { void apply(); interface CRDTransformer extends UnaryOperator { - default CRDTransformer thenTransform(@NotNull CRDApplier.CRDTransformer after) { + default CRDTransformer thenTransform(CRDApplier.CRDTransformer after) { return t -> after.apply(apply(t)); } diff --git a/starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java b/starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java index cb57e26..7c17585 100644 --- a/starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java +++ b/starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java @@ -26,7 +26,11 @@ import io.fabric8.openshift.client.OpenShiftClient; import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.api.config.*; +import io.javaoperatorsdk.operator.api.config.Cloner; +import io.javaoperatorsdk.operator.api.config.ConfigurationServiceOverrider; +import io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider; +import io.javaoperatorsdk.operator.api.config.DefaultResourceClassResolver; +import io.javaoperatorsdk.operator.api.config.ResourceClassResolver; import io.javaoperatorsdk.operator.api.monitoring.Metrics; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; @@ -93,7 +97,7 @@ public Operator operator( KubernetesClient kubernetesClient, List> reconcilers) { - var operator = new Operator(kubernetesClient, compositeConfigurationServiceOverrider); + var operator = new Operator(compositeConfigurationServiceOverrider); reconcilers.forEach(reconciler -> reconcilerRegisterer.accept(operator, reconciler)); return operator; @@ -122,14 +126,9 @@ public Consumer compositeConfigurationServiceOver @Order(0) public Consumer defaultConfigServiceOverrider( @Autowired(required = false) Cloner cloner, - ResourceClassResolver resourceClassResolver, - Metrics metrics) { + Metrics metrics, KubernetesClient kubernetesClient) { return overrider -> { doIfPresent(cloner, overrider::withResourceCloner); - doIfPresent(configuration.getMinConcurrentWorkflowExecutorThreads(), - overrider::withMinConcurrentWorkflowExecutorThreads); - doIfPresent(configuration.getMinConcurrentReconciliationThreads(), - overrider::withMinConcurrentReconciliationThreads); doIfPresent(configuration.getStopOnInformerErrorDuringStartup(), overrider::withStopOnInformerErrorDuringStartup); doIfPresent(configuration.getConcurrentWorkflowExecutorThreads(), @@ -139,8 +138,8 @@ public Consumer defaultConfigServiceOverrider( overrider .withConcurrentReconciliationThreads(configuration.getConcurrentReconciliationThreads()) .withMetrics(metrics) - .withResourceClassResolver(resourceClassResolver) - .checkingCRDAndValidateLocalModel(configuration.getCheckCrdAndValidateLocalModel()); + .checkingCRDAndValidateLocalModel(configuration.getCheckCrdAndValidateLocalModel()) + .withKubernetesClient(kubernetesClient); }; } diff --git a/starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/AutoConfigurationTest.java b/starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/AutoConfigurationTest.java index 1ee3f71..d24baed 100644 --- a/starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/AutoConfigurationTest.java +++ b/starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/AutoConfigurationTest.java @@ -95,11 +95,13 @@ void appliesConfigPropertiesToControllers() { .satisfies(controller -> { assertThat((ControllerConfiguration) controller.getConfiguration()) .satisfies(config -> { - assertThat(config.getNamespaces()).containsExactlyInAnyOrder("ns1", "ns2"); + assertThat(config.getInformerConfig().getNamespaces()) + .containsExactlyInAnyOrder("ns1", "ns2"); assertThat(config.isGenerationAware()).isTrue(); assertThat(config.getName()).isEqualTo("not-a-test-reconciler"); assertThat(config.getFinalizerName()).isEqualTo("barton.fink/1991"); - assertThat(config.getLabelSelector()).isEqualTo("version in (v1)"); + assertThat(config.getInformerConfig().getLabelSelector()) + .isEqualTo("version in (v1)"); assertThat(config.maxReconciliationInterval()).hasValue(Duration.ofMinutes(3)); }); assertThat(controller.getConfiguration().getRetry()) diff --git a/starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/model/TestResourceList.java b/starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/model/TestResourceList.java index 291639b..fac3e4a 100644 --- a/starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/model/TestResourceList.java +++ b/starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/model/TestResourceList.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.springboot.starter.model; -import io.fabric8.kubernetes.client.CustomResourceList; +import io.fabric8.kubernetes.api.model.DefaultKubernetesResourceList; -public class TestResourceList extends CustomResourceList { +public class TestResourceList extends DefaultKubernetesResourceList { }