Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use ignoreList in GenericKubernetesResourceMatcher #2050

Merged
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 @@ -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