-
Notifications
You must be signed in to change notification settings - Fork 460
Description
Problem
Currently, when reusing a Go type in a CRD, the validation rules associated with that type are automatically applied. However, there are use cases where users want to reuse a type but apply different validation rules. The current workaround is to create a new type without validations, which becomes a maintenance burden when there are many minor differences.
Proposal
Introduce a marker, such as +k8s:opaque, that can be used on a field to disable the generation of type-level validations for that field. Field-level validation annotations on the field would still be processed and applied.
This would allow users to reuse existing types without inheriting their validation rules, and instead define custom validation for the field as needed.
This approach is similar to the opaque validation of Declarative validation, KEP-5073.
Example
// Original type with validation
// +kubebuilder:validation:MaxLength=10
type MyString string
// CRD that reuses MyString but with different validation
type MyCRD struct {
// +k8s:opaque
// +kubebuilder:validation:MaxLength=5
MyField MyString `json:"myField"`
}In this example, the generated validation for MyField would only check for a maxLength of 5, and the maxLength=10 from MyString would be ignored.