Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.dsl.base.PatchContext;
import io.fabric8.kubernetes.client.dsl.base.PatchType;
import io.javaoperatorsdk.operator.OperatorException;
import io.javaoperatorsdk.operator.api.reconciler.support.PrimaryResourceCache;
import io.javaoperatorsdk.operator.processing.event.ResourceID;

Expand All @@ -34,7 +35,7 @@ private PrimaryUpdateAndCacheUtils() {}
* @param <P> primary resource type
*/
public static <P extends HasMetadata> P updateAndCacheStatus(P primary, Context<P> context) {
logWarnIfResourceVersionPresent(primary);
sanityChecks(primary, context);
return patchAndCacheStatus(
primary, context, () -> context.getClient().resource(primary).updateStatus());
}
Expand All @@ -49,7 +50,7 @@ public static <P extends HasMetadata> P updateAndCacheStatus(P primary, Context<
* @param <P> primary resource type
*/
public static <P extends HasMetadata> P patchAndCacheStatus(P primary, Context<P> context) {
logWarnIfResourceVersionPresent(primary);
sanityChecks(primary, context);
return patchAndCacheStatus(
primary, context, () -> context.getClient().resource(primary).patchStatus());
}
Expand All @@ -65,7 +66,7 @@ public static <P extends HasMetadata> P patchAndCacheStatus(P primary, Context<P
*/
public static <P extends HasMetadata> P editAndCacheStatus(
P primary, Context<P> context, UnaryOperator<P> operation) {
logWarnIfResourceVersionPresent(primary);
sanityChecks(primary, context);
return patchAndCacheStatus(
primary, context, () -> context.getClient().resource(primary).editStatus(operation));
}
Expand Down Expand Up @@ -101,24 +102,21 @@ public static <P extends HasMetadata> P patchAndCacheStatus(
*/
public static <P extends HasMetadata> P ssaPatchAndCacheStatus(
P primary, P freshResourceWithStatus, Context<P> context) {
logWarnIfResourceVersionPresent(freshResourceWithStatus);
var res =
context
.getClient()
.resource(freshResourceWithStatus)
.subresource("status")
.patch(
new PatchContext.Builder()
.withForce(true)
.withFieldManager(context.getControllerConfiguration().fieldManager())
.withPatchType(PatchType.SERVER_SIDE_APPLY)
.build());

context
.eventSourceRetriever()
.getControllerEventSource()
.handleRecentResourceUpdate(ResourceID.fromResource(primary), res, primary);
return res;
sanityChecks(freshResourceWithStatus, context);
return patchAndCacheStatus(
primary,
context,
() ->
context
.getClient()
.resource(freshResourceWithStatus)
.subresource("status")
.patch(
new PatchContext.Builder()
.withForce(true)
.withFieldManager(context.getControllerConfiguration().fieldManager())
.withPatchType(PatchType.SERVER_SIDE_APPLY)
.build()));
}

/**
Expand Down Expand Up @@ -222,4 +220,16 @@ private static <P extends HasMetadata> void logWarnIfResourceVersionPresent(P pr
+ "using optimistic locking is discouraged for this purpose. ");
}
}

private static <P extends HasMetadata> void sanityChecks(P primary, Context<P> context) {
logWarnIfResourceVersionPresent(primary);
if (!context
.getControllerConfiguration()
.getConfigurationService()
.parseResourceVersionsForEventFilteringAndCaching()) {
throw new OperatorException(
"For internal primary resource caching 'parseResourceVersionsForEventFilteringAndCaching'"
+ " must be allowed.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class StatusPatchCacheIT {
@RegisterExtension
LocallyRunOperatorExtension extension =
LocallyRunOperatorExtension.builder()
.withConfigurationService(o -> o.withParseResourceVersions(true))
.withReconciler(StatusPatchCacheReconciler.class)
.build();

Expand Down