mirror of
https://github.com/keycloak/keycloak.git
synced 2026-05-07 23:50:03 -05:00
fix: check operand StatefulSet is ready before creating job (#24720)
closes #24526 Signed-off-by: Steve Hawkins <shawkins@redhat.com> Co-authored-by: Piotr Godowski <Piotr.Godowski@pl.ibm.com>
This commit is contained in:
+14
-1
@@ -17,6 +17,7 @@
|
||||
package org.keycloak.operator.controllers;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
|
||||
import io.fabric8.kubernetes.api.model.apps.StatefulSetStatus;
|
||||
import io.fabric8.kubernetes.api.model.batch.v1.Job;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.javaoperatorsdk.operator.api.reconciler.Context;
|
||||
@@ -37,6 +38,7 @@ import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImportStatus
|
||||
import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImportStatusCondition;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
@@ -74,7 +76,9 @@ public class KeycloakRealmImportController implements Reconciler<KeycloakRealmIm
|
||||
|
||||
if (existingDeployment != null) {
|
||||
context.managedDependentResourceContext().put(StatefulSet.class, existingDeployment);
|
||||
jobDependentResource.reconcile(realm, context);
|
||||
if (getReadyReplicas(existingDeployment) > 0) {
|
||||
jobDependentResource.reconcile(realm, context);
|
||||
}
|
||||
}
|
||||
|
||||
updateStatus(statusBuilder, realm, existingJob, existingDeployment);
|
||||
@@ -118,6 +122,11 @@ public class KeycloakRealmImportController implements Reconciler<KeycloakRealmIm
|
||||
return;
|
||||
}
|
||||
|
||||
if (getReadyReplicas(existingDeployment) < 1) {
|
||||
status.addErrorMessage("Deployment not yet ready, waiting for it to be ready");
|
||||
return;
|
||||
}
|
||||
|
||||
if (existingJob == null) {
|
||||
Log.info("Job about to start");
|
||||
status.addStartedMessage("Import Job will start soon");
|
||||
@@ -145,6 +154,10 @@ public class KeycloakRealmImportController implements Reconciler<KeycloakRealmIm
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getReadyReplicas(StatefulSet existingDeployment) {
|
||||
return Optional.ofNullable(existingDeployment.getStatus()).map(StatefulSetStatus::getReadyReplicas).orElse(0);
|
||||
}
|
||||
|
||||
private void rollingRestart(KeycloakRealmImport realmCR) {
|
||||
client.apps().statefulSets()
|
||||
.inNamespace(realmCR.getMetadata().getNamespace())
|
||||
|
||||
Reference in New Issue
Block a user