question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Double generation from CRD to Java and back to CRD

See original GitHub issue

Describe the bug

I have the use case that I need to both generate CDR from Java, as well as generating Java from CDR. So I have both the annotation processor and maven plugin configured.

From what I can see, the maven plugin runs first and it generates Java code, and then the annotation processor kicks in, which totally makes sense because before compilation code needs to be generated.

The result is a roundtrip happens for the CDR and I get the generated one under /META-INF/fabric8 along with the original one in a different place. This is not a real problem, but could be confusing.

Fabric8 Kubernetes Client version

6.0.0

Steps to reproduce

Configure annotation processor

    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>crd-generator-apt</artifactId>
      <scope>provided</scope>
    </dependency>

Configure maven plugin

      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>java-generator-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <source>src/main/resources/kubernetes/crds</source>
        </configuration>
      </plugin>

Compile

mvn compile

Expected behavior

Maybe there is a way to configure the annotation processor to skip generated code that I’m not aware of. The expected behaviour is not to generate CDR form generated code.

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.24.2@latest

Environment

macOS

Fabric8 Kubernetes Client Logs

NA

Additional context

For a reason I have to use 5.12.3 annotation processor, but 6.0.0 maven plugin. Not sure whether that matters.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
honnixcommented, Aug 26, 2022

I guess, better to have some identity so it won’t skip other generated files, @Generated(value="io.facric8....").

0reactions
andreaTPcommented, Aug 26, 2022

I checked and there is, at the moment, no easy way to disable the CRD generator on a particular CRD and the separation @manusa suggested is the only viable option.

That said I’m all in for adding javax.annotation.processing.Generated which is indeed good practice, thanks for the suggestion @honnix 👍 .

The only suggestion(if it’s not me going to implement it) is to make it configurable (even a hidden configuration is fine) to not prevent testing the two generators as we are doing in the it tests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java-model-gen generates CRD that imports non-exist class
import io.kubernetes.client.models.IoK8sApimachineryPkgApisMetaV1ObjectMeta;. Actually, should I just replace it with the following? import io.
Read more >
Use design by contract to build Kubernetes Operators in Java
This article explains how to create a CRD and Operator in Java, complete with sample Java code and YAML specification files. We'll use...
Read more >
CRD creation with java-client for Kubernetes - Stack Overflow
IS it possible to create custom resource definition by reading the data from yaml file and using Java client for Kubernetes?
Read more >
How to generate client codes for Kubernetes Custom ... - ITNEXT
To generate this CRD resource codes, there are two steps involved. Write the type definition codes with proper code generator tags; Run the...
Read more >
Versions in CustomResourceDefinitions - Kubernetes
It is recommended to run this tutorial on a cluster with at least two nodes that ... If this occurs, switch back to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found