Aitozi commented on code in PR #196:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/196#discussion_r867441326
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/reconciler/ReconciliationUtils.java:
##########
@@ -255,4 +257,34 @@ public static boolean shouldRollBack(
.minus(readinessTimeout)
.isAfter(Instant.ofEpochMilli(reconciliationStatus.getReconciliationTimestamp()));
}
+
+ public static <
+ SPEC extends AbstractFlinkSpec,
+ STATUS extends CommonStatus<SPEC>,
+ CR extends CustomResource<SPEC, STATUS>>
+ boolean applyValidationErrorAndResetSpec(
Review Comment:
nit: for the return `boolean` I think we'd better document for it, Otherwise
we have to read the code to know what it mean
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/reconciler/ReconciliationUtils.java:
##########
@@ -255,4 +257,34 @@ public static boolean shouldRollBack(
.minus(readinessTimeout)
.isAfter(Instant.ofEpochMilli(reconciliationStatus.getReconciliationTimestamp()));
}
+
+ public static <
+ SPEC extends AbstractFlinkSpec,
+ STATUS extends CommonStatus<SPEC>,
+ CR extends CustomResource<SPEC, STATUS>>
+ boolean applyValidationErrorAndResetSpec(
+ CR deployment, CommonStatus<?> prevStatus, String newErr) {
+
+ if (!newErr.equals(prevStatus.getError())) {
+ LOG.error("Validation failed: " + newErr);
+ }
+
+ ReconciliationUtils.updateForReconciliationError(deployment, newErr);
+
+ var lastReconciledSpec =
+
deployment.getStatus().getReconciliationStatus().deserializeLastReconciledSpec();
+ if (lastReconciledSpec == null) {
+ // Validation failed before anything was deployed, nothing to do
+ return false;
+ } else {
+ // We need to observe/reconcile using the last version of the
deployment spec
+ deployment.setSpec(lastReconciledSpec);
Review Comment:
This means we will change the spec when it generates the validation error,
will this break the principle that not change the spec directly ?
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/reconciler/ReconciliationUtils.java:
##########
@@ -255,4 +257,34 @@ public static boolean shouldRollBack(
.minus(readinessTimeout)
.isAfter(Instant.ofEpochMilli(reconciliationStatus.getReconciliationTimestamp()));
}
+
+ public static <
+ SPEC extends AbstractFlinkSpec,
+ STATUS extends CommonStatus<SPEC>,
+ CR extends CustomResource<SPEC, STATUS>>
+ boolean applyValidationErrorAndResetSpec(
+ CR deployment, CommonStatus<?> prevStatus, String newErr) {
+
+ if (!newErr.equals(prevStatus.getError())) {
+ LOG.error("Validation failed: " + newErr);
+ }
+
+ ReconciliationUtils.updateForReconciliationError(deployment, newErr);
+
+ var lastReconciledSpec =
+
deployment.getStatus().getReconciliationStatus().deserializeLastReconciledSpec();
+ if (lastReconciledSpec == null) {
+ // Validation failed before anything was deployed, nothing to do
+ return false;
+ } else {
+ // We need to observe/reconcile using the last version of the
deployment spec
+ deployment.setSpec(lastReconciledSpec);
Review Comment:
I have a doubt that can we enforce user to use the operator with the
webhook? I think it will make the things much easier, because it will not apply
the unexpected spec succeed. Do you know whether there is strong reason for
users to disable the webhook?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]