Skip to content
Open
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 @@ -406,7 +406,9 @@ public <R extends HasMetadata> R update(
* @return the created resource as returned by the API server
*/
public <R extends HasMetadata> R create(R resource) {
// it is safe to do event filtering for create since check if the resource already exists.
// filtering the own event is safe here without optimistic locking or a matcher: a create either
// succeeds, in which case the event we filter is unambiguously ours, or the API server rejects
// it because the resource already exists.
return create(resource, Options.forceFilterEvents());
}

Expand Down Expand Up @@ -445,7 +447,7 @@ public <R extends HasMetadata> R create(
if (informerEventSource == null) {
return create(resource);
}
// it is safe to do event filtering for create since check if the resource already exists.
// see the note on create(R) about why filtering the own event is safe here
return resourcePatch(
resource, r -> context.getClient().resource(r).create(), informerEventSource, options);
}
Expand Down Expand Up @@ -556,7 +558,7 @@ public <R extends HasMetadata> R jsonPatch(R actualResource, UnaryOperator<R> un
*/
public <R extends HasMetadata> R jsonPatch(
R actualResource, UnaryOperator<R> unaryOperator, Options options) {
R desired = desiredForJsonPatch(actualResource, unaryOperator, options);
R desired = desiredForJsonPatch(actualResource, unaryOperator);
return resourcePatch(
desired,
actualResource,
Expand All @@ -580,7 +582,7 @@ public <R extends HasMetadata> R jsonPatch(
UnaryOperator<R> unaryOperator,
InformerEventSource<R, P> informerEventSource,
Options options) {
R desired = desiredForJsonPatch(actualResource, unaryOperator, options);
R desired = desiredForJsonPatch(actualResource, unaryOperator);
return resourcePatch(
desired,
actualResource,
Expand Down Expand Up @@ -620,7 +622,7 @@ public <R extends HasMetadata> R jsonPatchStatus(
*/
public <R extends HasMetadata> R jsonPatchStatus(
R actualResource, UnaryOperator<R> unaryOperator, Options options) {
R desired = desiredForJsonPatch(actualResource, unaryOperator, options);
R desired = desiredForJsonPatch(actualResource, unaryOperator);
return resourcePatch(
desired,
actualResource,
Expand All @@ -645,7 +647,7 @@ public <R extends HasMetadata> R jsonPatchStatus(
UnaryOperator<R> unaryOperator,
InformerEventSource<R, P> informerEventSource,
Options options) {
R desired = desiredForJsonPatch(actualResource, unaryOperator, options);
R desired = desiredForJsonPatch(actualResource, unaryOperator);
return resourcePatch(
desired,
actualResource,
Expand Down Expand Up @@ -680,7 +682,7 @@ public P jsonPatchPrimary(P actualResource, UnaryOperator<P> unaryOperator) {
* @return the patched resource as returned by the API server
*/
public P jsonPatchPrimary(P actualResource, UnaryOperator<P> unaryOperator, Options options) {
P desired = desiredForJsonPatch(actualResource, unaryOperator, options);
P desired = desiredForJsonPatch(actualResource, unaryOperator);
return resourcePatch(
desired,
actualResource,
Expand Down Expand Up @@ -717,7 +719,7 @@ public P jsonPatchPrimaryStatus(P actualResource, UnaryOperator<P> unaryOperator
*/
public P jsonPatchPrimaryStatus(
P actualResource, UnaryOperator<P> unaryOperator, Options options) {
P desired = desiredForJsonPatch(actualResource, unaryOperator, options);
P desired = desiredForJsonPatch(actualResource, unaryOperator);
return resourcePatch(
desired,
actualResource,
Expand Down Expand Up @@ -1435,7 +1437,7 @@ public enum Mode {
}

private <T extends HasMetadata> T desiredForJsonPatch(
T actualResource, UnaryOperator<T> unaryOperator, Options options) {
T actualResource, UnaryOperator<T> unaryOperator) {
var cloned =
context
.getControllerConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ public Optional<R> get(ResourceID resourceID) {
Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceID);
if (comparableResourceVersions
&& resource.isPresent()
&& ReconcilerUtilsInternal.compareResourceVersions(
resource.get().getMetadata().getResourceVersion(),
manager().lastSyncResourceVersion(resource.get().getMetadata().getNamespace()))
> 0) {
&& isLaterThanLastSyncResourceVersion(resource.orElseThrow())) {
log.debug("Latest resource found in temporary cache for Resource ID: {}", resourceID);
return resource;
} else {
Expand All @@ -242,6 +239,26 @@ public Optional<R> get(ResourceID resourceID) {
}
}

/**
* A resource from the temporary cache is only preferred over the informer cache if we can tell
* that it is newer. The last sync resource version is not available before an informer has
* completed its initial list, and the namespace might not be watched anymore after a dynamic
* namespace change, in both of which cases the informer cache is used instead.
*/
private boolean isLaterThanLastSyncResourceVersion(R resource) {
var namespace = resource.getMetadata().getNamespace();
if (!manager().isWatchingNamespace(namespace)) {
return false;
}
var lastSyncResourceVersion = manager().lastSyncResourceVersion(namespace);
if (lastSyncResourceVersion == null) {
return false;
}
Comment on lines +248 to +256
return ReconcilerUtilsInternal.compareResourceVersions(
resource.getMetadata().getResourceVersion(), lastSyncResourceVersion)
> 0;
}

/**
* @deprecated Use {@link #get(ResourceID)} instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ public boolean isNotPresentOrFulfilled() {
return !isExpectationPresent() || isFulfilled();
}

/**
* @return the name of the expectation this result refers to
* @throws IllegalStateException if there is no expectation, check {@link #isExpectationPresent()}
* first
*/
public String name() {
if (expectation == null) {
throw new IllegalStateException(
"No expectation present for this result, check isExpectationPresent() first.");
}
return expectation.name();
}
}
Loading