Skip to content

Commit c5cdd55

Browse files
committed
feat: make it clearer when the CRD file isn't found (#1503)
1 parent f4be98d commit c5cdd55

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ protected void before(ExtensionContext context) {
134134
ref.controllerConfigurationOverrider.accept(oconfig);
135135
}
136136

137-
applyCrd(config.getResourceTypeName());
137+
// only try to apply a CRD for the reconciler if it is associated to a CR
138+
if (CustomResource.class.isAssignableFrom(config.getResourceClass())) {
139+
applyCrd(config.getResourceTypeName());
140+
}
138141

139142
if (ref.reconciler instanceof KubernetesClientAware) {
140143
((KubernetesClientAware) ref.reconciler).setKubernetesClient(kubernetesClient);
@@ -151,6 +154,9 @@ protected void before(ExtensionContext context) {
151154
private void applyCrd(String resourceTypeName) {
152155
String path = "/META-INF/fabric8/" + resourceTypeName + "-v1.yml";
153156
try (InputStream is = getClass().getResourceAsStream(path)) {
157+
if (is == null) {
158+
throw new IllegalStateException("Cannot find CRD at " + path);
159+
}
154160
final var crd = getKubernetesClient().load(is);
155161
crd.createOrReplace();
156162
Thread.sleep(CRD_READY_WAIT); // readiness is not applicable for CRD, just wait a little

0 commit comments

Comments
 (0)