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

Unable to Generate List Class for CRD using java-generator-maven-plugin #5936

Open
fengyinqiao opened this issue Apr 23, 2024 · 7 comments
Open

Comments

@fengyinqiao
Copy link

Describe the bug

Hello,

I'm using the Fabric8 Kubernetes Client (version 6.12.0) to automatically generate Java classes from a CRD. The generation process successfully creates the individual resource class (ElasticSearch.class), but it does not generate the corresponding list class (ElasticSearchList.class).

Environment

  • MacOS 13.5
  • Java Version: 17
  • Kubernetes Version: 1.20
  • Fabric8 Kubernetes Client Version: 6.12.0

Issue Description

When I run the Maven generation plugin (java-generator-maven-plugin), it only generates the ElasticSearch.class and not the ElasticSearchList.class. My Maven plugin configuration is as follows:

<!-- Maven plugin configuration here -->
<plugin>
      <groupId>io.fabric8</groupId>
      <artifactId>java-generator-maven-plugin</artifactId>
      <version>6.12.0</version>
      <executions>
	      <execution>
		      <goals>
			      <goal>generate</goal>
		      </goals>
		      <configuration>
			      <source>src/main/resources/kubernetes</source>
			      <alwaysPreserveUnknown>true</alwaysPreserveUnknown>
		      </configuration>
	      </execution>
      </executions>
</plugin>

Fabric8 Kubernetes Client version

6.12.1

Steps to reproduce

  1. Configure the Maven plugin as shown above.
  2. Run the Maven generation command.
  3. Observe that only ElasticSearch.class is generated, not ElasticSearchList.class.

Expected behavior

generates both the ElasticSearch.class and the ElasticSearchList.class

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

other (please specify in additional context)

Environment

macOS

Fabric8 Kubernetes Client Logs

No response

Additional context

No response

@manusa
Copy link
Member

manusa commented Apr 23, 2024

AFAIR we no longer generate Kubernetes Resource List objects.

You should reuse DefaultKubernetesResourceList-> io.fabric8.kubernetes.api.model.KubernetesList and the associated builder if needed.

/cc @shawkins @andreaTP

@fengyinqiao
Copy link
Author

Can you give an example? @manusa thanks!

@rohanKanojia
Copy link
Member

rohanKanojia commented Apr 23, 2024

@fengyinqiao : Could you please check if this helps?

MixedOperation<CronTab, KubernetesResourceList<CronTab>, Resource<CronTab>> cronTabClient = client
.resources(CronTab.class);
cronTabClient.inNamespace("test-ns").create(cronTab1);
cronTabClient.inNamespace("test-ns").create(cronTab2);
cronTabClient.inNamespace("test-ns").create(cronTab3);
KubernetesResourceList<CronTab> cronTabList = cronTabClient.inNamespace("test-ns").list();
assertNotNull(cronTabList);
assertEquals(3, cronTabList.getItems().size());

@manusa
Copy link
Member

manusa commented Apr 23, 2024

new KubernetesListBuilder()
  .addToItems(new ElasticSearchBuilder()
    // ....
    .build())
  .build()
KubernetesResourceList<ElasticSearch> res = client.resources(ElasticSearch.class).list();

@fengyinqiao
Copy link
Author

@fengyinqiao : Could you please check if this helps?

MixedOperation<CronTab, KubernetesResourceList<CronTab>, Resource<CronTab>> cronTabClient = client
.resources(CronTab.class);
cronTabClient.inNamespace("test-ns").create(cronTab1);
cronTabClient.inNamespace("test-ns").create(cronTab2);
cronTabClient.inNamespace("test-ns").create(cronTab3);
KubernetesResourceList<CronTab> cronTabList = cronTabClient.inNamespace("test-ns").list();
assertNotNull(cronTabList);
assertEquals(3, cronTabList.getItems().size());

It does help, but is cronTabClient singleton? Whether I can use it globally after initialization, whether it has a race mode that can be used concurrently? @rohanKanojia thanks!

@andreaTP
Copy link
Member

From the java-generator I think we never generated the "Kubernetes Resource List".

This should be sufficient for all the use-cases I'm aware of: client.resources(ElasticSearch.class)

@fengyinqiao what are you trying to achieve?

@fengyinqiao
Copy link
Author

fengyinqiao commented Apr 23, 2024

From the java-generator I think we never generated the "Kubernetes Resource List".

This should be sufficient for all the use-cases I'm aware of: client.resources(ElasticSearch.class)

@fengyinqiao what are you trying to achieve?

I am new to fabric8-k8s-client and use client-go/controller-runtime before.

//      List<ElasticSearch> ElasticSearchs = client.resources(ElasticSearch.class, ElasticSearch List.class).inNamespace(namespace).list().getItems();
        List<ElasticSearch> ElasticSearchs = client.resources(ElasticSearch.class).inNamespace(namespace).list().getItems();

I thought there was only the first way to list CR, what‘s the difference between them? @andreaTP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants