Skip to content

draft of changes to simplify the recording mechanism #2005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public abstract class KubernetesDependentResource<R extends HasMetadata, P exten
implements KubernetesClientAware,
DependentResourceConfigurator<KubernetesDependentResourceConfig<R>> {

public static String PREVIOUS_ANNOTATION_KEY = "javaoperatorsdk.io/previous";

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

protected KubernetesClient client;
Expand Down Expand Up @@ -103,35 +105,14 @@ public void configureWith(InformerEventSource<R, P> informerEventSource) {
setEventSource(informerEventSource);
}


protected R handleCreate(R desired, P primary, Context<P> context) {
ResourceID resourceID = ResourceID.fromResource(desired);
try {
prepareEventFiltering(desired, resourceID);
return super.handleCreate(desired, primary, context);
} catch (RuntimeException e) {
cleanupAfterEventFiltering(resourceID);
throw e;
}
}

protected R handleUpdate(R actual, R desired, P primary, Context<P> context) {
ResourceID resourceID = ResourceID.fromResource(desired);
try {
prepareEventFiltering(desired, resourceID);
return super.handleUpdate(actual, desired, primary, context);
} catch (RuntimeException e) {
cleanupAfterEventFiltering(resourceID);
throw e;
}
}

@SuppressWarnings("unused")
public R create(R target, P primary, Context<P> context) {
if (useSSA(context)) {
// setting resource version for SSA so only created if it doesn't exist already
target.getMetadata().setResourceVersion("1");
}
String id = ((InformerEventSource<R, P>) eventSource().orElseThrow()).getId();
target.getMetadata().getAnnotations().put(PREVIOUS_ANNOTATION_KEY, id);
final var resource = prepare(target, primary, "Creating");
return useSSA(context)
? resource
Expand All @@ -147,20 +128,24 @@ public R update(R actual, R target, P primary, Context<P> context) {
actual.getMetadata().getResourceVersion());
}
R updatedResource;
String id = ((InformerEventSource<R, P>) eventSource().orElseThrow()).getId();
target.getMetadata().getAnnotations().put(PREVIOUS_ANNOTATION_KEY,
id + "," + actual.getMetadata().getResourceVersion());
if (useSSA(context)) {
target.getMetadata().setResourceVersion(actual.getMetadata().getResourceVersion());
updatedResource = prepare(target, primary, "Updating")
.fieldManager(context.getControllerConfiguration().fieldManager())
.forceConflicts().serverSideApply();
} else {
var updatedActual = updaterMatcher.updateResource(actual, target, context);
updatedResource = prepare(updatedActual, primary, "Updating").replace();
updatedResource = prepare(updatedActual, primary, "Updating").update();
}
log.debug("Resource version after update: {}",
updatedResource.getMetadata().getResourceVersion());
return updatedResource;
}

@Override
public Result<R> match(R actualResource, P primary, Context<P> context) {
final var desired = desired(primary, context);
final boolean matches;
Expand Down Expand Up @@ -193,6 +178,7 @@ private boolean useSSA(Context<P> context) {
.ssaBasedCreateUpdateMatchForDependentResources();
}

@Override
protected void handleDelete(P primary, R secondary, Context<P> context) {
if (secondary != null) {
client.resource(secondary).delete();
Expand Down Expand Up @@ -290,16 +276,6 @@ protected R desired(P primary, Context<P> context) {
return super.desired(primary, context);
}

private void prepareEventFiltering(R desired, ResourceID resourceID) {
((InformerEventSource<R, P>) eventSource().orElseThrow())
.prepareForCreateOrUpdateEventFiltering(resourceID, desired);
}

private void cleanupAfterEventFiltering(ResourceID resourceID) {
((InformerEventSource<R, P>) eventSource().orElseThrow())
.cleanupOnCreateOrUpdateEventFiltering(resourceID);
}

@Override
public Optional<KubernetesDependentResourceConfig<R>> configuration() {
return Optional.ofNullable(kubernetesDependentResourceConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ public boolean matches(R actual, R desired, Context<?> context) {
keepOnlyManagedFields(prunedActual, actualMap,
managedFieldsEntry.getFieldsV1().getAdditionalProperties(), objectMapper);

((Map<String, Object>) prunedActual.get(METADATA_KEY)).computeIfPresent("annotations", (k, v) -> {
var annotations = (Map<String, Object>)v;
annotations.remove(KubernetesDependentResource.PREVIOUS_ANNOTATION_KEY);
if (annotations.isEmpty()) {
return null;
}
return annotations;
});

removeIrrelevantValues(desiredMap);

if (LoggingUtils.isNotSensitiveResource(desired)) {
Expand Down

This file was deleted.

Loading