Skip to content

Commit 43a1a90

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent c44e0c6 commit 43a1a90

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cachingfilteringupdate/CachingFilteringUpdateReconciler.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,40 @@ public class CachingFilteringUpdateReconciler
3939
public static final String RESOURCE_VERSION_INDEX = "resourceVersionIndex";
4040
private final AtomicBoolean issueFound = new AtomicBoolean(false);
4141

42-
InformerEventSource<ConfigMap, CachingFilteringUpdateCustomResource> configMapEventSource;
42+
private InformerEventSource<ConfigMap, CachingFilteringUpdateCustomResource> configMapEventSource;
4343

4444
@Override
4545
public UpdateControl<CachingFilteringUpdateCustomResource> reconcile(
4646
CachingFilteringUpdateCustomResource resource,
4747
Context<CachingFilteringUpdateCustomResource> context) {
48+
try {
49+
var updated = context.resourceOperations().serverSideApply(prepareCM(resource, 1));
50+
var cachedCM = context.getSecondaryResource(ConfigMap.class);
51+
if (cachedCM.isEmpty()) {
52+
throw new IllegalStateException("Error for resource: " + ResourceID.fromResource(resource));
53+
}
54+
checkListContainsCM(updated);
55+
checkIfResourceVersionIndexContainsUpdated(updated);
56+
updated = context.resourceOperations().serverSideApply(prepareCM(resource, 2));
57+
cachedCM = context.getSecondaryResource(ConfigMap.class);
58+
if (!cachedCM
59+
.orElseThrow()
60+
.getMetadata()
61+
.getResourceVersion()
62+
.equals(updated.getMetadata().getResourceVersion())) {
63+
throw new IllegalStateException(
64+
"Update error for resource: " + ResourceID.fromResource(resource));
65+
}
66+
checkListContainsCM(updated);
67+
checkIfResourceVersionIndexContainsUpdated(updated);
4868

49-
var updated = context.resourceOperations().serverSideApply(prepareCM(resource, 1));
50-
var cachedCM = context.getSecondaryResource(ConfigMap.class);
51-
if (cachedCM.isEmpty()) {
69+
ensureStatusExists(resource);
70+
resource.getStatus().setUpdated(true);
71+
return UpdateControl.patchStatus(resource);
72+
} catch (IllegalStateException e) {
5273
issueFound.set(true);
53-
throw new IllegalStateException("Error for resource: " + ResourceID.fromResource(resource));
74+
throw e;
5475
}
55-
checkListContainsCM(updated);
56-
checkIfResourceVersionIndexContainsUpdated(updated);
57-
updated = context.resourceOperations().serverSideApply(prepareCM(resource, 2));
58-
cachedCM = context.getSecondaryResource(ConfigMap.class);
59-
if (!cachedCM
60-
.orElseThrow()
61-
.getMetadata()
62-
.getResourceVersion()
63-
.equals(updated.getMetadata().getResourceVersion())) {
64-
issueFound.set(true);
65-
throw new IllegalStateException(
66-
"Update error for resource: " + ResourceID.fromResource(resource));
67-
}
68-
checkListContainsCM(updated);
69-
checkIfResourceVersionIndexContainsUpdated(updated);
70-
71-
ensureStatusExists(resource);
72-
resource.getStatus().setUpdated(true);
73-
return UpdateControl.patchStatus(resource);
7476
}
7577

7678
private void checkIfResourceVersionIndexContainsUpdated(ConfigMap updated) {

0 commit comments

Comments
 (0)