-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: Add support for size constraints #5836
Comments
@andreaTP : Could you please share your thoughts on this one? Do you think this could be a good addition to CRD Generator? |
Hi @baloo42 and thanks a lot for this proposal. This intersects with the discussion around CEL and validation, I would prefer to have a(shared) understanding of the final target from this effort before commenting on (perceived?)"sub-tasks" like this one. Can you please come up with a design proposal along with a mocked/dummy dev-UX sample? |
In my opinion it is independent of CEL/Kubernetes Validation Rules: If a field or one of its accessors is annotated with public class ExampleSpec {
@Size(min = 1, max = 3)
String stringWithLowerAndUpperLimits;
@Size(min = 1, max = 3)
List<String> listWithLowerAndUpperLimits;
@Size(min = 1, max = 3)
String[] arrayWithLowerAndUpperLimits;
@Size(min = 1, max = 3)
Map<String, String> mapWithLowerAndUpperLimits;
} The field will have the spec:
properties:
stringWithLowerAndUpperLimits:
maxLength: 3
minLength: 1
type: string
listWithLowerAndUpperLimits:
items:
type: string
maxItems: 3
minItems: 1
type: array
arrayWithLowerAndUpperLimits:
items:
type: string
maxItems: 3
minItems: 1
type: array
mapWithLowerAndUpperLimits:
additionalProperties:
type: string
maxProperties: 3
minProperties: 1
type: object
type: object see PoC: baloo42#4 And what about the relation to Kubernetes Validation rules?
|
right, thanks for pointing this out, in this case we would need to support more constructs, e.g.: Thanks a lot for the POC and the rest, highly useful! On top of my mind:
|
No problem, I will create a new issue with an overview. Notes:
Why is the name
In my opinion, we don't have to implement a hierarchy (yet).
Can you explain this more in detail? |
Appreciated, thanks 🙏
mentioning because its extremely interesting the nuance here ( ref ) :
🤦♂️
Yes, everything we are talking about in this thread is not related to the CRDGenerator but to CRDs in general.
Does it make more sense now? cc. @metacosm as he demonstrated interest in chipping in this discussion. |
Yeah, it's very misleading.
Yes, now it makes sense. I agree with you that the annotations should be stored centrally so that they can be reused. |
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! |
Can someone reopen this issue? |
Add support for exclusiveMinimum and exclusiveMaximum (#5868) --- Fix annotation description --- Add support for minLength and maxLength (#5836) --- Add support for minItems and maxItems (#5836) --- Add support for minProperties and maxProperties (#5836) --- Add tests for type annotations and cleanup --- Add type support for strings Lists and Maps using `@Size` --- Fix javadoc in Size annotation --- Fix approval test --- Rename group in approvaltest --- Add default value handling again --- Updated docs to describe inclusive/exclusive and `@Size` annotation --- Fix typo --- Cleanup SpecReplicasPathTest --- Add unit tests --- Add changelog entries
Is your enhancement related to a problem? Please describe
At the moment the CRDGenerator does not support size constraints:
Describe the solution you'd like
A new annotation
@Size
allows to define min and/or max constraints on a field or its accessors:The CRDGenerator detects this annotation and adds JSONSchema constraints dependending on the java type:
maxLength
maxItems
maxProperties
If the annotation is used on an unsupported type, a warning message is logged.
Describe alternatives you've considered
No response
Additional context
Size constraints become more important if someone wants to use CEL Validation rules on fields of a CRD.
Because of the cost calculations of a CEL rule, constraints on strings/lists/maps are often only allowed if limits are defined.
The text was updated successfully, but these errors were encountered: