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

feat: print diff resource as yaml #2542

Merged
Merged
Changes from 5 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 @@ -104,12 +104,23 @@ public boolean matches(R actual, R desired, Context<?> context) {
removeIrrelevantValues(desiredMap);

if (LoggingUtils.isNotSensitiveResource(desired)) {
log.debug("Pruned actual: \n {} \n desired: \n {} ", prunedActual, desiredMap);
logDiff(prunedActual, desiredMap, objectMapper);
}

return prunedActual.equals(desiredMap);
}

private void logDiff(Map<String, Object> prunedActualMap, Map<String, Object> desiredMap,
KubernetesSerialization serialization) {
if (log.isDebugEnabled()) {
var actualYaml = serialization.asYaml(prunedActualMap);
var desiredYaml = serialization.asYaml(desiredMap);
log.debug("Pruned actual yaml: \n {} \n desired yaml: \n {} ", actualYaml, desiredYaml);
} else {
log.debug("Pruned actual map: \n {} \n desired map: \n {} ", prunedActualMap, desiredMap);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I follow this. "If debug is not enabled we log something on debug" ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, missed that, though there should actually be no output since debug is checked internally (iirc) but it does make sense to remove the else branch altogether, indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/operator-framework/java-operator-sdk/pull/2542/files#diff-7568f2dc58ce3a6a5d7ce2d5227aeb49402136b091fb19a4d8cadb28351ce709L107

we remain the debug logging regardless of whether the debug mode was enabled.
Would it be better to remove the else block?

Although the cost of the else block itself doesn't seem significant, I'd like to hear your thoughts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that the else block never logs any message, since only called if no debug is enabled but logs on debug level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@csviri

Ah understand

96920ab

I thought it would be better to just remove this part, so I modified it as shown above. What do you think?

}
}

/**
* Correct for known issue with SSA
*/
Expand Down
Loading