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

Add diff logging #191

Conversation

dhaiducek
Copy link
Member

@dhaiducek dhaiducek commented Jan 22, 2024

Adds a recordDiff enum parameter to the ConfigurationPolicy. When set to Log, it uses the go-difflib package to compare the YAML marshalled into strings, with unified output similar to the diff command in the shell. While go-difflib is unmaintained, it's extensively imported, in particular by the stretchr/testify package here.

For simplicity, the diff for objectDefinitions without a name specified are not logged.

Further enhancements could be made by making the diff object-aware. For instance, the ArgoCD diff goes so far as to hack around the Kubernetes library that implements apply. However, I think this is a good, simple implementation as far as an MVP goes and is likely more performant than an object-aware implementation.

ref: https://issues.redhat.com/browse/ACM-9072

@dhaiducek
Copy link
Member Author

dhaiducek commented Jan 22, 2024

Particularly special thanks to @JustinKuli for the initial legwork on this PR. 😄

@dhaiducek dhaiducek force-pushed the 9072-diff-log-option branch 11 times, most recently from a86850f to ff59b81 Compare January 23, 2024 20:42
@dhaiducek
Copy link
Member Author

/hold Okay, this is ready for review now!

@gparvin
Copy link
Member

gparvin commented Jan 23, 2024

This looks good. I only had one minor comment. Thanks Dale!

These tests are flaky on the minimum K8s version:
- operator policy compliance check
- alternative kubeconfig in hosted mode

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
@dhaiducek dhaiducek force-pushed the 9072-diff-log-option branch 3 times, most recently from d717eb7 to cd5d597 Compare January 24, 2024 19:12
mprahl
mprahl previously approved these changes Jan 24, 2024
Copy link
Member

@mprahl mprahl left a comment

Choose a reason for hiding this comment

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

/hold depending on if you want to support OCP 3.11

mprahl
mprahl previously approved these changes Jan 26, 2024
Copy link
Member

@mprahl mprahl left a comment

Choose a reason for hiding this comment

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

/hold for fixing the typo in the log message

@openshift-ci openshift-ci bot added the lgtm label Jan 26, 2024
Adds a `recordDiff` enum parameter to the
`ConfigurationPolicy`. When set to `Log`, it uses
the `go-difflib` package to compare the YAML
marshalled into strings. While `go-difflib` is
unmaintained, it's extensively imported, in
particular by the `stretchr/testify` package here.

For simplicity, the diff for objectDefinitions
without a name specified are not logged.

ref: https://issues.redhat.com/browse/ACM-9072
Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
Copy link
Member

@mprahl mprahl left a comment

Choose a reason for hiding this comment

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

/unhold

Copy link

openshift-ci bot commented Jan 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dhaiducek, mprahl

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants