From 3c2b33b07d9fd76b42ff742d909f7930014dafb5 Mon Sep 17 00:00:00 2001 From: Luca Molteni Date: Thu, 14 Mar 2024 17:00:04 +0100 Subject: [PATCH] Fix Optaplanner Operator, disabled SSA as with the current version of the code it's broken --- build/optaplanner-build-parent/pom.xml | 2 +- optaplanner-operator/pom.xml | 13 ------------- .../solver/OptaPlannerSolverReconciler.java | 19 ++++++++++++------- .../model/ConfigMapDependentResource.java | 6 ++---- .../model/DeploymentDependentResource.java | 4 +--- .../keda/ScaledObjectDependentResource.java | 4 +--- ...riggerAuthenticationDependentResource.java | 4 +--- .../ArtemisQueueDependentResource.java | 4 +--- .../src/main/resources/application.properties | 8 ++++++++ 9 files changed, 27 insertions(+), 37 deletions(-) diff --git a/build/optaplanner-build-parent/pom.xml b/build/optaplanner-build-parent/pom.xml index 9d7167b480b..f8c339e706d 100644 --- a/build/optaplanner-build-parent/pom.xml +++ b/build/optaplanner-build-parent/pom.xml @@ -45,7 +45,7 @@ 1.4.6 2.20.0 1.4.20 - 6.0.3 + 6.6.4 3.8.0 3.6.1 1.10.0 diff --git a/optaplanner-operator/pom.xml b/optaplanner-operator/pom.xml index b61caf36426..d49f08a2b87 100644 --- a/optaplanner-operator/pom.xml +++ b/optaplanner-operator/pom.xml @@ -44,19 +44,6 @@ org.optaplanner.operator - - - - - io.quarkus - quarkus-bom - ${version.io.quarkus} - import - pom - - - - io.quarkiverse.operatorsdk diff --git a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/OptaPlannerSolverReconciler.java b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/OptaPlannerSolverReconciler.java index 11b61cc73c1..d3946a4b250 100644 --- a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/OptaPlannerSolverReconciler.java +++ b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/OptaPlannerSolverReconciler.java @@ -46,6 +46,7 @@ import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; +import io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService; @ControllerConfiguration(name = "optaplanner-solver") public final class OptaPlannerSolverReconciler implements Reconciler, ErrorStatusHandler, @@ -61,13 +62,17 @@ public final class OptaPlannerSolverReconciler implements Reconciler( optaPlannerSolver -> new ResourceID(optaPlannerSolver.getInputMessageAddressName(), diff --git a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/ConfigMapDependentResource.java b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/ConfigMapDependentResource.java index 61b6d4c4a79..cb8ed095416 100644 --- a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/ConfigMapDependentResource.java +++ b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/ConfigMapDependentResource.java @@ -24,7 +24,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; -import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; @@ -37,9 +36,8 @@ public final class ConfigMapDependentResource extends CRUDKubernetesDependentRes public static final String SOLVER_MESSAGE_AMQ_HOST_KEY = "solver.amq.host"; public static final String SOLVER_MESSAGE_AMQ_PORT_KEY = "solver.amq.port"; - public ConfigMapDependentResource(KubernetesClient kubernetesClient) { + public ConfigMapDependentResource() { super(ConfigMap.class); - setKubernetesClient(kubernetesClient); } @Override @@ -63,7 +61,7 @@ protected ConfigMap desired(OptaPlannerSolver solver, Context public ConfigMap update(ConfigMap actual, ConfigMap target, OptaPlannerSolver solver, Context context) { ConfigMap resultingConfigMap = super.update(actual, target, solver, context); String namespace = actual.getMetadata().getNamespace(); - getKubernetesClient() + context.getClient() .pods() .inNamespace(namespace) .withLabel("app", solver.getMetadata().getName()) diff --git a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/DeploymentDependentResource.java b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/DeploymentDependentResource.java index 297f68fa2b2..b78f4bffc04 100644 --- a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/DeploymentDependentResource.java +++ b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/DeploymentDependentResource.java @@ -32,7 +32,6 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder; import io.fabric8.kubernetes.api.model.apps.DeploymentSpecBuilder; -import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; @@ -47,9 +46,8 @@ public final class DeploymentDependentResource extends CRUDKubernetesDependentRe private static final String ENV_AMQ_USERNAME = "SOLVER_MESSAGE_AMQ_USERNAME"; private static final String ENV_AMQ_PASSWORD = "SOLVER_MESSAGE_AMQ_PASSWORD"; - public DeploymentDependentResource(KubernetesClient k8s) { + public DeploymentDependentResource() { super(Deployment.class); - setKubernetesClient(k8s); } @Override diff --git a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/keda/ScaledObjectDependentResource.java b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/keda/ScaledObjectDependentResource.java index 98a68427764..d5b0f8f3966 100644 --- a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/keda/ScaledObjectDependentResource.java +++ b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/keda/ScaledObjectDependentResource.java @@ -25,7 +25,6 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; @@ -75,9 +74,8 @@ public final class ScaledObjectDependentResource extends CRUDKubernetesDependent */ private static final int TARGET_QUEUE_LENGTH = 1; - public ScaledObjectDependentResource(KubernetesClient kubernetesClient) { + public ScaledObjectDependentResource() { super(ScaledObject.class); - setKubernetesClient(kubernetesClient); } @Override diff --git a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/keda/TriggerAuthenticationDependentResource.java b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/keda/TriggerAuthenticationDependentResource.java index 51398a1e391..a788fe81ea2 100644 --- a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/keda/TriggerAuthenticationDependentResource.java +++ b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/keda/TriggerAuthenticationDependentResource.java @@ -24,7 +24,6 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.SecretKeySelector; -import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; @@ -54,9 +53,8 @@ public final class TriggerAuthenticationDependentResource public static final String PARAM_USERNAME = "username"; public static final String PARAM_PASSWORD = "password"; - public TriggerAuthenticationDependentResource(KubernetesClient kubernetesClient) { + public TriggerAuthenticationDependentResource() { super(TriggerAuthentication.class); - setKubernetesClient(kubernetesClient); } @Override diff --git a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/messaging/ArtemisQueueDependentResource.java b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/messaging/ArtemisQueueDependentResource.java index 082a3a3943b..0c5bf820025 100644 --- a/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/messaging/ArtemisQueueDependentResource.java +++ b/optaplanner-operator/src/main/java/org/optaplanner/operator/impl/solver/model/messaging/ArtemisQueueDependentResource.java @@ -23,7 +23,6 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; @@ -31,10 +30,9 @@ @KubernetesDependent public final class ArtemisQueueDependentResource extends CRUDKubernetesDependentResource { - public ArtemisQueueDependentResource(MessageAddress messageAddress, KubernetesClient kubernetesClient) { + public ArtemisQueueDependentResource(MessageAddress messageAddress) { super(ArtemisQueue.class); this.messageAddress = messageAddress; - setKubernetesClient(kubernetesClient); } private final MessageAddress messageAddress; diff --git a/optaplanner-operator/src/main/resources/application.properties b/optaplanner-operator/src/main/resources/application.properties index be41ebafb56..8672871dc98 100644 --- a/optaplanner-operator/src/main/resources/application.properties +++ b/optaplanner-operator/src/main/resources/application.properties @@ -17,7 +17,15 @@ # under the License. # + quarkus.operator-sdk.crd.apply=true + +# New version of the operator use SSA, a different algorithm for creating resources +# that needs some changes. In the meanwhile this feature flag reverts to the old behaviour +# See https://javaoperatorsdk.io/docs/dependent-resources#comparing-desired-and-actual-state-matching +# And https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L332-L358 +quarkus.operator-sdk.enable-ssa=false + quarkus.log.category."io.quarkiverse.operatorsdk".level=ERROR ########################