From f31b5ce02072374cab843cf891365085102034a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 11 Sep 2023 14:14:25 +0200 Subject: [PATCH] add default resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../kubernetes/DesiredResourceSanitizer.java | 6 ++---- .../KubernetesDependentResource.java | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/DesiredResourceSanitizer.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/DesiredResourceSanitizer.java index 4e5962d1d2..0521a35173 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/DesiredResourceSanitizer.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/DesiredResourceSanitizer.java @@ -6,15 +6,13 @@ import io.fabric8.kubernetes.api.model.apps.StatefulSet; import io.javaoperatorsdk.operator.api.reconciler.Context; -import static io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource.useSSA; - public class DesiredResourceSanitizer { private DesiredResourceSanitizer() {} public static void sanitizeDesired(R desired, R actual, P primary, - Context

context) { - if (useSSA(context)) { + Context

context, boolean useSSA) { + if (useSSA) { if (desired instanceof StatefulSet) { fillDefaultsOnVolumeClaimTemplate((StatefulSet) desired); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 7dbdee91da..9afabec7f1 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -7,7 +7,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.Resource; import io.javaoperatorsdk.operator.OperatorException; @@ -38,6 +40,10 @@ public abstract class KubernetesDependentResource> DEFAULT_NON_SSA_RESOURCES = + Set.of(ConfigMap.class, + Secret.class); + protected KubernetesClient client; private final ResourceUpdaterMatcher updaterMatcher; private final boolean garbageCollected = this instanceof GarbageCollected; @@ -134,6 +140,7 @@ public R update(R actual, R desired, P primary, Context

context) { sanitizeDesired(desired, actual, primary, context); if (useSSA(context)) { updatedResource = prepare(desired, primary, "Updating") + .fieldManager(context.getControllerConfiguration().fieldManager()) .fieldManager(context.getControllerConfiguration().fieldManager()) .forceConflicts().serverSideApply(); } else { @@ -192,13 +199,18 @@ protected void addMetadata(boolean forMatch, R actualResource, final R target, P addReferenceHandlingMetadata(target, primary); } - protected void sanitizeDesired(R desired, R actual, P primary, Context

context) { - DesiredResourceSanitizer.sanitizeDesired(desired, actual, primary, context); - } + protected void sanitizeDesired(R desired, R actual, P primary, Context

context) { + DesiredResourceSanitizer.sanitizeDesired(desired, actual, primary, context, useSSA(context)); + } - private boolean useSSA(Context

context) { + protected boolean useSSA(Context

context) { Optional useSSAConfig = configuration().flatMap(KubernetesDependentResourceConfig::useSSA); + + // don't use SSA for certain resources by default, only if explicitly overriden + if (useSSAConfig.isEmpty() && DEFAULT_NON_SSA_RESOURCES.contains(resourceType())) { + return false; + } return useSSAConfig.orElse(context.getControllerConfiguration().getConfigurationService() .ssaBasedCreateUpdateMatchForDependentResources()); }