java-operator-sdk icon indicating copy to clipboard operation
java-operator-sdk copied to clipboard

Selecting secondary resources based on equals is improper

Open metacosm opened this issue 4 months ago • 1 comments

See https://github.com/quarkiverse/quarkus-operator-sdk/issues/1148#issuecomment-3221721413 for more details but the gist of it is that if a resource exists but somehow differs (based on equals) from the desired state then https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java#L140 will return an empty list when it should return the resource identified by the name and namespace at the very least because otherwise JOSDK will never get a chance to update the resource and instead always attempt to re-create it.

metacosm avatar Aug 25 '25 21:08 metacosm

The current approach assumes that use overrides the equals method: https://github.com/operator-framework/java-operator-sdk/blob/a32f4c74d1b09e6c9cde17a9e3eb486538d70d70/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/schema/Schema.java#L29

If he cannot do that still can override the selectTargetSecondaryResource: https://github.com/operator-framework/java-operator-sdk/blob/a32f4c74d1b09e6c9cde17a9e3eb486538d70d70/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java#L137

But as we discussed I also see that this could be improved, since it is easy to miss. For exmaple something like having an "ExternalResource" interface that would provide an T getId() method , where id we can compare (equals) with id of actual resources.

csviri avatar Aug 26 '25 11:08 csviri