Search in sources :

Example 1 with MissingCRDException

use of io.javaoperatorsdk.operator.MissingCRDException 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);
    }
}
Also used : EventSourceInitializer(io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer) MissingCRDException(io.javaoperatorsdk.operator.MissingCRDException) EventSourceContext(io.javaoperatorsdk.operator.api.reconciler.EventSourceContext) CustomResource(io.fabric8.kubernetes.client.CustomResource) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)

Example 2 with MissingCRDException

use of io.javaoperatorsdk.operator.MissingCRDException in project java-operator-sdk by java-operator-sdk.

the class EventSourceManager method registerEventSource.

public final void registerEventSource(EventSource eventSource) throws OperatorException {
    Objects.requireNonNull(eventSource, "EventSource must not be null");
    lock.lock();
    try {
        eventSources.add(eventSource);
        eventSource.setEventHandler(eventProcessor);
    } catch (Throwable e) {
        if (e instanceof IllegalStateException || e instanceof MissingCRDException) {
            // leave untouched
            throw e;
        }
        throw new OperatorException("Couldn't register event source: " + eventSource.getClass().getName(), e);
    } finally {
        lock.unlock();
    }
}
Also used : MissingCRDException(io.javaoperatorsdk.operator.MissingCRDException) OperatorException(io.javaoperatorsdk.operator.OperatorException)

Aggregations

MissingCRDException (io.javaoperatorsdk.operator.MissingCRDException)2 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)1 CustomResource (io.fabric8.kubernetes.client.CustomResource)1 OperatorException (io.javaoperatorsdk.operator.OperatorException)1 EventSourceContext (io.javaoperatorsdk.operator.api.reconciler.EventSourceContext)1 EventSourceInitializer (io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer)1