mirror of
https://github.com/keycloak/keycloak.git
synced 2026-02-03 20:39:33 -05:00
fix: performing scale down prior to deletion (#44095)
closes: #34868 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
fb13aa5039
commit
281ced0ca8
1 changed files with 14 additions and 1 deletions
|
|
@ -62,6 +62,7 @@ import org.keycloak.operator.controllers.KeycloakDeploymentDependentResource;
|
|||
import org.keycloak.operator.controllers.KeycloakRealmImportController;
|
||||
import org.keycloak.operator.controllers.KeycloakUpdateJobDependentResource;
|
||||
import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak;
|
||||
import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakBuilder;
|
||||
import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakSpecBuilder;
|
||||
import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatus;
|
||||
import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImport;
|
||||
|
|
@ -341,12 +342,24 @@ public enum OperatorDeployment {local_apiserver,local,remote}
|
|||
}
|
||||
Log.info("Deleting Keycloak CR");
|
||||
|
||||
// first graceful scaledown
|
||||
k8sclient.resources(Keycloak.class).list().getItems().forEach(
|
||||
k -> k8sclient.resource(new KeycloakBuilder(k).editSpec().withInstances(0).endSpec().build()).update());
|
||||
|
||||
try {
|
||||
k8sclient.resources(Keycloak.class).informOnCondition(
|
||||
l -> l.stream().allMatch(k -> Optional.ofNullable(k.getStatus()).map(KeycloakStatus::getInstances).orElse(0).equals(0)))
|
||||
.get(40, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
throw KubernetesClientException.launderThrowable(e);
|
||||
}
|
||||
|
||||
// this can be simplified to just the root deletion after we pick up the fix
|
||||
// it can be further simplified after https://github.com/fabric8io/kubernetes-client/issues/5838
|
||||
// to just a timed foreground deletion
|
||||
var roots = List.of(Keycloak.class, KeycloakRealmImport.class);
|
||||
roots.forEach(c -> k8sclient.resources(c).delete());
|
||||
// enforce that at least the statefulset / pods are gone
|
||||
// enforce that at least the statefulset are gone
|
||||
try {
|
||||
k8sclient
|
||||
.apps()
|
||||
|
|
|
|||
Loading…
Reference in a new issue