kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

CRD-Generator: Selectable fields

Open baloo42 opened this issue 5 months ago • 0 comments

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: https://github.com/fabric8io/kubernetes-client/pull/6390

baloo42 avatar Sep 30 '24 19:09 baloo42