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

CRDGenerator: Selectable fields #6392

Closed
baloo42 opened this issue Sep 30, 2024 · 5 comments · Fixed by #6540
Closed

CRDGenerator: Selectable fields #6392

baloo42 opened this issue Sep 30, 2024 · 5 comments · Fixed by #6540
Labels
component/crd-generator Related to the CRD generator enhancement
Milestone

Comments

@baloo42
Copy link
Contributor

baloo42 commented Sep 30, 2024

Is your enhancement related to a problem? Please describe

CRD-Generator should support selectable fields:

https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#crd-selectable-fields

Describe the solution you'd like

CRD-Generator should support it similar to @AdditionalPrinterColumn / @PrinterColumn

Annotations:

/**
 * Marks a field as selectable.
 *
 * @see <a href=
 *      "https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-selectors">Kubernetes
 *      Docs - Field Selectors</a>
 */
@Target({ ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface SelectableField {
}
/**
 * Defines a selectable field. Must be placed at the root of the
 * custom resource.
 *
 * @see <a href=
 *      "https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-selectors">Kubernetes
 *      Docs - Field Selectors</a>
 */
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(AdditionalSelectableField.List.class)
public @interface AdditionalSelectableField {

  /**
   * The JSON Path to the field.
   *
   * @return the JSON path
   */
  String jsonPath();

  @Retention(RetentionPolicy.RUNTIME)
  @Target(ElementType.TYPE)
  @interface List {
    AdditionalSelectableField[] value();
  }
}

Describe alternatives you've considered

No response

Additional context

Example Approval Test:

https://github.com/baloo42/crd-generator-victools/tree/main/test/src/test/java/io/fabric8/crd/generator/victools/approvaltests/selectablefield
https://github.com/baloo42/crd-generator-victools/blob/main/test/src/test/resources/io/fabric8/crd/generator/victools/approvaltests/CRDGeneratorVictoolsApprovalTest.approvalTest.selectablefields.samples.fabric8.io.v1.approved.yml

Relates to: #6390

@baloo42 baloo42 changed the title Selectable fields for custom resources CRD-Generator: Selectable fields for custom resources Oct 5, 2024
@baloo42 baloo42 changed the title CRD-Generator: Selectable fields for custom resources CRD-Generator: Selectable fields Oct 5, 2024
@manusa manusa added component/crd-generator Related to the CRD generator enhancement labels Oct 8, 2024
@vaidikcode
Copy link

@baloo42 I have created the annotations and understand the reflection logic behind the selector field annotation. However, I am having trouble integrating it with the CRD generator. Could you please guide me to any documents or resources that I can refer to for understanding the current CRD generator? if any exist? That would be very helpful. Thank you!

@baloo42
Copy link
Contributor Author

baloo42 commented Oct 31, 2024

The selector field annotation has not been implemented yet. The links in the description are pointing to a prototype of a CRD-Generator which is based on victools/json-schema-generator instead of Jackson/json-schema. The links are only mentioned here because it's possible to copy the test cases over to the fabric8/kubernetes-client/CRD-Generator implementation.

If you need a stable CRD-Generator now, I would recommend to use the latest v6 version, at the moment v6.13.4, until v7 has been released.

https://javaoperatorsdk.io/docs/features/#automatic-generation-of-crds
https://docs.quarkiverse.io/quarkus-operator-sdk/dev/includes/quarkus-operator-sdk.html#quarkus-operator-sdk_quarkus-operator-sdk-crd-generate
https://github.com/fabric8io/kubernetes-client/blob/v6.13.4/doc/CRD-generator.md

@metacosm
Copy link
Collaborator

metacosm commented Nov 7, 2024

Which also raises the question: can we actually perform field-selector queries using the client at this point? @manusa

@manusa
Copy link
Member

manusa commented Nov 7, 2024

Which also raises the question: can we actually perform field-selector queries using the client at this point? @manusa

if you're talking about things like

client.pods().withField("metadata.name", "the-name").withoutField("foo", "bar").list();

are perfectly possible in the client.

@metacosm
Copy link
Collaborator

metacosm commented Nov 7, 2024

Cool! Wasn't aware of that feature both in kube and in the client… 😅
Learned something today!

@manusa manusa added this to the 7.0.0 milestone Nov 20, 2024 — with automated-tasks
manusa pushed a commit that referenced this issue Nov 20, 2024
feat(crd-generator): Add support for selectable fields (#6392)
---
Include selectable field in unit test
---
Add docs about `@AdditionalPrinterColumn` annotation
---
Add docs about `@SelectableField` and `@AdditionalSelectableField` annotation
---
Add changelog
@manusa manusa changed the title CRD-Generator: Selectable fields CRDGenerator: Selectable fields Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/crd-generator Related to the CRD generator enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants