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: Support for ListType #6669

Open
baloo42 opened this issue Nov 27, 2024 · 0 comments
Open

CRDGenerator: Support for ListType #6669

baloo42 opened this issue Nov 27, 2024 · 0 comments

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

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

No branches or pull requests

1 participant