Skip to content

Commit c479a46

Browse files
authored
[FLINK-38517] Fixed equal check to happen after inplace modifications diffResult
1 parent b21db11 commit c479a46

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ public BlueGreenDiffType compare() {
5959
FlinkDeploymentSpec leftSpec = left.getTemplate().getSpec();
6060
FlinkDeploymentSpec rightSpec = right.getTemplate().getSpec();
6161

62+
// Used in Case 2 & 3: Delegate to ReflectiveDiffBuilder for nested spec comparison
63+
// Calculate diffResult before comparison to apply in-place removal of ignored fields
64+
DiffResult<FlinkDeploymentSpec> diffResult =
65+
new ReflectiveDiffBuilder<>(deploymentMode, leftSpec, rightSpec).build();
66+
6267
// Case 1: FlinkDeploymentSpecs are identical
6368
if (leftSpec.equals(rightSpec)) {
6469
return BlueGreenDiffType.IGNORE;
6570
}
6671

67-
// Case 2 & 3: Delegate to ReflectiveDiffBuilder for nested spec comparison
68-
DiffResult<FlinkDeploymentSpec> diffResult =
69-
new ReflectiveDiffBuilder<>(deploymentMode, leftSpec, rightSpec).build();
70-
72+
// Extract the diff type from ReflectiveDiffBuilder result
7173
DiffType diffType = diffResult.getType();
7274

7375
// Case 2: ReflectiveDiffBuilder returns IGNORE

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.flink.kubernetes.operator.api.spec.UpgradeMode;
3434

3535
import io.fabric8.kubernetes.api.model.ObjectMeta;
36+
import io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder;
3637
import org.junit.jupiter.api.Test;
3738

3839
import java.util.HashMap;
@@ -133,6 +134,68 @@ public void testIgnoreForConfigurationDifference() {
133134
assertEquals(BlueGreenDiffType.IGNORE, diff.compare());
134135
}
135136

137+
@Test
138+
public void testIgnoreForRootPodTemplateAdditionalProps() {
139+
FlinkBlueGreenDeploymentSpec spec1 = createBasicSpec();
140+
FlinkBlueGreenDeploymentSpec spec2 = createBasicSpec();
141+
142+
// Set spec1 to have empty podTemplate to not cause valid diff to be detected
143+
spec1.getTemplate().getSpec().setPodTemplate(new PodTemplateSpecBuilder().build());
144+
spec2.getTemplate()
145+
.getSpec()
146+
.setPodTemplate(
147+
new PodTemplateSpecBuilder()
148+
.withAdditionalProperties(Map.of("apiVersion", "v1"))
149+
.build());
150+
FlinkBlueGreenDeploymentSpecDiff diff =
151+
new FlinkBlueGreenDeploymentSpecDiff(DEPLOYMENT_MODE, spec1, spec2);
152+
assertEquals(BlueGreenDiffType.IGNORE, diff.compare());
153+
}
154+
155+
@Test
156+
public void testIgnoreForJobManagerPodTemplateAdditionalProps() {
157+
FlinkBlueGreenDeploymentSpec spec1 = createBasicSpec();
158+
FlinkBlueGreenDeploymentSpec spec2 = createBasicSpec();
159+
160+
// Set spec1 to have empty podTemplate to not cause valid diff to be detected
161+
spec1.getTemplate()
162+
.getSpec()
163+
.getJobManager()
164+
.setPodTemplate(new PodTemplateSpecBuilder().build());
165+
spec2.getTemplate()
166+
.getSpec()
167+
.getJobManager()
168+
.setPodTemplate(
169+
new PodTemplateSpecBuilder()
170+
.withAdditionalProperties(Map.of("apiVersion", "v1"))
171+
.build());
172+
FlinkBlueGreenDeploymentSpecDiff diff =
173+
new FlinkBlueGreenDeploymentSpecDiff(DEPLOYMENT_MODE, spec1, spec2);
174+
assertEquals(BlueGreenDiffType.IGNORE, diff.compare());
175+
}
176+
177+
@Test
178+
public void testIgnoreForTaskManagerPodTemplateAdditionalProps() {
179+
FlinkBlueGreenDeploymentSpec spec1 = createBasicSpec();
180+
FlinkBlueGreenDeploymentSpec spec2 = createBasicSpec();
181+
182+
// Set spec1 to have empty podTemplate to not cause valid diff to be detected
183+
spec1.getTemplate()
184+
.getSpec()
185+
.getTaskManager()
186+
.setPodTemplate(new PodTemplateSpecBuilder().build());
187+
spec2.getTemplate()
188+
.getSpec()
189+
.getTaskManager()
190+
.setPodTemplate(
191+
new PodTemplateSpecBuilder()
192+
.withAdditionalProperties(Map.of("apiVersion", "v1"))
193+
.build());
194+
FlinkBlueGreenDeploymentSpecDiff diff =
195+
new FlinkBlueGreenDeploymentSpecDiff(DEPLOYMENT_MODE, spec1, spec2);
196+
assertEquals(BlueGreenDiffType.IGNORE, diff.compare());
197+
}
198+
136199
@Test
137200
public void testTransitionForNestedSpecDifference() {
138201
FlinkBlueGreenDeploymentSpec spec1 = createBasicSpec();

0 commit comments

Comments
 (0)