Skip to content

Commit ec120f4

Browse files
committed
Removing redundant BlueGreenDiffType cases
1 parent f712125 commit ec120f4

File tree

6 files changed

+52
-69
lines changed

6 files changed

+52
-69
lines changed

flink-kubernetes-operator-api/src/main/java/org/apache/flink/kubernetes/operator/api/bluegreen/BlueGreenDiffType.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/api/bluegreen/BlueGreenDiffType.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,5 @@ public enum BlueGreenDiffType {
2626
TRANSITION,
2727

2828
/** Changes that only affect the child FlinkDeploymentSpec. */
29-
PATCH_CHILD,
30-
31-
// TODO: the PATCH_TOP_LEVEL and PATCH_BOTH values are redundant, eliminate
32-
/** Changes that only affect the top-level configuration. */
33-
PATCH_TOP_LEVEL,
34-
35-
/** Changes that affect both top-level and child specifications. */
36-
PATCH_BOTH
29+
PATCH_CHILD
3730
}

flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/controller/bluegreen/BlueGreenDeploymentService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private UpdateControl<FlinkBlueGreenDeployment> patchFlinkDeployment(
146146
DeploymentType currentDeploymentType,
147147
BlueGreenDiffType specDiff) {
148148

149-
if (specDiff == BlueGreenDiffType.PATCH_BOTH || specDiff == BlueGreenDiffType.PATCH_CHILD) {
149+
if (specDiff == BlueGreenDiffType.PATCH_CHILD) {
150150
FlinkDeployment nextFlinkDeployment =
151151
context.getDeploymentByType(currentDeploymentType);
152152

flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/reconciler/diff/FlinkBlueGreenDeploymentSpecDiff.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public BlueGreenDiffType compare() {
6363
return BlueGreenDiffType.IGNORE;
6464
}
6565

66-
boolean hasTopLevelDiff = hasTopLevelDifferences();
6766
BlueGreenDiffType childDiffType = getChildSpecDiffType();
6867

6968
// If nested spec has SCALE or UPGRADE differences, return TRANSITION regardless
@@ -74,13 +73,11 @@ public BlueGreenDiffType compare() {
7473
// Determine result based on where differences are found
7574
boolean hasChildDiff = childDiffType != BlueGreenDiffType.IGNORE;
7675

77-
if (hasTopLevelDiff && hasChildDiff) {
78-
return BlueGreenDiffType.PATCH_BOTH;
79-
} else if (hasTopLevelDiff) {
80-
return BlueGreenDiffType.PATCH_TOP_LEVEL;
81-
} else if (hasChildDiff) {
76+
if (hasChildDiff) {
77+
// Child spec changes take precedence, return the child diff type
8278
return BlueGreenDiffType.PATCH_CHILD;
83-
} else {
79+
}
80+
else {
8481
return BlueGreenDiffType.IGNORE;
8582
}
8683
}

flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/controller/FlinkBlueGreenDeploymentControllerTest.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ public void verifyFailureDuringTransition(FlinkVersion flinkVersion) throws Exce
281281
assertFalse(rs.updateControl.isPatchResource());
282282
assertTrue(rs.updateControl.getScheduleDelay().isPresent());
283283
reschedDelayMs = rs.updateControl.getScheduleDelay().get();
284-
assertTrue(reschedDelayMs == reconciliationReschedulingIntervalMs && reschedDelayMs > 0);
284+
assertTrue(
285+
reschedDelayMs == reconciliationReschedulingIntervalMs && reschedDelayMs > 0);
285286
assertTrue(
286287
instantStrToMillis(rs.reconciledStatus.getAbortTimestamp())
287288
> System.currentTimeMillis());
@@ -409,12 +410,18 @@ public void verifyPatchScenario(FlinkVersion flinkVersion, PatchTestCase testCas
409410

410411
testCase.applyChanges(rs.deployment, kubernetesClient);
411412

412-
var result = reconcileAndVerifyPatchBehavior(rs);
413-
414-
testCase.verifySpecificBehavior(result, getFlinkDeployments());
415-
416-
assertFinalized(
417-
result.minReconciliationTs, result.rs, FlinkBlueGreenDeploymentState.ACTIVE_BLUE);
413+
// PatchTopLevelTestCase should now be ignored (return noUpdate)
414+
if (testCase instanceof PatchTopLevelTestCase) {
415+
var result = reconcileAndVerifyIgnoreBehavior(rs);
416+
testCase.verifySpecificBehavior(result, getFlinkDeployments());
417+
} else {
418+
var result = reconcileAndVerifyPatchBehavior(rs);
419+
testCase.verifySpecificBehavior(result, getFlinkDeployments());
420+
assertFinalized(
421+
result.minReconciliationTs,
422+
result.rs,
423+
FlinkBlueGreenDeploymentState.ACTIVE_BLUE);
424+
}
418425
}
419426

420427
// ==================== Parameterized Test Inputs ====================
@@ -607,6 +614,30 @@ private ReconcileResult reconcileAndVerifyPatchBehavior(
607614
return new ReconcileResult(minReconciliationTs, rs, existingFlinkDeployment);
608615
}
609616

617+
private ReconcileResult reconcileAndVerifyIgnoreBehavior(
618+
TestingFlinkBlueGreenDeploymentController.BlueGreenReconciliationResult rs)
619+
throws Exception {
620+
621+
var flinkDeployments = getFlinkDeployments();
622+
assertEquals(1, flinkDeployments.size());
623+
var existingFlinkDeployment = flinkDeployments.get(0);
624+
625+
var minReconciliationTs = System.currentTimeMillis() - 1;
626+
rs = reconcile(rs.deployment);
627+
628+
assertIgnoreOperationTriggered(rs);
629+
630+
return new ReconcileResult(minReconciliationTs, rs, existingFlinkDeployment);
631+
}
632+
633+
private void assertIgnoreOperationTriggered(
634+
TestingFlinkBlueGreenDeploymentController.BlueGreenReconciliationResult rs) {
635+
// For IGNORE behavior, we expect noUpdate (no patch status, no reschedule)
636+
assertFalse(rs.updateControl.isPatchStatus());
637+
assertFalse(rs.updateControl.isPatchResource());
638+
assertFalse(rs.updateControl.getScheduleDelay().isPresent());
639+
}
640+
610641
private void assertPatchOperationTriggered(
611642
TestingFlinkBlueGreenDeploymentController.BlueGreenReconciliationResult rs,
612643
long minReconciliationTs) {

flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/reconciler/diff/FlinkBlueGreenDeploymentSpecDiffTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void testIgnoreForIdenticalSpecs() {
101101
}
102102

103103
@Test
104-
public void testPatchTopLevelForMetadataDifference() {
104+
public void testIgnoreForMetadataDifference() {
105105
FlinkBlueGreenDeploymentSpec spec1 = createBasicSpec();
106106
FlinkBlueGreenDeploymentSpec spec2 = createBasicSpec();
107107

@@ -113,11 +113,11 @@ public void testPatchTopLevelForMetadataDifference() {
113113
FlinkBlueGreenDeploymentSpecDiff diff =
114114
new FlinkBlueGreenDeploymentSpecDiff(DEPLOYMENT_MODE, spec1, spec2);
115115

116-
assertEquals(BlueGreenDiffType.PATCH_TOP_LEVEL, diff.compare());
116+
assertEquals(BlueGreenDiffType.IGNORE, diff.compare());
117117
}
118118

119119
@Test
120-
public void testPatchTopLevelForConfigurationDifference() {
120+
public void testIgnoreForConfigurationDifference() {
121121
FlinkBlueGreenDeploymentSpec spec1 = createBasicSpec();
122122
FlinkBlueGreenDeploymentSpec spec2 = createBasicSpec();
123123

@@ -129,7 +129,7 @@ public void testPatchTopLevelForConfigurationDifference() {
129129
FlinkBlueGreenDeploymentSpecDiff diff =
130130
new FlinkBlueGreenDeploymentSpecDiff(DEPLOYMENT_MODE, spec1, spec2);
131131

132-
assertEquals(BlueGreenDiffType.PATCH_TOP_LEVEL, diff.compare());
132+
assertEquals(BlueGreenDiffType.IGNORE, diff.compare());
133133
}
134134

135135
@Test
@@ -150,7 +150,7 @@ public void testPatchChildForNestedSpecDifference() {
150150
}
151151

152152
@Test
153-
public void testPatchBothForTopLevelAndNestedDifferences() {
153+
public void testPatchChildForTopLevelAndNestedDifferences() {
154154
FlinkBlueGreenDeploymentSpec spec1 = createBasicSpec();
155155
FlinkBlueGreenDeploymentSpec spec2 = createBasicSpec();
156156

@@ -166,7 +166,7 @@ public void testPatchBothForTopLevelAndNestedDifferences() {
166166
FlinkBlueGreenDeploymentSpecDiff diff =
167167
new FlinkBlueGreenDeploymentSpecDiff(DEPLOYMENT_MODE, spec1, spec2);
168168

169-
assertEquals(BlueGreenDiffType.PATCH_BOTH, diff.compare());
169+
assertEquals(BlueGreenDiffType.PATCH_CHILD, diff.compare());
170170
}
171171

172172
@Test
@@ -198,7 +198,7 @@ public void testTransitionForUpgradeDifference() {
198198
}
199199

200200
@Test
201-
public void testTransitionOverridesPatchBoth() {
201+
public void testTransitionOverridesPatchChild() {
202202
FlinkBlueGreenDeploymentSpec spec1 = createBasicSpec();
203203
FlinkBlueGreenDeploymentSpec spec2 = createBasicSpec();
204204

@@ -211,7 +211,7 @@ public void testTransitionOverridesPatchBoth() {
211211
FlinkBlueGreenDeploymentSpecDiff diff =
212212
new FlinkBlueGreenDeploymentSpecDiff(DEPLOYMENT_MODE, spec1, spec2);
213213

214-
// Should return TRANSITION, not PATCH_BOTH
214+
// Should return TRANSITION, not PATCH_CHILD
215215
assertEquals(BlueGreenDiffType.TRANSITION, diff.compare());
216216
}
217217

0 commit comments

Comments
 (0)