[FLINK-31849] Adds basic CRD validations#1144
Conversation
|
@gyfora I think we can expand it. I just added single-field constraints that map cleanly to the CRD schema with zero behavior change for already-valid resources. The same approach can be extended incrementally:
@required on always-mandatory fields: e.g. serviceAccount and deploymentName. These are already mandatory in DefaultValidator, so the only change is moving rejection to admission time but I am not sure about this because it is a user-visible UX change Cross-field rules via CEL: |
5a74f8b to
7a6d3b1
Compare
Dennis-Mircea
left a comment
There was a problem hiding this comment.
I'd say this PR touches a validation area that needs a more careful look, deeper investigation, and proper testing before it moves forward.
As it stands it feels a bit superficial, since it also misses a number of other fields that could be validated the same way, for example:
FlinkDeploymentSpec.serviceAccount->@Required(currently invalidateServiceAccount, same pattern asflinkVersion).FlinkSessionJobSpec.deploymentName->@Required+@Pattern(theDEPLOYMENT_NAME_PATTERNregex already exists).
Before marking this PR as ready for review, please make sure every single-field constraint in DefaultValidator that can be expressed declaratively is actually covered by an annotation. The checks that genuinely cannot move (cross-field or config-derived rules, e.g. the replicas > 1 requires-HA rule, the parallelism fallback, ingress URL parsing) should be the only ones left imperative, and ideally called out as such.
| return Optional.of("Flink Version must be defined."); | ||
| // Presence is enforced by the CRD schema (@Required on | ||
| // FlinkDeploymentSpec.flinkVersion); nothing further to validate here. | ||
| return Optional.empty(); |
There was a problem hiding this comment.
The new validation is admission-only and does not cover the reconcile cycle. The new added constraints are enforced only at admission, and only if the updated CRD is installed, which is a manual step (Helm does not auto-upgrade crds/). DefaultValidator, however, runs on every reconcile as well, so removing these checks drops the runtime validation checks: after an operator bump where the CRD has not been replaced yet, an invalid spec reaching reconcile is no longer caught and hits deploy logic with a bad value.
| * Maximum number of retries before the snapshot is considered as failed. Set to -1 for | ||
| * unlimited or 0 for no retries. | ||
| */ | ||
| @Min(-1) |
There was a problem hiding this comment.
This doesn't look as a necessary validation constraint.

What is the purpose of the change
This pull request moves simple, single-field spec validation from the operator's imperative DefaultValidator into declarative CRD-generator annotations, so these constraints are enforced by the Kubernetes API server at admission time rather than only during reconciliation. This gives users immediate, schema-level feedback on
kubectl applyand simplifies the validation logic in the operator.Brief change log
Verifying this change
linkConfigurationYamlSupportTest#crdRejectsInvalidSpecValues, which applies the regenerated CRD to an in-process API server (kubeapitest) and verifies that resources violating each new constraintare rejected at admission, while a fully specified deployment is acceptedDoes this pull request potentially affect one of the following parts:
CustomResourceDescriptors: yes.Documentation