Skip to content

CRD Generator maven plugin fails to detect CustomResources that are located in test sourcesΒ #6683

@metacosm

Description

@metacosm

Describe the bug

I have tests that rely on being able to deploy the CRD associated with test custom resources. However, this currently doesn't work with the maven plugin. I've tried to use the

<configuration>
    <classpath>WITH_ALL_DEPENDENCIES_AND_TESTS</classpath>
</configuration>

configuration option but this didn't change anything. Looking at the code of the plugin, it seems as if the classpath only takes effect for loading the custom resource classes, not when indexing, which means that the classes are never detected. I've tried to change the plugin code but the tests are now failing in an obscure way and that's about as far as I got tonight πŸ˜…

That's the modification I made:

 public CustomResourceCollector withClasspathElements(Collection<String> classpathElements) {
    if (classpathElements != null) {
      withFilesToScan(classpathElements.stream()
        .map(File::new)
        .filter(File::exists)
        .collect(Collectors.toList()));
    }
    this.customResourceClassLoader.withClasspathElements(classpathElements);
    return this;
  }

the idea being that if a user wants to change the lookup classpath, then the corresponding elements should probably also be indexed.

This actually raises another issue (for which I might create a separate ticket but still mentioning it here): we need another scope that includes only the runtime and test scopes instead of forcing everything just to get the test scope.

/cc @baloo42

Fabric8 Kubernetes Client version

SNAPSHOT

Steps to reproduce

You can see an example of the failure at operator-framework/java-operator-sdk#2540

Expected behavior

CRDs should also be generated for test classes if requested (and it should be easy to configure the plugin to also consider test classes).

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

next (development version)

Environment

macOS

Fabric8 Kubernetes Client Logs

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions