|
1 | 1 | package io.javaoperatorsdk.operator;
|
2 | 2 |
|
| 3 | +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; |
3 | 4 | import io.fabric8.kubernetes.client.CustomResource;
|
4 | 5 | import io.fabric8.kubernetes.client.KubernetesClient;
|
5 | 6 | import io.fabric8.kubernetes.client.Version;
|
@@ -96,23 +97,26 @@ public <R extends CustomResource> void register(
|
96 | 97 | Class<R> resClass = configuration.getCustomResourceClass();
|
97 | 98 | String finalizer = configuration.getFinalizer();
|
98 | 99 |
|
99 |
| - // check that the custom resource is known by the cluster |
100 |
| - final var crdName = configuration.getCRDName(); |
101 |
| - final var crd = |
102 |
| - k8sClient.apiextensions().v1().customResourceDefinitions().withName(crdName).get(); |
103 |
| - final var controllerName = configuration.getName(); |
104 |
| - if (crd == null) { |
105 |
| - throw new OperatorException( |
106 |
| - "'" |
107 |
| - + crdName |
108 |
| - + "' CRD was not found on the cluster, controller " |
109 |
| - + controllerName |
110 |
| - + " cannot be registered"); |
| 100 | + final String controllerName = configuration.getName(); |
| 101 | + |
| 102 | + // check that the custom resource is known by the cluster if configured that way |
| 103 | + final CustomResourceDefinition crd; |
| 104 | + if (configurationService.validateCustomResources()) { |
| 105 | + final var crdName = configuration.getCRDName(); |
| 106 | + crd = k8sClient.apiextensions().v1().customResourceDefinitions().withName(crdName).get(); |
| 107 | + if (crd == null) { |
| 108 | + throw new OperatorException( |
| 109 | + "'" |
| 110 | + + crdName |
| 111 | + + "' CRD was not found on the cluster, controller " |
| 112 | + + controllerName |
| 113 | + + " cannot be registered"); |
| 114 | + } |
| 115 | + |
| 116 | + // Apply validations that are not handled by fabric8 |
| 117 | + CustomResourceUtils.assertCustomResource(resClass, crd); |
111 | 118 | }
|
112 | 119 |
|
113 |
| - // Apply validations that are not handled by fabric8 |
114 |
| - CustomResourceUtils.assertCustomResource(resClass, crd); |
115 |
| - |
116 | 120 | final var client = k8sClient.customResources(resClass);
|
117 | 121 | EventDispatcher dispatcher =
|
118 | 122 | new EventDispatcher(
|
|
0 commit comments