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 @@ -191,20 +191,36 @@ public void handleRecentResourceCreate(ResourceID resourceID, R resource) {

@Override
public Optional<R> get(ResourceID resourceID) {
// The order of reading from these caches matters
Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceID);
var res = cache.get(resourceID);
if (comparableResourceVersions
&& resource.isPresent()
&& ReconcilerUtilsInternal.compareResourceVersions(
resource.get().getMetadata().getResourceVersion(),
manager().lastSyncResourceVersion(resource.get().getMetadata().getNamespace()))
> 0) {
log.debug("Latest resource found in temporary cache for Resource ID: {}", resourceID);
return resource;
if (comparableResourceVersions && resource.isPresent()) {
var comp =
ReconcilerUtilsInternal.compareResourceVersions(
resource.get().getMetadata().getResourceVersion(),
manager().lastSyncResourceVersion(resource.get().getMetadata().getNamespace()));
if (comp > 0) {
log.debug("Latest resource found in temporary cache for Resource ID: {}", resourceID);
return resource;
} else {
log.debug(
"Latest resource not found in temporary but was obsolete: {}. Re-reading the informer"
+ " cache: {}",
resourceID,
res.isEmpty());
if (res.isEmpty()) {
// re-reading resource from informer cache since an add even might have received
// after the first read.
return cache.get(resourceID);
} else {
Comment on lines +211 to +215
return res;
}
}
}
log.debug(
"Resource not found, or older, in temporary cache. Found in informer cache {}, for"
+ " Resource ID: {}",
"Resource found in temp cache: {}, or older, in temporary cache. Found in informer cache"
+ " {}, for Resource ID: {}",
Comment on lines +221 to +222
resource.isPresent(),
res.isPresent(),
resourceID);
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,39 @@ public UpdateControl<CachingFilteringUpdateCustomResource> reconcile(
CachingFilteringUpdateCustomResource resource,
Context<CachingFilteringUpdateCustomResource> context) {

context.resourceOperations().serverSideApply(prepareCM(resource));
context.resourceOperations().serverSideApply(prepareCM(resource, 1));
var cachedCM = context.getSecondaryResource(ConfigMap.class);
if (cachedCM.isEmpty()) {
issueFound.set(true);
throw new IllegalStateException("Error for resource: " + ResourceID.fromResource(resource));
}

var updated = context.resourceOperations().serverSideApply(prepareCM(resource, 2));
cachedCM = context.getSecondaryResource(ConfigMap.class);
if (!cachedCM
.orElseThrow()
Comment on lines +55 to +56
.getMetadata()
.getResourceVersion()
.equals(updated.getMetadata().getResourceVersion())) {
issueFound.set(true);
throw new IllegalStateException(
"Update error for resource: " + ResourceID.fromResource(resource));
}

ensureStatusExists(resource);
resource.getStatus().setUpdated(true);
return UpdateControl.patchStatus(resource);
}

private static ConfigMap prepareCM(CachingFilteringUpdateCustomResource p) {
private static ConfigMap prepareCM(CachingFilteringUpdateCustomResource p, int num) {
var cm =
new ConfigMapBuilder()
.withMetadata(
new ObjectMetaBuilder()
.withName(p.getMetadata().getName())
.withNamespace(p.getMetadata().getNamespace())
.build())
.withData(Map.of("name", p.getMetadata().getName()))
.withData(Map.of("name", p.getMetadata().getName(), "num", "" + num))
.build();
cm.addOwnerReference(p);
return cm;
Expand Down
Loading