Skip to content

feat: add retrieval of RegisteredController by name #2829

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

Merged
merged 2 commits into from
Jun 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.health.EventSourceHealthIndicator;
import io.javaoperatorsdk.operator.health.InformerWrappingEventSourceHealthIndicator;
import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource;
Expand All @@ -22,14 +23,15 @@ public class RuntimeInfo {
private final Operator operator;

public RuntimeInfo(Operator operator) {
this.registeredControllers = operator.getRegisteredControllers();
this.registeredControllers = Collections.unmodifiableSet(operator.getRegisteredControllers());
this.operator = operator;
}

public boolean isStarted() {
return operator.isStarted();
}

@SuppressWarnings("unused")
public Set<RegisteredController> getRegisteredControllers() {
checkIfStarted();
return registeredControllers;
Expand Down Expand Up @@ -80,4 +82,23 @@ public Map<String, Map<String, EventSourceHealthIndicator>> unhealthyEventSource
}
return res;
}

/**
* Retrieves the {@link RegisteredController} associated with the specified controller name or
* {@code null} if no such controller is registered.
*
* @param controllerName the name of the {@link RegisteredController} to retrieve
* @return the {@link RegisteredController} associated with the specified controller name or
* {@code null} if no such controller is registered
* @since 5.1.2
*/
@SuppressWarnings({"unchecked", "unused"})
public RegisteredController<? extends HasMetadata> getRegisteredController(
String controllerName) {
checkIfStarted();
return registeredControllers.stream()
.filter(rc -> rc.getConfiguration().getName().equals(controllerName))
.findFirst()
.orElse(null);
}
}