Skip to content

Commit

Permalink
add default resources
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Mészáros <[email protected]>
  • Loading branch information
csviri committed Sep 11, 2023
1 parent d8deae4 commit f31b5ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <R, P extends HasMetadata> void sanitizeDesired(R desired, R actual, P primary,
Context<P> context) {
if (useSSA(context)) {
Context<P> context, boolean useSSA) {
if (useSSA) {
if (desired instanceof StatefulSet) {
fillDefaultsOnVolumeClaimTemplate((StatefulSet) desired);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +40,10 @@ public abstract class KubernetesDependentResource<R extends HasMetadata, P exten

private static final Logger log = LoggerFactory.getLogger(KubernetesDependentResource.class);

public static final Set<Class<? extends HasMetadata>> DEFAULT_NON_SSA_RESOURCES =
Set.of(ConfigMap.class,
Secret.class);

protected KubernetesClient client;
private final ResourceUpdaterMatcher<R> updaterMatcher;
private final boolean garbageCollected = this instanceof GarbageCollected;
Expand Down Expand Up @@ -134,6 +140,7 @@ public R update(R actual, R desired, P primary, Context<P> 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 {
Expand Down Expand Up @@ -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<P> context) {
DesiredResourceSanitizer.sanitizeDesired(desired, actual, primary, context);
}
protected void sanitizeDesired(R desired, R actual, P primary, Context<P> context) {
DesiredResourceSanitizer.sanitizeDesired(desired, actual, primary, context, useSSA(context));
}

private boolean useSSA(Context<P> context) {
protected boolean useSSA(Context<P> context) {
Optional<Boolean> 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());
}
Expand Down

0 comments on commit f31b5ce

Please sign in to comment.