From e5d763afc8357a5ba4662adf64687ef8e9d30e64 Mon Sep 17 00:00:00 2001 From: ebma16 Date: Tue, 10 Dec 2024 11:05:23 +0100 Subject: [PATCH 1/4] chore: update to josdk v5.0.0-beta1 and fabric8 kubernetes-client v7.0.0 and related fixes --- pom.xml | 5 +- ...e.java => ConfigMapDependentResource.java} | 9 ++-- .../sample/CustomServiceReconciler.java | 7 +-- .../starter/test/TestConfiguration.java | 2 +- starter/pom.xml | 6 +++ .../starter/OperatorAutoConfiguration.java | 54 +++++++++---------- .../starter/AutoConfigurationTest.java | 4 +- .../starter/model/TestResourceList.java | 4 +- 8 files changed, 50 insertions(+), 41 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..b301acf 100644 --- a/pom.xml +++ b/pom.xml @@ -59,14 +59,15 @@ 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 3.2.7 3.3.1 + 26.0.1 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..24df400 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,17 @@ 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..a713651 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 @@ -22,7 +22,7 @@ import io.fabric8.mockwebserver.Context; import io.javaoperatorsdk.operator.springboot.starter.OperatorAutoConfiguration; -import okhttp3.mockwebserver.MockWebServer; +import io.fabric8.mockwebserver.MockWebServer; @Configuration @ImportAutoConfiguration(OperatorAutoConfiguration.class) diff --git a/starter/pom.xml b/starter/pom.xml index 36494a2..f55a76f 100644 --- a/starter/pom.xml +++ b/starter/pom.xml @@ -115,5 +115,11 @@ jenvtest-fabric8-client-support test + + org.jetbrains + annotations + ${jetbrains-annotations.version} + compile + 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..df34a60 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 @@ -1,23 +1,5 @@ package io.javaoperatorsdk.operator.springboot.starter; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.BiConsumer; -import java.util.function.Consumer; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; - import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.KubernetesClient; @@ -26,12 +8,33 @@ 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; import io.javaoperatorsdk.operator.springboot.starter.CRDApplier.CRDTransformer; import io.javaoperatorsdk.operator.springboot.starter.CRDApplier.DefaultCRDApplier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.BiConsumer; +import java.util.function.Consumer; @Configuration @EnableConfigurationProperties(OperatorConfigurationProperties.class) @@ -93,7 +96,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 +125,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 +137,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..67e2a64 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,11 @@ 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 { } From 36ae36619e83d678c5d2e8842f478a5ca178b47c Mon Sep 17 00:00:00 2001 From: ebma16 Date: Tue, 10 Dec 2024 11:41:59 +0100 Subject: [PATCH 2/4] fix: apply spotless plugin to reformat code --- .../sample/ConfigMapDependentResource.java | 3 +- .../starter/test/TestConfiguration.java | 3 +- .../starter/OperatorAutoConfiguration.java | 35 ++++++++++--------- .../starter/AutoConfigurationTest.java | 6 ++-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDependentResource.java b/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDependentResource.java index 24df400..557408b 100644 --- a/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDependentResource.java +++ b/samples/common/src/main/java/io/javaoperatorsdk/operator/springboot/starter/sample/ConfigMapDependentResource.java @@ -11,8 +11,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; @KubernetesDependent( - informer = @Informer(labelSelector = "app.kubernetes.io/managed-by=custom-service-operator") -) + informer = @Informer(labelSelector = "app.kubernetes.io/managed-by=custom-service-operator")) public class ConfigMapDependentResource extends CRUDKubernetesDependentResource { public ConfigMapDependentResource() { 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 a713651..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 io.fabric8.mockwebserver.MockWebServer; - @Configuration @ImportAutoConfiguration(OperatorAutoConfiguration.class) @EnableConfigurationProperties(TestConfigurationProperties.class) 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 df34a60..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 @@ -1,5 +1,23 @@ package io.javaoperatorsdk.operator.springboot.starter; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; + import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.KubernetesClient; @@ -18,23 +36,6 @@ import io.javaoperatorsdk.operator.processing.retry.GenericRetry; import io.javaoperatorsdk.operator.springboot.starter.CRDApplier.CRDTransformer; import io.javaoperatorsdk.operator.springboot.starter.CRDApplier.DefaultCRDApplier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.BiConsumer; -import java.util.function.Consumer; @Configuration @EnableConfigurationProperties(OperatorConfigurationProperties.class) 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 67e2a64..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.getInformerConfig().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.getInformerConfig().getLabelSelector()).isEqualTo("version in (v1)"); + assertThat(config.getInformerConfig().getLabelSelector()) + .isEqualTo("version in (v1)"); assertThat(config.maxReconciliationInterval()).hasValue(Duration.ofMinutes(3)); }); assertThat(controller.getConfiguration().getRetry()) From cbbf449022cdeb2fba8e39da45af2a478e77bf88 Mon Sep 17 00:00:00 2001 From: ebma16 Date: Tue, 10 Dec 2024 14:03:23 +0100 Subject: [PATCH 3/4] fix: remove dependency jetbrains-annotations from pom files --- pom.xml | 1 - starter/pom.xml | 6 ------ 2 files changed, 7 deletions(-) diff --git a/pom.xml b/pom.xml index b301acf..9181b54 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,6 @@ 3.11.2 3.2.7 3.3.1 - 26.0.1 diff --git a/starter/pom.xml b/starter/pom.xml index f55a76f..36494a2 100644 --- a/starter/pom.xml +++ b/starter/pom.xml @@ -115,11 +115,5 @@ jenvtest-fabric8-client-support test - - org.jetbrains - annotations - ${jetbrains-annotations.version} - compile - From d4e4474aa4cbf35f9df858604998d38d45413b72 Mon Sep 17 00:00:00 2001 From: ebma16 Date: Tue, 10 Dec 2024 14:11:34 +0100 Subject: [PATCH 4/4] fix: remove unnecessary jetbrain-annotation from CRDApplier.java --- .../operator/springboot/starter/CRDApplier.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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)); }