4545import static org .apache .flink .kubernetes .operator .controller .bluegreen .BlueGreenKubernetesService .deployCluster ;
4646import static org .apache .flink .kubernetes .operator .controller .bluegreen .BlueGreenKubernetesService .isFlinkDeploymentReady ;
4747import static org .apache .flink .kubernetes .operator .controller .bluegreen .BlueGreenKubernetesService .suspendFlinkDeployment ;
48- import static org .apache .flink .kubernetes .operator .controller .bluegreen .BlueGreenKubernetesService .updateFlinkDeployment ;
4948import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .fetchSavepointInfo ;
5049import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .getReconciliationReschedInterval ;
5150import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .getSpecDiff ;
5453import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .isSavepointRequired ;
5554import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .millisToInstantStr ;
5655import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .prepareFlinkDeployment ;
57- import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .setAbortTimestamp ;
5856import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .setLastReconciledSpec ;
5957import static org .apache .flink .kubernetes .operator .utils .bluegreen .BlueGreenUtils .triggerSavepoint ;
6058
@@ -131,7 +129,7 @@ public UpdateControl<FlinkBlueGreenDeployment> checkAndInitiateDeployment(
131129 context , currentBlueGreenDeploymentType , currentFlinkDeployment );
132130 } else {
133131 setLastReconciledSpec (context );
134- return patchFlinkDeployment (context , currentBlueGreenDeploymentType , specDiff );
132+ return patchFlinkDeployment (context , currentBlueGreenDeploymentType );
135133 }
136134 } else {
137135 if (context .getDeploymentStatus ().getJobStatus ().getState () != JobStatus .FAILING ) {
@@ -152,25 +150,25 @@ public UpdateControl<FlinkBlueGreenDeployment> checkAndInitiateDeployment(
152150 }
153151
154152 private UpdateControl <FlinkBlueGreenDeployment > patchFlinkDeployment (
155- BlueGreenContext context ,
156- BlueGreenDeploymentType currentBlueGreenDeploymentType ,
157- BlueGreenDiffType specDiff ) {
153+ BlueGreenContext context , BlueGreenDeploymentType currentBlueGreenDeploymentType ) {
158154
159- if (specDiff == BlueGreenDiffType .PATCH_CHILD ) {
160- FlinkDeployment nextFlinkDeployment =
161- context .getDeploymentByType (currentBlueGreenDeploymentType );
155+ String childDeploymentName =
156+ context .getBgDeployment ().getMetadata ().getName ()
157+ + "-"
158+ + currentBlueGreenDeploymentType .toString ().toLowerCase ();
159+ LOG .info ("Patching FlinkDeployment '{}'" , childDeploymentName );
162160
163- nextFlinkDeployment .setSpec (
164- context .getBgDeployment ().getSpec ().getTemplate ().getSpec ());
161+ // We want to patch, therefore the transition should point to the existing deployment
162+ // details
163+ var patchingState = calculatePatchingState (currentBlueGreenDeploymentType );
165164
166- updateFlinkDeployment (nextFlinkDeployment , context );
167- }
165+ // If we're not transitioning between deployments, mark as a single deployment to have it
166+ // not wait for synchronization
167+ var isFirstDeployment = context .getDeployments ().getNumberOfDeployments () != 2 ;
168168
169- return patchStatusUpdateControl (
170- context ,
171- calculatePatchingState (currentBlueGreenDeploymentType ),
172- JobStatus .RECONCILING )
173- .rescheduleAfter (BlueGreenUtils .getReconciliationReschedInterval (context ));
169+ // No checkpoint will be used when patching
170+ return initiateDeployment (
171+ context , currentBlueGreenDeploymentType , patchingState , null , isFirstDeployment );
174172 }
175173
176174 private UpdateControl <FlinkBlueGreenDeployment > startTransition (
@@ -284,7 +282,7 @@ private boolean handleSavepoint(
284282 return true ;
285283 }
286284
287- LOG .debug ("Savepoint previously requested (triggerId: {})" , savepointTriggerId );
285+ LOG .info ("Savepoint previously requested (triggerId: {})" , savepointTriggerId );
288286 return false ;
289287 }
290288
@@ -309,11 +307,16 @@ private FlinkBlueGreenDeploymentState calculateSavepointingState(
309307 public UpdateControl <FlinkBlueGreenDeployment > monitorTransition (
310308 BlueGreenContext context , BlueGreenDeploymentType currentBlueGreenDeploymentType ) {
311309
310+ var updateControl =
311+ handleSpecChangesDuringTransition (context , currentBlueGreenDeploymentType );
312+
313+ if (updateControl != null ) {
314+ return updateControl ;
315+ }
316+
312317 TransitionState transitionState =
313318 determineTransitionState (context , currentBlueGreenDeploymentType );
314319
315- handleSpecChangesDuringTransition (context , transitionState );
316-
317320 if (isFlinkDeploymentReady (transitionState .nextDeployment )) {
318321 return shouldWeDelete (
319322 context ,
@@ -326,28 +329,20 @@ public UpdateControl<FlinkBlueGreenDeployment> monitorTransition(
326329 }
327330 }
328331
329- private void handleSpecChangesDuringTransition (
330- BlueGreenContext context , TransitionState transitionState ) {
332+ private UpdateControl < FlinkBlueGreenDeployment > handleSpecChangesDuringTransition (
333+ BlueGreenContext context , BlueGreenDeploymentType currentBlueGreenDeploymentType ) {
331334 if (hasSpecChanged (context )) {
332335 BlueGreenDiffType diffType = getSpecDiff (context );
333336
334- FlinkDeployment incomingFlinkDeployment = transitionState .nextDeployment ;
335-
336337 if (diffType != BlueGreenDiffType .IGNORE ) {
337- // Apply new spec changes to the deployment currently being transitioned to
338- incomingFlinkDeployment .setSpec (
339- context .getBgDeployment ().getSpec ().getTemplate ().getSpec ());
340- // Reset abort grace period to allow more time for the updated deployment
341- setAbortTimestamp (context );
342- // Mark spec change as reconciled
343338 setLastReconciledSpec (context );
344- updateFlinkDeployment (incomingFlinkDeployment , context );
345-
346- LOG .info (
347- "Blue/Green Spec change detected during transition, patching incoming '{}' deployment with new changes" ,
348- incomingFlinkDeployment .getMetadata ().getName ());
339+ var oppositeDeploymentType =
340+ context .getOppositeDeploymentType (currentBlueGreenDeploymentType );
341+ return patchFlinkDeployment (context , oppositeDeploymentType );
349342 }
350343 }
344+
345+ return null ;
351346 }
352347
353348 private TransitionState determineTransitionState (
0 commit comments