Skip to content

Commit

Permalink
improve: re-use ignoreList in GenericKubernetesResourceMatcher (#2050)
Browse files Browse the repository at this point in the history
Signed-off-by: David Sondermann <[email protected]>
  • Loading branch information
Donnerbart authored Sep 11, 2023
1 parent ddd7c42 commit 85e65ed
Showing 1 changed file with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,17 @@ public static <R extends HasMetadata, P extends HasMetadata> Result<R> match(R d
}
}

final var matched = matchSpec(actualResource, desired, specEquality, context, ignoredPaths);
final var matched = matchSpec(actualResource, desired, specEquality, context, ignoreList);
return Result.computed(matched, desired);
}

private static <R extends HasMetadata> boolean matchSpec(R actual, R desired, boolean equality,
Context<?> context,
String[] ignoredPaths) {

Context<?> context, List<String> ignoreList) {
final var kubernetesSerialization = context.getClient().getKubernetesSerialization();
var desiredNode = kubernetesSerialization.convertValue(desired, JsonNode.class);
var actualNode = kubernetesSerialization.convertValue(actual, JsonNode.class);
var wholeDiffJsonPatch = JsonDiff.asJson(desiredNode, actualNode);

final List<String> ignoreList =
ignoredPaths != null && ignoredPaths.length > 0 ? Arrays.asList(ignoredPaths)
: Collections.emptyList();
// reflection will be replaced by this:
// https://github.com/fabric8io/kubernetes-client/issues/3816
var specDiffJsonPatch = getDiffsImpactingPathsWithPrefixes(wholeDiffJsonPatch, SPEC);
Expand All @@ -218,15 +213,10 @@ private static <R extends HasMetadata> boolean matchSpec(R actual, R desired, bo
return false;
}
if (!equality && !ignoreList.isEmpty()) {
if (!allDiffsOnIgnoreList(specDiffJsonPatch, ignoreList)) {
return false;
}
return allDiffsOnIgnoreList(specDiffJsonPatch, ignoreList);
} else {
if (!allDiffsAreAddOps(specDiffJsonPatch)) {
return false;
}
return allDiffsAreAddOps(specDiffJsonPatch);
}
return true;
}

private static boolean allDiffsOnIgnoreList(List<JsonNode> metadataJSonDiffs,
Expand All @@ -241,7 +231,6 @@ private static <R extends HasMetadata, P extends HasMetadata> Optional<Result<R>
R desired,
R actualResource,
boolean labelsAndAnnotationsEquality, Context<P> context) {

if (labelsAndAnnotationsEquality) {
final var desiredMetadata = desired.getMetadata();
final var actualMetadata = actualResource.getMetadata();
Expand Down

0 comments on commit 85e65ed

Please sign in to comment.