Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public static <R extends HasMetadata, P extends HasMetadata> Matcher.Result<R> m
final var kubernetesSerialization = context.getClient().getKubernetesSerialization();
var desiredNode = kubernetesSerialization.convertValue(desired, JsonNode.class);
var actualNode = kubernetesSerialization.convertValue(actualResource, JsonNode.class);
var wholeDiffJsonPatch = JsonDiff.asJson(desiredNode, actualNode);
// move and copy operations would hide additions and removals from the checks below
var wholeDiffJsonPatch =
JsonDiff.asJson(desiredNode, actualNode, DiffFlags.dontNormalizeOpIntoMoveAndCopy());

boolean matched = true;
for (int i = 0; i < wholeDiffJsonPatch.size() && matched; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,47 @@ void matchesAdditiveOnlyChanges() {
.isTrue();
}

@Test
void matchesAdditiveChangesWithValueEqualToAnExistingValue() {
var desired =
new ServiceBuilder()
.withNewMetadata()
.withName("test")
.endMetadata()
.withNewSpec()
.addNewPort()
.withPort(80)
.endPort()
.endSpec()
.build();
// the API server defaults targetPort to the value of port
var actual =
new ServiceBuilder(desired)
.editSpec()
.editFirstPort()
.withTargetPort(new IntOrString(80))
.endPort()
.endSpec()
.build();
assertThat(GenericKubernetesResourceMatcher.match(desired, actual, context).matched())
.withFailMessage(
"Additive changes should not cause a mismatch even if the added value equals an"
+ " existing one")
.isTrue();
}

@Test
void doesNotMatchRemovedValueAddedBackUnderIgnoredPath() {
actual = createDeployment();
// revisionHistoryLimit is 10 in desired, the added priority has the same value
actual.getSpec().setRevisionHistoryLimit(null);
actual.getSpec().getTemplate().getSpec().setPriority(10);
assertThat(
match(dependentResource, actual, null, context, false, "/spec/template/spec").matched())
.withFailMessage("Removing values outside of ignored paths should lead to a mismatch")
.isFalse();
}

@Test
void matchesWithStrongSpecEquality() {
actual.getSpec().getTemplate().getMetadata().getLabels().put("new-key", "val");
Expand Down
Loading