2929import org .apache .flink .kubernetes .operator .config .KubernetesOperatorConfigOptions ;
3030import org .apache .flink .kubernetes .operator .controller .FlinkBlueGreenDeployments ;
3131import org .apache .flink .kubernetes .operator .controller .FlinkResourceContext ;
32- import org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils ;
3332import org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils ;
3433import org .apache .flink .util .Preconditions ;
3534
4948import static org .apache .flink .kubernetes .operator .controller .bluegreen .BlueGreenKubernetesService .updateFlinkDeployment ;
5049import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .fetchSavepointInfo ;
5150import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .getLastCheckpoint ;
51+ import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .getSpecDiff ;
52+ import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .hasSpecChanged ;
5253import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .isSavepointRequired ;
5354import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .lookForCheckpoint ;
5455import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .prepareFlinkDeployment ;
56+ import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .setLastReconciledSpec ;
5557import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenSpecUtils .triggerSavepoint ;
5658import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .getReconciliationReschedInterval ;
5759import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .instantStrToMillis ;
5860import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .millisToInstantStr ;
61+ import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .setAbortTimestamp ;
5962
6063/** Consolidated service for all Blue/Green deployment operations. */
6164public class BlueGreenDeploymentService {
@@ -108,7 +111,7 @@ public UpdateControl<FlinkBlueGreenDeployment> initiateDeployment(
108111 */
109112 public UpdateControl <FlinkBlueGreenDeployment > checkAndInitiateDeployment (
110113 BlueGreenContext context , DeploymentType currentDeploymentType ) {
111- BlueGreenDiffType specDiff = BlueGreenSpecUtils . getSpecDiff (context );
114+ BlueGreenDiffType specDiff = getSpecDiff (context );
112115
113116 if (specDiff != BlueGreenDiffType .IGNORE ) {
114117 FlinkDeployment currentFlinkDeployment =
@@ -124,15 +127,15 @@ public UpdateControl<FlinkBlueGreenDeployment> checkAndInitiateDeployment(
124127 .rescheduleAfter (getReconciliationReschedInterval (context ));
125128 }
126129
127- BlueGreenSpecUtils . setLastReconciledSpec (context );
130+ setLastReconciledSpec (context );
128131 return startTransition (context , currentDeploymentType , currentFlinkDeployment );
129132 } else {
130- BlueGreenSpecUtils . setLastReconciledSpec (context );
133+ setLastReconciledSpec (context );
131134 return patchFlinkDeployment (context , currentDeploymentType , specDiff );
132135 }
133136 } else {
134137 if (context .getDeploymentStatus ().getJobStatus ().getState () != JobStatus .FAILING ) {
135- BlueGreenSpecUtils . setLastReconciledSpec (context );
138+ setLastReconciledSpec (context );
136139 return patchStatusUpdateControl (context , null , JobStatus .FAILING );
137140 }
138141 }
@@ -292,10 +295,10 @@ private FlinkBlueGreenDeploymentState calculateSavepointingState(DeploymentType
292295 public UpdateControl <FlinkBlueGreenDeployment > monitorTransition (
293296 BlueGreenContext context , DeploymentType currentDeploymentType ) {
294297
295- handleSpecChangesDuringTransition (context );
296-
297298 TransitionState transitionState = determineTransitionState (context , currentDeploymentType );
298299
300+ handleSpecChangesDuringTransition (context , transitionState );
301+
299302 if (isFlinkDeploymentReady (transitionState .nextDeployment )) {
300303 return shouldWeDelete (
301304 context ,
@@ -308,11 +311,27 @@ public UpdateControl<FlinkBlueGreenDeployment> monitorTransition(
308311 }
309312 }
310313
311- private void handleSpecChangesDuringTransition (BlueGreenContext context ) {
312- if (BlueGreenSpecUtils .hasSpecChanged (context )) {
313- BlueGreenSpecUtils .revertToLastSpec (context );
314- LOG .warn (
315- "Blue/Green Spec change detected during transition, ignored and reverted to the last reconciled spec" );
314+ private void handleSpecChangesDuringTransition (
315+ BlueGreenContext context , TransitionState transitionState ) {
316+ if (hasSpecChanged (context )) {
317+ BlueGreenDiffType diffType = getSpecDiff (context );
318+
319+ FlinkDeployment incomingFlinkDeployment = transitionState .nextDeployment ;
320+
321+ if (diffType != BlueGreenDiffType .IGNORE ) {
322+ // Apply the new spec changes to the currently active deployment
323+ incomingFlinkDeployment .setSpec (
324+ context .getBgDeployment ().getSpec ().getTemplate ().getSpec ());
325+ // Resetting the abort grace period
326+ setAbortTimestamp (context );
327+ // Ack'ing the spec change
328+ setLastReconciledSpec (context );
329+ updateFlinkDeployment (incomingFlinkDeployment , context );
330+
331+ LOG .info (
332+ "Blue/Green Spec change detected during transition, patching incoming '{}' deployment with new changes" ,
333+ incomingFlinkDeployment .getMetadata ().getName ());
334+ }
316335 }
317336 }
318337
0 commit comments