Skip to content

CRDGenerator: Support for ListType #6669

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

Open
baloo42 opened this issue Nov 27, 2024 · 1 comment
Open

CRDGenerator: Support for ListType #6669

baloo42 opened this issue Nov 27, 2024 · 1 comment
Labels
component/crd-generator Related to the CRD generator enhancement

Comments

@baloo42
Copy link
Contributor

baloo42 commented Nov 27, 2024

Is your enhancement related to a problem? Please describe

In Kubernetes the topology of lists/arrays can be described further:

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#jsonschemaprops-v1-apiextensions-k8s-io

List restrictions are sometimes required to apply CEL validation rules. Those rules can't be used at the moment because we don't offer a way to configure the topology.

Relates to #5881

Describe the solution you'd like

Suggested Annotations:

/**
 * Annotates a list or array to further describe its topology.
 * <p>
 * Emits {@code x-kubernetes-list-type}
 * </p>
 */
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface ListType {

  /**
   * @return the list type
   */
  Type value() default Type.ATOMIC;

  /**
   * @return the map keys. Only used if {@link Type} is {@link Type#MAP}.
   */
  String[] mapKeys() default {};

  /**
   * The Kubernetes List Type
   */
  enum Type {
    /**
     * The list is treated as a single entity, like a scalar.
     * Atomic lists will be entirely replaced when updated.
     */
    ATOMIC,

    /**
     * Sets are lists that must not have multiple items with the same value. Each
     * value must be a scalar, an object with x-kubernetes-map-type <code>atomic</code>
     * ({@link MapType.Type#ATOMIC}) or an array with x-kubernetes-list-type
     * <code>atomic</code> ({@link ListType.Type#ATOMIC}).
     */
    SET,

    /**
     * These lists are like maps in that their elements have a non-index key
     * used to identify them. Order is preserved upon merge. The map tag
     * must only be used on a list with elements of type object.
     *
     * @see ListMapKey
     */
    MAP
  }
}
/**
 * Marks a field as key.
 * Only considered if {@link ListType.Type#MAP} is used
 * on the parent container.
 *
 * @see ListType
 */
@Target({ ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface ListMapKey {
}

Describe alternatives you've considered

No response

Additional context

Example:
https://github.com/baloo42/crd-generator-victools/blob/main/test/src/test/java/io/fabric8/crd/generator/victools/approvaltests/listtype/ListTypeSpec.java
https://github.com/baloo42/crd-generator-victools/blob/main/test/src/test/resources/io/fabric8/crd/generator/victools/approvaltests/CRDGeneratorVictoolsApprovalTest.approvalTest.listtypes.samples.fabric8.io.v1.approved.yml

Copy link

stale bot commented Mar 1, 2025

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale label Mar 1, 2025
@stale stale bot closed this as completed Mar 8, 2025
@manusa manusa reopened this Mar 8, 2025
@stale stale bot removed the status/stale label Mar 8, 2025
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

No branches or pull requests

2 participants