Skip to content

Commit b646eb5

Browse files
committed
improve: cleanup resources after test DependentResourceCrossRefIT
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 28e18f7 commit b646eb5

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package io.javaoperatorsdk.operator.baseapi.startsecondaryaccess;
2+
3+
import java.util.List;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import io.fabric8.kubernetes.api.model.ConfigMap;
9+
import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration;
10+
import io.javaoperatorsdk.operator.api.reconciler.Context;
11+
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
12+
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
13+
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
14+
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
15+
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
16+
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource;
17+
18+
import static io.javaoperatorsdk.operator.baseapi.startsecondaryaccess.StartupSecondaryAccessIT.SECONDARY_NUMBER;
19+
20+
@ControllerConfiguration
21+
public class StartupSecondaryAccessReconciler
22+
implements Reconciler<StartupSecondaryAccessCustomResource> {
23+
24+
private static final Logger log = LoggerFactory.getLogger(StartupSecondaryAccessReconciler.class);
25+
26+
public static final String LABEL_KEY = "app";
27+
public static final String LABEL_VALUE = "secondary-test";
28+
29+
private InformerEventSource<ConfigMap, StartupSecondaryAccessCustomResource> cmInformer;
30+
31+
private boolean secondaryAndCacheSameAmount = true;
32+
private boolean reconciled = false;
33+
34+
@Override
35+
public UpdateControl<StartupSecondaryAccessCustomResource> reconcile(
36+
StartupSecondaryAccessCustomResource resource,
37+
Context<StartupSecondaryAccessCustomResource> context) {
38+
39+
var secondary = context.getSecondaryResources(ConfigMap.class);
40+
var cached = cmInformer.list().toList();
41+
42+
log.info(
43+
"Secondary number: {}, cached: {}, expected: {}",
44+
secondary.size(),
45+
cached.size(),
46+
SECONDARY_NUMBER);
47+
48+
if (secondary.size() != cached.size()) {
49+
secondaryAndCacheSameAmount = false;
50+
}
51+
reconciled = true;
52+
return UpdateControl.noUpdate();
53+
}
54+
55+
@Override
56+
public List<EventSource<?, StartupSecondaryAccessCustomResource>> prepareEventSources(
57+
EventSourceContext<StartupSecondaryAccessCustomResource> context) {
58+
cmInformer =
59+
new InformerEventSource<>(
60+
InformerEventSourceConfiguration.from(
61+
ConfigMap.class, StartupSecondaryAccessCustomResource.class)
62+
.withLabelSelector(LABEL_KEY + "=" + LABEL_VALUE)
63+
.build(),
64+
context);
65+
return List.of(cmInformer);
66+
}
67+
68+
public boolean isSecondaryAndCacheSameAmount() {
69+
return secondaryAndCacheSameAmount;
70+
}
71+
72+
public boolean isReconciled() {
73+
return reconciled;
74+
}
75+
}

0 commit comments

Comments
 (0)