@@ -101,8 +101,7 @@ public UpdateControl<FlinkBlueGreenDeployment> reconcile(
101
101
102
102
if (deploymentStatus == null ) {
103
103
deploymentStatus = new FlinkBlueGreenDeploymentStatus ();
104
- deploymentStatus .setLastReconciledSpec (
105
- SpecUtils .serializeObject (flinkBlueGreenDeployment .getSpec (), "spec" ));
104
+ setLastReconciledSpec (flinkBlueGreenDeployment , deploymentStatus );
106
105
return initiateDeployment (
107
106
flinkBlueGreenDeployment ,
108
107
deploymentStatus ,
@@ -115,12 +114,6 @@ public UpdateControl<FlinkBlueGreenDeployment> reconcile(
115
114
FlinkBlueGreenDeployments deployments =
116
115
FlinkBlueGreenDeployments .fromSecondaryResources (josdkContext );
117
116
118
- // TODO: if a new deployment request comes while in the middle of a transition it's
119
- // currently ignored, but the new spec remains changed, should we roll it back?
120
- // TODO: if we choose to leave a previously failed deployment 'running' for debug
121
- // purposes,
122
- // we should flag it somehow as 'ROLLED_BACK' to signal that it can be overriden by a
123
- // new deployment attempt.
124
117
switch (deploymentStatus .getBlueGreenState ()) {
125
118
case ACTIVE_BLUE :
126
119
return checkAndInitiateDeployment (
@@ -161,7 +154,21 @@ private UpdateControl<FlinkBlueGreenDeployment> monitorTransition(
161
154
FlinkBlueGreenDeployments deployments ,
162
155
FlinkBlueGreenDeploymentStatus deploymentStatus ,
163
156
DeploymentType currentDeploymentType ,
164
- Context <FlinkBlueGreenDeployment > josdkContext ) {
157
+ Context <FlinkBlueGreenDeployment > josdkContext )
158
+ throws JsonProcessingException {
159
+
160
+ if (hasSpecChanged (bgDeployment .getSpec (), deploymentStatus , currentDeploymentType )) {
161
+ // this means the spec was changed during transition,
162
+ // ignore the new change, revert the spec and log as warning
163
+ bgDeployment .setSpec (
164
+ SpecUtils .deserializeObject (
165
+ deploymentStatus .getLastReconciledSpec (),
166
+ "spec" ,
167
+ FlinkBlueGreenDeploymentSpec .class ));
168
+ josdkContext .getClient ().resource (bgDeployment ).replace ();
169
+ LOG .warn (
170
+ "Blue/Green Spec change detected during transition, ignored and reverted to the last reconciled spec" );
171
+ }
165
172
166
173
var nextState = FlinkBlueGreenDeploymentState .ACTIVE_BLUE ;
167
174
FlinkDeployment currentDeployment ;
@@ -185,18 +192,8 @@ private UpdateControl<FlinkBlueGreenDeployment> monitorTransition(
185
192
186
193
if (isDeploymentReady (nextDeployment , josdkContext , deploymentStatus )) {
187
194
return deleteAndFinalize (
188
- bgDeployment ,
189
- deploymentStatus ,
190
- currentDeploymentType ,
191
- josdkContext ,
192
- currentDeployment ,
193
- nextState );
195
+ bgDeployment , deploymentStatus , josdkContext , currentDeployment , nextState );
194
196
} else {
195
- // This phase requires rescheduling the reconciliation because the pod initialization
196
- // could get stuck
197
- // (e.g. waiting for resources)
198
- // TODO: figure out the course of action for error/failure cases
199
-
200
197
int maxNumRetries = bgDeployment .getSpec ().getTemplate ().getMaxNumRetries ();
201
198
if (maxNumRetries <= 0 ) {
202
199
maxNumRetries = DEFAULT_MAX_NUM_RETRIES ;
@@ -242,7 +239,6 @@ private static int getReconciliationReschedInterval(FlinkBlueGreenDeployment bgD
242
239
private UpdateControl <FlinkBlueGreenDeployment > deleteAndFinalize (
243
240
FlinkBlueGreenDeployment bgDeployment ,
244
241
FlinkBlueGreenDeploymentStatus deploymentStatus ,
245
- DeploymentType currentDeploymentType ,
246
242
Context <FlinkBlueGreenDeployment > josdkContext ,
247
243
FlinkDeployment currentDeployment ,
248
244
FlinkBlueGreenDeploymentState nextState ) {
@@ -251,11 +247,6 @@ private UpdateControl<FlinkBlueGreenDeployment> deleteAndFinalize(
251
247
deleteDeployment (currentDeployment , josdkContext );
252
248
return UpdateControl .noUpdate ();
253
249
} else {
254
- deploymentStatus .setLastReconciledSpec (
255
- SpecUtils .serializeObject (bgDeployment .getSpec (), "spec" ));
256
-
257
- // TODO: Set the new child job STATUS to RUNNING too
258
-
259
250
return patchStatusUpdateControl (
260
251
bgDeployment , deploymentStatus , nextState , JobStatus .RUNNING , false );
261
252
}
@@ -272,6 +263,9 @@ private UpdateControl<FlinkBlueGreenDeployment> checkAndInitiateDeployment(
272
263
if (hasSpecChanged (
273
264
flinkBlueGreenDeployment .getSpec (), deploymentStatus , currentDeploymentType )) {
274
265
266
+ // Ack the change in the spec (setLastReconciledSpec)
267
+ setLastReconciledSpec (flinkBlueGreenDeployment , deploymentStatus );
268
+
275
269
FlinkDeployment currentFlinkDeployment =
276
270
DeploymentType .BLUE == currentDeploymentType
277
271
? deployments .getFlinkDeploymentBlue ()
@@ -286,10 +280,6 @@ private UpdateControl<FlinkBlueGreenDeployment> checkAndInitiateDeployment(
286
280
FlinkResourceContext <FlinkDeployment > resourceContext =
287
281
ctxFactory .getResourceContext (currentFlinkDeployment , josdkContext );
288
282
289
- // TODO: this operation is already done by hasSpecChanged() above, dedup later
290
- String serializedSpec =
291
- SpecUtils .serializeObject (flinkBlueGreenDeployment .getSpec (), "spec" );
292
-
293
283
// Updating status
294
284
if (DeploymentType .BLUE == currentDeploymentType ) {
295
285
nextState = FlinkBlueGreenDeploymentState .TRANSITIONING_TO_GREEN ;
@@ -323,6 +313,14 @@ private UpdateControl<FlinkBlueGreenDeployment> checkAndInitiateDeployment(
323
313
return UpdateControl .noUpdate ();
324
314
}
325
315
316
+ private static void setLastReconciledSpec (
317
+ FlinkBlueGreenDeployment flinkBlueGreenDeployment ,
318
+ FlinkBlueGreenDeploymentStatus deploymentStatus ) {
319
+ deploymentStatus .setLastReconciledSpec (
320
+ SpecUtils .serializeObject (flinkBlueGreenDeployment .getSpec (), "spec" ));
321
+ deploymentStatus .setLastReconciledTimestamp (System .currentTimeMillis ());
322
+ }
323
+
326
324
public void logPotentialWarnings (
327
325
FlinkDeployment flinkDeployment ,
328
326
Context <FlinkBlueGreenDeployment > josdkContext ,
@@ -345,7 +343,7 @@ public void logPotentialWarnings(
345
343
LOG .warn ("Deployment not healthy, some Pods have the following status: " + podPhases );
346
344
}
347
345
348
- List <Event > badEvents =
346
+ List <Event > abnormalEvents =
349
347
josdkContext
350
348
.getClient ()
351
349
.v1 ()
@@ -373,8 +371,8 @@ public void logPotentialWarnings(
373
371
.contains (p )))
374
372
.collect (Collectors .toList ());
375
373
376
- if (!badEvents .isEmpty ()) {
377
- LOG .warn ("Bad events detected: " + badEvents );
374
+ if (!abnormalEvents .isEmpty ()) {
375
+ LOG .warn ("Abnormal events detected: " + abnormalEvents );
378
376
}
379
377
}
380
378
@@ -393,9 +391,7 @@ private static Savepoint configureSavepoint(
393
391
.getJobId ()),
394
392
resourceContext .getObserveConfig ());
395
393
396
- // TODO 1: check the last CP age with the logic from
397
- // AbstractJobReconciler.changeLastStateIfCheckpointTooOld
398
- // TODO 2: if no checkpoint is available, take a savepoint? throw error?
394
+ // TODO: alternative action if no checkpoint is available?
399
395
if (lastCheckpoint .isEmpty ()) {
400
396
throw new IllegalStateException (
401
397
"Last Checkpoint for Job "
@@ -422,8 +418,6 @@ private UpdateControl<FlinkBlueGreenDeployment> initiateDeployment(
422
418
josdkContext ,
423
419
isFirstDeployment );
424
420
425
- // TODO: set child job status to JobStatus.INITIALIZING
426
-
427
421
return patchStatusUpdateControl (
428
422
flinkBlueGreenDeployment ,
429
423
deploymentStatus ,
@@ -439,8 +433,7 @@ private boolean isDeploymentReady(
439
433
FlinkBlueGreenDeploymentStatus deploymentStatus ) {
440
434
if (ResourceLifecycleState .STABLE == deployment .getStatus ().getLifecycleState ()
441
435
&& JobStatus .RUNNING == deployment .getStatus ().getJobStatus ().getState ()) {
442
- // TODO: verify, e.g. will pods be "pending" after the FlinkDeployment is RUNNING and
443
- // STABLE?
436
+ // TODO: checking for running pods seems to be redundant, check if this can be removed
444
437
int notRunningPods =
445
438
(int )
446
439
getDeploymentPods (josdkContext , deployment )
@@ -501,7 +494,6 @@ private UpdateControl<FlinkBlueGreenDeployment> patchStatusUpdateControl(
501
494
deploymentStatus .getJobStatus ().setState (jobState );
502
495
}
503
496
504
- deploymentStatus .setLastReconciledTimestamp (System .currentTimeMillis ());
505
497
flinkBlueGreenDeployment .setStatus (deploymentStatus );
506
498
return UpdateControl .patchStatus (flinkBlueGreenDeployment );
507
499
}
@@ -553,9 +545,6 @@ private void deploy(
553
545
554
546
private static void deleteDeployment (
555
547
FlinkDeployment currentDeployment , Context <FlinkBlueGreenDeployment > josdkContext ) {
556
- // TODO: This gets called multiple times, check to see if it's already in a TERMINATING
557
- // state
558
- // (or only execute if RUNNING)
559
548
List <StatusDetails > deletedStatus =
560
549
josdkContext
561
550
.getClient ()
0 commit comments