Remove ForceRecreate Operation

Closes #37661

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2025-03-03 16:26:33 +01:00 committed by GitHub
parent 44cbdc2fe1
commit 41c8623a94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 5 additions and 69 deletions

View File

@ -501,7 +501,7 @@ spec:
enabled:
- rolling-updates # <1>
update:
strategy: RecreateOnImageChange|ForceRecreate|Auto # <2>
strategy: RecreateOnImageChange|Auto # <2>
----
<1> Enable preview feature `rolling-updates`.
<2> Set the desired update strategy here (Recreate in this example).
@ -516,10 +516,6 @@ spec:
|Mimics Keycloak 26.1 or older behavior.
When the image field changes, the StatefulSet is scaled down before applying the new image.
|`ForceRecreate`
|On any configuration or image change
|The StatefulSet is scaled down before applying the new configuration or image.
|`Auto`
|On incompatible changes
|The {project_name} Operator detects if a rolling or recreate upgrade is possible.

View File

@ -253,6 +253,7 @@
</executions>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<!-- Used in KeycloakDeploymentTest#testPreconfiguredPodLabels -->
<OPERATOR_TEST_LABEL_EXPRESSION>my-value</OPERATOR_TEST_LABEL_EXPRESSION>
</systemPropertyVariables>

View File

@ -26,10 +26,6 @@ public enum UpdateStrategy {
@JsonProperty("RecreateOnImageChange")
RECREATE_ON_IMAGE_CHANGE,
@JsonPropertyDescription("Shutdown the Keycloak cluster before applying the new changes.")
@JsonProperty("ForceRecreate")
FORCE_RECREATE,
@JsonPropertyDescription("Automatically detects if the Keycloak CR changes requires a rolling or recreate update.")
@JsonProperty("Auto")
AUTO

View File

@ -23,7 +23,6 @@ import jakarta.inject.Inject;
import org.keycloak.operator.controllers.KeycloakUpdateJobDependentResource;
import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak;
import org.keycloak.operator.crds.v2alpha1.deployment.spec.UpdateSpec;
import org.keycloak.operator.upgrade.impl.ForceRecreateUpgradeLogic;
import org.keycloak.operator.upgrade.impl.AutoUpgradeLogic;
import org.keycloak.operator.upgrade.impl.RecreateOnImageChangeUpgradeLogic;
@ -39,7 +38,6 @@ public class UpgradeLogicFactory {
var strategy = UpdateSpec.getUpdateStrategy(keycloak);
return switch (strategy) {
case RECREATE_ON_IMAGE_CHANGE -> new RecreateOnImageChangeUpgradeLogic(context, keycloak);
case FORCE_RECREATE -> new ForceRecreateUpgradeLogic(context, keycloak);
case AUTO -> new AutoUpgradeLogic(context, keycloak, updateJobDependentResource);
};
}

View File

@ -1,43 +0,0 @@
/*
* Copyright 2025 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.operator.upgrade.impl;
import java.util.Optional;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak;
import org.keycloak.operator.upgrade.UpgradeLogic;
import org.keycloak.operator.upgrade.UpgradeType;
/**
* An {@link UpgradeLogic} implementation that forces a {@link UpgradeType#RECREATE} on every configuration or image
* change.
*/
public class ForceRecreateUpgradeLogic extends BaseUpgradeLogic {
public ForceRecreateUpgradeLogic(Context<Keycloak> context, Keycloak keycloak) {
super(context, keycloak);
}
@Override
Optional<UpdateControl<Keycloak>> onUpgrade() {
decideRecreateUpgrade("Strategy ForceRecreate configured.");
return Optional.empty();
}
}

View File

@ -80,9 +80,6 @@ public class UpgradeTest extends BaseOperatorTest {
// - Unexpected update-compatibility command exit code.
assertRecreateUpdateTypeStatus(kc, "Unexpected update-compatibility command");
break;
case FORCE_RECREATE:
assertRecreateUpdateTypeStatus(kc, "Strategy ForceRecreate configured.");
break;
case RECREATE_ON_IMAGE_CHANGE:
assertRecreateUpdateTypeStatus(kc, "Image changed");
break;
@ -113,11 +110,8 @@ public class UpgradeTest extends BaseOperatorTest {
assertUnknownUpdateTypeStatus(kc);
// changing the local cache max-count should never use the recreate upgrade type
// except if forced by the Keycloak CR.
kc.getSpec().getAdditionalOptions().add(new ValueOrSecret("cache-embedded-authorization-max-count", "10"));
var upgradeCondition = updateStrategy == UpdateStrategy.FORCE_RECREATE ?
eventuallyRecreateUpgradeStatus(k8sclient, kc) :
eventuallyRollingUpgradeStatus(k8sclient, kc);
var upgradeCondition = eventuallyRollingUpgradeStatus(k8sclient, kc);
deployKeycloak(k8sclient, kc, true);
await(upgradeCondition);
@ -125,9 +119,6 @@ public class UpgradeTest extends BaseOperatorTest {
case AUTO:
assertRollingUpdateTypeStatus(kc, "Compatible changes detected.");
break;
case FORCE_RECREATE:
assertRecreateUpdateTypeStatus(kc, "Strategy ForceRecreate configured.");
break;
case RECREATE_ON_IMAGE_CHANGE:
assertRollingUpdateTypeStatus(kc, "Image unchanged");
break;
@ -162,9 +153,6 @@ public class UpgradeTest extends BaseOperatorTest {
case AUTO:
assertRollingUpdateTypeStatus(kc, "Compatible changes detected.");
break;
case FORCE_RECREATE:
assertRecreateUpdateTypeStatus(kc, "Strategy ForceRecreate configured.");
break;
case RECREATE_ON_IMAGE_CHANGE:
assertRecreateUpdateTypeStatus(kc, "Image changed");
break;

View File

@ -262,7 +262,7 @@ public class CRSerializationTest {
assertNotNull(updateSpec);
var upgradeStrategy = updateSpec.getStrategy();
assertNotNull(upgradeStrategy);
assertEquals(UpdateStrategy.FORCE_RECREATE, upgradeStrategy);
assertEquals(UpdateStrategy.AUTO, upgradeStrategy);
}
@Test

View File

@ -124,7 +124,7 @@ spec:
service:
secret: else
update:
strategy: ForceRecreate
strategy: Auto
unsupported:
podTemplate:
metadata: