5
5
import org .slf4j .Logger ;
6
6
import org .slf4j .LoggerFactory ;
7
7
8
+ import io .fabric8 .kubernetes .api .model .HasMetadata ;
8
9
import io .javaoperatorsdk .operator .health .EventSourceHealthIndicator ;
9
10
import io .javaoperatorsdk .operator .health .InformerWrappingEventSourceHealthIndicator ;
10
11
import io .javaoperatorsdk .operator .processing .event .source .controller .ControllerEventSource ;
@@ -22,14 +23,15 @@ public class RuntimeInfo {
22
23
private final Operator operator ;
23
24
24
25
public RuntimeInfo (Operator operator ) {
25
- this .registeredControllers = operator .getRegisteredControllers ();
26
+ this .registeredControllers = Collections . unmodifiableSet ( operator .getRegisteredControllers () );
26
27
this .operator = operator ;
27
28
}
28
29
29
30
public boolean isStarted () {
30
31
return operator .isStarted ();
31
32
}
32
33
34
+ @ SuppressWarnings ("unused" )
33
35
public Set <RegisteredController > getRegisteredControllers () {
34
36
checkIfStarted ();
35
37
return registeredControllers ;
@@ -80,4 +82,23 @@ public Map<String, Map<String, EventSourceHealthIndicator>> unhealthyEventSource
80
82
}
81
83
return res ;
82
84
}
85
+
86
+ /**
87
+ * Retrieves the {@link RegisteredController} associated with the specified controller name or
88
+ * {@code null} if no such controller is registered.
89
+ *
90
+ * @param controllerName the name of the {@link RegisteredController} to retrieve
91
+ * @return the {@link RegisteredController} associated with the specified controller name or
92
+ * {@code null} if no such controller is registered
93
+ * @since 5.1.2
94
+ */
95
+ @ SuppressWarnings ({"unchecked" , "unused" })
96
+ public RegisteredController <? extends HasMetadata > getRegisteredController (
97
+ String controllerName ) {
98
+ checkIfStarted ();
99
+ return registeredControllers .stream ()
100
+ .filter (rc -> rc .getConfiguration ().getName ().equals (controllerName ))
101
+ .findFirst ()
102
+ .orElse (null );
103
+ }
83
104
}
0 commit comments