Skip to content

[operator] Cannot customize TheiaCloudClient due to overriding restrictions in Guice #489

Description

@kittaakos

Describe the bug

Follow-up of #433 that has been closed without any resolution.

From #433 (comment):

Describe the bug

The current design of AbstractTheiaCloudOperatorModule in Theia Cloud does not support customization of certain dependencies, particularly when attempting to override @Provides methods using Modules.override.

Our use case:

When we enable the activity-tracker, additional logic in TheiaCloudClient (such as calls to getClusterIPFromSessionName) is triggered. To inspect (errors like No ClusterIP found for session) and enhance this behavior, we subclass TheiaCloudClient and want to inject our custom version.

However, the framework defines a @Provides method like the following:

@provides
@singleton
protected TheiaCloudClient provideTheiaCloudClient(NamespacedKubernetesClient client) {
return new DefaultTheiaCloudClient(client);
}

Problem 1: Overriding the provider method directly causes a runtime error

@OverRide
protected TheiaCloudClient provideTheiaCloudClient(NamespacedKubernetesClient client) {
return new MyTheiaCloudClient(client);
}
Results in:

Overriding @Provides methods is not allowed.
    @Provides method: AbstractTheiaCloudOperatorModule.provideTheiaCloudClient()
    overridden by: MyOperatorModule.provideTheiaCloudClient()

Problem 2: Defining a second provider method causes a binding conflict

@provides
@singleton
protected TheiaCloudClient provideCustomTheiaCloudClient(NamespacedKubernetesClient client) {
return new MyTheiaCloudClient(client);
}
Produces:

[Guice/BindingAlreadySet]: TheiaCloudClient was bound multiple times.
Bound at:
1  : MyMonitorMessagingServiceTest$1.configure(MyMonitorMessagingServiceTest.java:91)
    \_ installed by: Modules$OverrideModule -> MyMonitorMessagingServiceTest$1
2  : AbstractTheiaCloudOperatorModule.provideTheiaCloudClient(AbstractTheiaCloudOperatorModule.java:165)
    \_ installed by: Modules$OverrideModule -> MyOperatorModule

Problem 3: Modules.override(...) cannot return an AbstractTheiaCloudOperatorModule type

Attempting to override with:

@OverRide
public AbstractTheiaCloudOperatorModule createModule(TheiaCloudOperatorArguments arguments) {
return Modules.override(new MyOperatorModule(arguments)).with(new AbstractModule() {
@OverRide
protected void configure() {
// attempt to customize the provider
}
});
}
...fails at compile time because Modules.override(...) returns only a Module, not an AbstractTheiaCloudOperatorModule.

This restriction exists even though the launcher does not use the specific API of AbstractTheiaCloudOperatorModule. The type is only passed to Guice as a module:

protected void startOperatorAsLeader(TheiaCloudOperatorArguments arguments) {
AbstractTheiaCloudOperatorModule module = this.createModule(arguments);
Injector injector = Guice.createInjector(module);
TheiaCloudOperator theiaCloud = injector.getInstance(TheiaCloudOperator.class);
theiaCloud.start();
}
Maybe I am doing something wrong. What is the correct way of customizing the default Theia Cloud client? Thank you!

Expected behavior

The framework provides a way to customize the operator.

Cluster provider

No response

Version

No response

Additional information

Related #426 (comment)

I am new to this API, but I do not understand why getting the IP requires a new client creation when it is already set at the constructor of the default implementation:

theia-cloud/java/common/org.eclipse.theia.cloud.common/src/main/java/org/eclipse/theia/cloud/common/k8s/client/TheiaCloudClient.java

Line 81 in 55813e2

try (final KubernetesClient client = new KubernetesClientBuilder().build()) {
theia-cloud/java/common/org.eclipse.theia.cloud.common/src/main/java/org/eclipse/theia/cloud/common/k8s/client/DefaultTheiaCloudClient.java

Lines 28 to 31 in 55813e2

public DefaultTheiaCloudClient(Client client) {
super(client.adapt(KubernetesClientImpl.class));
this.client = client.adapt(NamespacedKubernetesClient.class);
}

Expected behavior

The framework provides a way to customize the operator.

Cluster provider

No response

Version

No response

Additional information

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions