kubernetes-sigs / kubernetes-sigs/controller-tools
Feature Request: Provide an explicit way to opt out of type-level validations
- Dominant language
- Go
- Stars
- 868
- Forks
- 482
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 8
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
```go
// 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.
Contributor guide
Research direction
No implementation files or tests are named. Start by tracing controller-tools' CRD validation-generation entry point and existing marker handling, then add focused coverage for a field that reuses a validated type. Done means the marker suppresses inherited type-level validations while preserving field-level annotations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100