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

CRD Generation - Defaulting Support #5410

Closed
penev-ff opened this issue Aug 30, 2023 · 4 comments · Fixed by #5431
Closed

CRD Generation - Defaulting Support #5410

penev-ff opened this issue Aug 30, 2023 · 4 comments · Fixed by #5431
Assignees
Labels
component/crd-generator Related to the CRD generator enhancement
Milestone

Comments

@penev-ff
Copy link

penev-ff commented Aug 30, 2023

While the crd-generator currently supports annotations such as @Pattern, @Min, @Max, @Required, etc, which helps to enforce constraints on CRD fields, there is no way of specifying default values. I would appreciate built-in support for setting default values when generating the CustomResourceDefinition.

Reference: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting

I suggest implementing a mechanism that allows to define such default values for the CRD fields by using annotations, similar to how existing annotations work. For example:

public class MyCustomResourceSpec {
    // ... Other annotations
    @Required
    @DefaultValue("example")
    private String exampleValue;
}

Corresponding default: example will be generated in the output CRD, such as:

properties:
  spec:
    properties:
      exampleValue:
        type: string
        default: "example"
      required:
      - exampleValue
@andreaTP andreaTP added enhancement component/crd-generator Related to the CRD generator labels Aug 30, 2023
@andreaTP
Copy link
Member

All in all, I'm in favor of adding this functionality.

The challenge here is that the "default value" expressed in the annotation and emitted in the CRD might be different than the default applied after deserialization(due to Jackson configuration etc.).
This behavior might make things confusing, but I don't think we have any way to extract the "default value" ATM (cc. @metacosm ).

@shawkins
Copy link
Contributor

Jackson does support a defaultValue argument with JsonProperty as well.

@andreaTP
Copy link
Member

andreaTP commented Sep 4, 2023

Jackson does support a defaultValue argument with JsonProperty as well.

For context, we already moved away from "reusing existing Annotations" as they are not under our control and we don't want to add more semantics to something outside this codebase.

@manusa
Copy link
Member

manusa commented Sep 5, 2023

Similar to #5324

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