-
Notifications
You must be signed in to change notification settings - Fork 540
[FLINK-31849] Adds basic CRD validations #1144
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,7 +154,9 @@ private Optional<String> validateFlinkVersion(FlinkDeployment deployment) { | |
| var spec = deployment.getSpec(); | ||
| var version = spec.getFlinkVersion(); | ||
| if (version == null) { | ||
| 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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
| } | ||
|
|
||
| if (!FlinkVersion.isSupported(version)) { | ||
|
|
@@ -182,12 +184,11 @@ private Optional<String> validateFlinkVersion(FlinkDeployment deployment) { | |
| } | ||
|
|
||
| private Optional<String> validateIngress(IngressSpec ingress, String name, String namespace) { | ||
| if (ingress == null) { | ||
| if (ingress == null || ingress.getTemplate() == null) { | ||
| // Template presence (when an ingress is configured) is enforced by the CRD schema | ||
| // (@Required on IngressSpec.template). | ||
| return Optional.empty(); | ||
| } | ||
| if (ingress.getTemplate() == null) { | ||
| return Optional.of("Ingress template must be defined"); | ||
| } | ||
| try { | ||
| IngressUtils.getIngressUrl(ingress.getTemplate(), name, namespace); | ||
| } catch (ReconciliationException e) { | ||
|
|
@@ -294,9 +295,10 @@ private Optional<String> validateJobSpec( | |
|
|
||
| var tmReplicasDefined = tm != null && tm.getReplicas() != null; | ||
|
|
||
| if (tmReplicasDefined && tm.getReplicas() < 1) { | ||
| return Optional.of("TaskManager replicas must be larger than 0"); | ||
| } else if (!tmReplicasDefined && job.getParallelism() < 1) { | ||
| // TaskManager replicas >= 1 is enforced by the CRD schema (@Min(1) on | ||
| // TaskManagerSpec.replicas). Only the parallelism fallback (used when replicas are not | ||
| // set) needs checking here, since parallelism defaults to 0 and is otherwise unconstrained. | ||
| if (!tmReplicasDefined && job.getParallelism() < 1) { | ||
| return Optional.of("Job parallelism must be larger than 0"); | ||
| } | ||
|
|
||
|
|
@@ -414,9 +416,8 @@ private Optional<String> validateJmMemoryConfig(Configuration conf) { | |
| } | ||
|
|
||
| private Optional<String> validateJmReplicas(int replicas, Map<String, String> confMap) { | ||
| if (replicas < 1) { | ||
| return Optional.of("JobManager replicas should not be configured less than one."); | ||
| } else if (replicas > 1 | ||
| // replicas >= 1 is enforced by the CRD schema (@Min(1) on JobManagerSpec.replicas). | ||
| if (replicas > 1 | ||
| && !HighAvailabilityMode.isHighAvailabilityModeActivated( | ||
| Configuration.fromMap(confMap))) { | ||
| return Optional.of( | ||
|
|
@@ -442,8 +443,7 @@ private Optional<String> validateTmSpec(TaskManagerSpec tmSpec, Map<String, Stri | |
| return firstPresent( | ||
| tmMemoryConfigValidation, | ||
| validateResources("TaskManager", tmSpec.getResource()), | ||
| validateResourceRequirements("TaskManager", tmSpec.getResources()), | ||
| validateTmReplicas(tmSpec)); | ||
| validateResourceRequirements("TaskManager", tmSpec.getResources())); | ||
| } | ||
|
|
||
| private Optional<String> validateTmMemoryConfig(Configuration conf) { | ||
|
|
@@ -457,13 +457,6 @@ private Optional<String> validateTmMemoryConfig(Configuration conf) { | |
| return Optional.empty(); | ||
| } | ||
|
|
||
| private Optional<String> validateTmReplicas(TaskManagerSpec tmSpec) { | ||
| if (tmSpec.getReplicas() != null && tmSpec.getReplicas() < 1) { | ||
| return Optional.of("TaskManager replicas should not be configured less than one."); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| private Optional<String> validateResources(String component, Resource resource) { | ||
| if (resource == null) { | ||
| return Optional.empty(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look as a necessary validation constraint.