Skip to content

Question & Opinion) ResourceController's init(EventSourceManager) method feels a bit vague. #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
snowdrop-bot opened this issue Oct 21, 2021 · 0 comments

Comments

@snowdrop-bot
Copy link

HI, all
I was wondering how to register eventSource in Controller, so I looked at the code.

https://github.com/java-operator-sdk/java-operator-sdk/blob/2e8f219437e53b9ca58f146a24397dbf38f0bfb8/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ResourceController.java#L55

Looking at this method, it looks like I can create and use my own EventSourceManager.

However, in reality, when operator.start() starts, DefaultEventSourceManager is unconditionally injected in configuredController.
(https://github.com/java-operator-sdk/java-operator-sdk/blob/2e8f219437e53b9ca58f146a24397dbf38f0bfb8/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/ConfiguredController.java#L178-L179)

And actually, the user should directly register the EventSource that the user wants to register with the EventSourceManager inside the init method.
like this

  @Override
  public void init(EventSourceManager eventSourceManager) {
    ...
    eventSourceManager.registerEventSource(eventSource);
  }

Personally, I think this might be a bit ambiguous.
It feels like the user can directly inject and use CustomEventSourceManager .

If that's not what you intended, Rather, I think the interface below would be a little clearer.

public interface ResourceController<R extends CustomResource> {
 ...
  default List<EventSource> registerEventSources() {
    return List.of();
  }
}

And by calling this method in the framework, it will be able to directly register it with the event source manager.

Since EventSourceManager is an important component in the framework, it seems to be able to prevent it from being directly exposed to users.

This is just my personal opinion.
Thank you for reading this question :)


operator-framework#615


$upstream:615$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants