Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #2561 is broken #2658

Open
tombentley opened this issue Jan 6, 2025 · 0 comments · May be fixed by #2662
Open

Fix for #2561 is broken #2658

tombentley opened this issue Jan 6, 2025 · 0 comments · May be fixed by #2662
Assignees
Milestone

Comments

@tombentley
Copy link

Bug Report

What did you do?

I finally got round to trying to use the new API introduced to address #2561 for real yesterday. Sorry it has taken so long. Sadly, it seems there's a bug.

What did you expect to see?

I expected the CRD to be loaded from the file specified via the new withAdditionalCRD() method

What did you see instead? Under which circumstances?

The file is not loaded and I got an IllegalStateException, exactly as before. For example:

java.lang.IllegalStateException: Cannot apply CRD yaml: /META-INF/fabric8/tests.crd.example-v1.yml

	at io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension.applyCrd(LocallyRunOperatorExtension.java:143)
	at io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension.applyCrd(LocallyRunOperatorExtension.java:115)
	at io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension.applyCrd(LocallyRunOperatorExtension.java:270)
	at io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension.before(LocallyRunOperatorExtension.java:231)
	at io.javaoperatorsdk.operator.junit.AbstractOperatorExtension.beforeEachImpl(AbstractOperatorExtension.java:133)
	at io.javaoperatorsdk.operator.junit.AbstractOperatorExtension.beforeEach(AbstractOperatorExtension.java:79)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.IllegalStateException: Cannot find CRD at /META-INF/fabric8/tests.crd.example-v1.yml
	at io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension.applyCrd(LocallyRunOperatorExtension.java:131)
	... 7 more

Additional context

Taking a closer look at the code on main I found the test io.javaoperatorsdk.operator.CRDMappingInTestExtensionIT initially failed in the same way as my usage when I ran it in the IDE. When I then compiled with maven it worked. That's because the CRDMappingInTestExtensionIT.TestCR is being picked up by the Fabric8 crd-generator-maven-plugin, which generates a CRD and puts it in target/classes/META-INF/fabric8/tests.crd.example-v1.yml. It's that file which is picked up by LocallyRunOperatorExtension.applyCrd(), the one passed via LocallyRunOperatorExtension.withAdditionalCRD("src/test/resources/crd/test.crd") is basically ignored.

The other way you can tell there's a problem is that the only caller of private static void applyCrd(InputStream is, String path, KubernetesClient client) is public static void applyCrd(String resourceTypeName, KubernetesClient client), which hard codes the path to use as String path = "/META-INF/fabric8/" + resourceTypeName + "-v1.yml";. In other words, the LocallyRunOperatorExtension is still making the same assumption as it was when #2561 was originally raised.

@csviri csviri added this to the 5.0 milestone Jan 7, 2025
@metacosm metacosm self-assigned this Jan 7, 2025
metacosm added a commit that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants