Skip to content
Merged
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,8 +191,8 @@ 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(
Expand All @@ -201,13 +201,16 @@ public Optional<R> get(ResourceID resourceID) {
> 0) {
log.debug("Latest resource found in temporary cache for Resource ID: {}", resourceID);
return resource;
} else {
// this needs to happen after comparison to ensure correctness
var resFromInformer = cache.get(resourceID);
log.debug(
"Resource {} in temp cache; {}found in informer cache" + ", for Resource ID: {}",
resource.isPresent() ? "obsolete" : "not found",
resFromInformer.isPresent() ? "" : "not ",
resourceID);
return resFromInformer;
}
log.debug(
"Resource not found, or older, in temporary cache. Found in informer cache {}, for"
+ " Resource ID: {}",
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()
.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