Skip to content

Commit 679ffb4

Browse files
committed
fix IT
Signed-off-by: Attila Mészáros <csviri@gmail.com>
1 parent ce21662 commit 679ffb4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,26 @@ public ExternalWithStateDependentResource() {
3434
@SuppressWarnings("unchecked")
3535
public Set<ExternalResource> fetchResources(
3636
ExternalStateCustomResource primaryResource) {
37-
Optional<ConfigMap> configMapOptional =
38-
getExternalStateEventSource().getSecondaryResource(primaryResource);
39-
40-
return configMapOptional.map(configMap -> {
41-
var id = configMap.getData().get(ID_KEY);
37+
return getResourceID(primaryResource).map(id -> {
4238
var externalResource = externalService.read(id);
4339
return externalResource.map(Set::of).orElseGet(Collections::emptySet);
4440
}).orElseGet(Collections::emptySet);
4541
}
4642

43+
@Override
44+
protected Optional<ExternalResource> selectManagedSecondaryResource(
45+
Set<ExternalResource> secondaryResources,
46+
ExternalStateCustomResource primary, Context<ExternalStateCustomResource> context) {
47+
var id = getResourceID(primary);
48+
return id.flatMap(k -> secondaryResources.stream().filter(e -> e.getId().equals(k)).findAny());
49+
}
50+
51+
private Optional<String> getResourceID(ExternalStateCustomResource primaryResource) {
52+
Optional<ConfigMap> configMapOptional =
53+
getExternalStateEventSource().getSecondaryResource(primaryResource);
54+
return configMapOptional.map(cm -> cm.getData().get(ID_KEY));
55+
}
56+
4757
@Override
4858
protected ExternalResource desired(ExternalStateCustomResource primary,
4959
Context<ExternalStateCustomResource> context) {

0 commit comments

Comments
 (0)