Skip to content

External DependentResource with Updater cannot check if desired and actual match #2128

Closed
@BramMeerten

Description

@BramMeerten

If I have an dependentResource that extends from AbstractExternalDependentResource, but also from Updater, then the update will never be called when the Primary resource is updated. This is caused by a problem with the match method.

For example this dependent resource:

public class ExternalUserDependentResource
        extends PerResourcePollingDependentResource<ExternalUser, MyPrimary>
        implements Creator<ExternalUser, MyPrimary>, 
                             Deleter<MyPrimary>, 
                             Updater<ExternalUser, MyPrimary> {
    // ... 
    @Override
    protected ExternalUser desired(MyPrimary primary, Context<MyPrimary> context) {
        return new ExternalUser(primary.getSpec().username());
    }

    @Override
    public ExternalUser create(ExternalUser desired, MyPrimary primary, Context<Prim> context) {
        externalSystem.create(desired.username());
        return desired;
    }

    @Override
    public ExternalUser update(ExternalUser actual, ExternalUser desired, MyPrimary primary, Context<MyPrimary> context) {
        externalSystem.update(desired.username());
        return desired;
    }

    @Override
    public Set<ExternalUser> fetchResources(MyPrimary primary) {
        return externalSystem
               .findUsers(primary.getSpec().username())
               .map(u -> new ExternalUser(u.username())
               .collect(toSet());
    }
}

This is caused by a method call to match that keeps calling itself:

  1. AbstractDependentResource::match is called:
public Result<R> match(R resource, P primary, Context<P> context) {
    return updater.match(resource, primary, context);
}
  1. It calls the match method on the field updater, but this is the same dependent resource (ExternalUserDependentResource in my example):
protected AbstractDependentResource() {
    creator = creatable ? (Creator<R, P>) this : null;
    updater = updatable ? (Updater<R, P>) this : null;
  1. Stuck in a loop

Workaround:
Override match in the dependent resource and do the check yourself.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions