8000 feat: throw an explicit exception if CRD is not found · r00ta/java-operator-sdk@6cde0be · GitHub
[go: up one dir, main page]

Skip to content

Commit 6cde0be

Browse files
committed
feat: throw an explicit exception if CRD is not found
Fail fast when the CRD is not found instead of letting watchers throw a cryptic exception based on PR discussion. Fixes operator-framework#315
1 parent 09ce889 commit 6cde0be

File tree

1 file changed

+10
-14
lines changed
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator

1 file changed

+10
-14
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void start() {
4646
* Registers the specified controller with this operator.
4747
*
4848
* @param controller the controller to register
49-
* @param <R> the {@code CustomResource} type associated with the controller
49+
* @param <R> the {@code CustomResource} type associated with the controller
5050
* @throws OperatorException if a problem occurred during the registration process
5151
*/
5252
public <R extends CustomResource> void register(ResourceController<R> controller)
@@ -56,14 +56,13 @@ public <R extends CustomResource> void register(ResourceController<R> controller
5656

5757
/**
5858
* Registers the specified controller with this operator, overriding its default configuration by
59-
* the specified one (usually created via {@link
60-
* io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)},
59+
* the specified one (usually created via {@link io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)},
6160
* passing it the controller's original configuration.
6261
*
63-
* @param controller the controller to register
62+
* @param controller the controller to register
6463
* @param configuration the configuration with which we want to register the controller, if {@code
65-
* null}, the controller's orginal configuration is used
66-
* @param <R> the {@code CustomResource} type associated with the controller
64+
* null}, the controller's orginal configuration is used
65+
* @param <R> the {@code CustomResource} type associated with the controller
6766
* @throws OperatorException if a problem occurred during the registration process
6867
*/
6968
public <R extends CustomResource> void register(
@@ -83,7 +82,7 @@ public <R extends CustomResource> void register(
8382
}
8483

8584
final var retry = GenericRetry.fromConfiguration(configuration.getRetryConfiguration());
86-
final var targetNamespaces = configuration.getNamespaces().toArray(new String[] {});
85+
final var targetNamespaces = configuration.getNamespaces().toArray(new String[]{});
8786
Class<R> resClass = configuration.getCustomResourceClass();
8887
String finalizer = configuration.getFinalizer();
8988
final var client = k8sClient.customResources(resClass);
@@ -97,12 +96,9 @@ public <R extends CustomResource> void register(
9796
k8sClient.apiextensions().v1().customResourceDefinitions().withName(crdName).get();
9897
final var controllerName = configuration.getName();
9998
if (crd == null) {
100-
log.warn(
101-
"'{}' CRD was not found on the {} cluster, skipping '{}' controller registration",
102-
crdName,
103-
configurationService.getClientConfiguration().getMasterUrl(),
104-
controllerName);
105-
return;
99+
throw new OperatorException(
100+
"'" + crdName + "' CRD was not found on the cluster, controller "
101+
+ controllerName + " cannot be registered");
106102
}
107103

108104
CustomResourceCache customResourceCache = new CustomResourceCache();
@@ -145,7 +141,7 @@ private CustomResourceEventSource createCustomResourceEventSource(
145141
CustomResourceEventSource customResourceEventSource =
146142
watchAllNamespaces
147143
? CustomResourceEventSource.customResourceEventSourceForAllNamespaces(
148-
customResourceCache, client, generationAware, finalizer)
144+
customResourceCache, client, generationAware, finalizer)
149145
: CustomResourceEventSource.customResourceEventSourceForTargetNamespaces(
150146
customResourceCache, client, targetNamespaces, generationAware, finalizer);
151147

0 commit comments

Comments
 (0)
0