Skip to content

Commit

Permalink
Fix Optaplanner Operator, disabled SSA as with the current version of…
Browse files Browse the repository at this point in the history
… the code it's broken
  • Loading branch information
lucamolteni committed Mar 14, 2024
1 parent 33614d6 commit 3c2b33b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build/optaplanner-build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<version.ch.qos.logback>1.4.6</version.ch.qos.logback>
<version.org.apache.logging.log4j>2.20.0</version.org.apache.logging.log4j>
<version.com.thoughtworks.xstream>1.4.20</version.com.thoughtworks.xstream>
<version.io.quarkiverse.operatorsdk>6.0.3</version.io.quarkiverse.operatorsdk>
<version.io.quarkiverse.operatorsdk>6.6.4</version.io.quarkiverse.operatorsdk>
<version.io.quarkus>3.8.0</version.io.quarkus>
<version.org.apache.commons.math3>3.6.1</version.org.apache.commons.math3>
<version.org.apache.commons.text>1.10.0</version.org.apache.commons.text>
Expand Down
13 changes: 0 additions & 13 deletions optaplanner-operator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@
<java.module.name>org.optaplanner.operator</java.module.name>
</properties>

<!-- TODO: Remove when OptaPlanner no longer supports Quarkus 2.13 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${version.io.quarkus}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkiverse.operatorsdk</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OptaPlannerSolver>, ErrorStatusHandler<OptaPlannerSolver>,
Expand All @@ -61,13 +62,17 @@ public final class OptaPlannerSolverReconciler implements Reconciler<OptaPlanner
private final ScaledObjectDependentResource scaledObjectDependentResource;

@Inject
public OptaPlannerSolverReconciler(KubernetesClient kubernetesClient) {
deploymentDependentResource = new DeploymentDependentResource(kubernetesClient);
inputQueueDependentResource = new ArtemisQueueDependentResource(MessageAddress.INPUT, kubernetesClient);
outputQueueDependentResource = new ArtemisQueueDependentResource(MessageAddress.OUTPUT, kubernetesClient);
configMapDependentResource = new ConfigMapDependentResource(kubernetesClient);
triggerAuthenticationDependentResource = new TriggerAuthenticationDependentResource(kubernetesClient);
scaledObjectDependentResource = new ScaledObjectDependentResource(kubernetesClient);
QuarkusConfigurationService configurationService;

@Inject
public OptaPlannerSolverReconciler() {

deploymentDependentResource = new DeploymentDependentResource();
inputQueueDependentResource = new ArtemisQueueDependentResource(MessageAddress.INPUT);
outputQueueDependentResource = new ArtemisQueueDependentResource(MessageAddress.OUTPUT);
configMapDependentResource = new ConfigMapDependentResource();
triggerAuthenticationDependentResource = new TriggerAuthenticationDependentResource();
scaledObjectDependentResource = new ScaledObjectDependentResource();

inputQueueDependentResource.setResourceDiscriminator(new ResourceIDMatcherDiscriminator<>(
optaPlannerSolver -> new ResourceID(optaPlannerSolver.getInputMessageAddressName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -63,7 +61,7 @@ protected ConfigMap desired(OptaPlannerSolver solver, Context<OptaPlannerSolver>
public ConfigMap update(ConfigMap actual, ConfigMap target, OptaPlannerSolver solver, Context<OptaPlannerSolver> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@

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;

@KubernetesDependent
public final class ArtemisQueueDependentResource extends CRUDKubernetesDependentResource<ArtemisQueue, OptaPlannerSolver> {

public ArtemisQueueDependentResource(MessageAddress messageAddress, KubernetesClient kubernetesClient) {
public ArtemisQueueDependentResource(MessageAddress messageAddress) {
super(ArtemisQueue.class);
this.messageAddress = messageAddress;
setKubernetesClient(kubernetesClient);
}

private final MessageAddress messageAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

########################
Expand Down

0 comments on commit 3c2b33b

Please sign in to comment.