diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java index da408322f1..5cf191edab 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java @@ -62,17 +62,9 @@ public boolean equals(Object o) { return Objects.equals(name, that.name) && Objects.equals(namespace, that.namespace); } - public boolean isSameResource(HasMetadata hasMetadata) { - if (hasMetadata == null) { - return false; - } - final var metadata = hasMetadata.getMetadata(); - return isSameResource(metadata.getName(), metadata.getNamespace()); - } - /** - * Whether this ResourceID points to the same resource as the one identified by the specified name - * and namespace. + * Whether this ResourceID points to the same resource as the one identified only by the specified + * name and namespace. * *

Note that this doesn't take API version or Kind into account so this should only be used * when checking resources that are reasonably expected to be of the same type. @@ -83,7 +75,7 @@ public boolean isSameResource(HasMetadata hasMetadata) { * specified name and namespace, {@code false} otherwise * @since 5.3.0 */ - public boolean isSameResource(String name, String namespace) { + public boolean equals(String name, String namespace) { return Objects.equals(this.name, name) && Objects.equals(this.namespace, namespace); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java index 4df8df385b..5c4af25b21 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java @@ -95,7 +95,7 @@ void latestDistinctKeepsOnlyLatestResourceVersion() { // Find pod1 in default namespace - should have version 200 final var pod1InDefault = result.stream() - .filter(r -> ResourceID.fromResource(r).isSameResource("pod1", "default")) + .filter(r -> ResourceID.fromResource(r).equals(new ResourceID("pod1", "default"))) .findFirst() .orElseThrow(); assertThat(pod1InDefault.getMetadata().getResourceVersion()).isEqualTo("200"); @@ -103,7 +103,7 @@ void latestDistinctKeepsOnlyLatestResourceVersion() { // Find pod2 in default namespace - should exist HasMetadata pod2InDefault = result.stream() - .filter(r -> ResourceID.fromResource(r).isSameResource("pod2", "default")) + .filter(r -> ResourceID.fromResource(r).equals("pod2", "default")) .findFirst() .orElseThrow(); assertThat(pod2InDefault.getMetadata().getResourceVersion()).isEqualTo("100"); @@ -111,7 +111,7 @@ void latestDistinctKeepsOnlyLatestResourceVersion() { // Find pod1 in other namespace - should exist HasMetadata pod1InOther = result.stream() - .filter(r -> ResourceID.fromResource(r).isSameResource("pod1", "other")) + .filter(r -> ResourceID.fromResource(r).equals("pod1", "other")) .findFirst() .orElseThrow(); assertThat(pod1InOther.getMetadata().getResourceVersion()).isEqualTo("50");