use of io.javaoperatorsdk.operator.api.reconciler.EventSourceContext in project java-operator-sdk by java-operator-sdk.
the class Controller method start.
/**
* Registers the specified controller with this operator, overriding its default configuration by
* the specified one (usually created via
* {@link io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)},
* passing it the controller's original configuration.
*
* @throws OperatorException if a problem occurred during the registration process
*/
public void start() throws OperatorException {
final Class<R> resClass = configuration.getResourceClass();
final String controllerName = configuration.getName();
final var crdName = configuration.getResourceTypeName();
final var specVersion = "v1";
// fail early if we're missing the current namespace information
failOnMissingCurrentNS();
try {
// check that the custom resource is known by the cluster if configured that way
// todo: check proper CRD spec version based on config
final CustomResourceDefinition crd;
if (configurationService().checkCRDAndValidateLocalModel() && CustomResource.class.isAssignableFrom(resClass)) {
crd = kubernetesClient.apiextensions().v1().customResourceDefinitions().withName(crdName).get();
if (crd == null) {
throwMissingCRDException(crdName, specVersion, controllerName);
}
// Apply validations that are not handled by fabric8
CustomResourceUtils.assertCustomResource(resClass, crd);
}
eventSourceManager = new EventSourceManager<>(this);
if (reconciler instanceof EventSourceInitializer) {
((EventSourceInitializer<R>) reconciler).prepareEventSources(new EventSourceContext<>(eventSourceManager.getControllerResourceEventSource(), configurationService(), kubernetesClient)).forEach(eventSourceManager::registerEventSource);
}
eventSourceManager.start();
} catch (MissingCRDException e) {
throwMissingCRDException(crdName, specVersion, controllerName);
}
}
Aggregations