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

OCPBUGS-16735: Truncate existing files when writing from inspect #1520

Merged
merged 1 commit into from Jul 26, 2023

Conversation

MarSik
Copy link
Contributor

@MarSik MarSik commented Jul 25, 2023

oc adm inspect generated files sometime have the leading "---" and some time do not. This depends on the order of objects collected. This by itself is not an issue.

However this becomes an issue when combined with multiple invocations of oc adm inspect and collecting data to the same directory like must-gather does.

If an object is collected multiple times then the second time oc might overwrite the original file improperly and leave 4 bytes of the original content behind.

This is happening when not writing the "---\n" in the second invocation as this makes the content 4B shorter and the original tailing 4B are left in the file intact.

This garbage confuses YAML parsers.

oc adm inspect generated files sometime have the leading "---"
and some time do not. This depends on the order of objects collected.
This by itself is not an issue.

However this becomes an issue when combined with multiple
invocations of oc adm inspect and collecting data to the same
directory like must-gather does.

If an object is collected multiple times then the second time
oc might overwrite the original file improperly and leave 4 bytes
of the original content behind.

This is happening when not writing the "---\n" in the second
invocation as this makes the content 4B shorter and the original
tailing 4B are left in the file intact.

This garbage confuses YAML parsers.

Signed-off-by: Martin Sivak <msivak@redhat.com>
@openshift-ci-robot openshift-ci-robot added jira/severity-important Referenced Jira bug's severity is important for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jul 25, 2023
@openshift-ci-robot
Copy link

@MarSik: This pull request references Jira Issue OCPBUGS-16735, which is invalid:

  • expected the bug to target the "4.14.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

oc adm inspect generated files sometime have the leading "---" and some time do not. This depends on the order of objects collected. This by itself is not an issue.

However this becomes an issue when combined with multiple invocations of oc adm inspect and collecting data to the same directory like must-gather does.

If an object is collected multiple times then the second time oc might overwrite the original file improperly and leave 4 bytes of the original content behind.

This is happening when not writing the "---\n" in the second invocation as this makes the content 4B shorter and the original tailing 4B are left in the file intact.

This garbage confuses YAML parsers.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot requested review from ardaguclu and mfojtik July 25, 2023 10:37
@MarSik
Copy link
Contributor Author

MarSik commented Jul 25, 2023

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jul 25, 2023
@openshift-ci-robot
Copy link

@MarSik: This pull request references Jira Issue OCPBUGS-16735, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.14.0) matches configured target version for branch (4.14.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @zhouying7780

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot requested a review from zhouying7780 July 25, 2023 10:38
@@ -51,7 +51,7 @@ func (r *resourceWriterReadCloser) Close() error {
type simpleFileWriter struct{}

func (f *simpleFileWriter) Write(filepath string, src fileWriterSource) error {
dest, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE, 0755)
dest, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
Copy link
Member

Choose a reason for hiding this comment

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

In terms of yaml files generated by oc adm inspect command, this is indeed a problem and I'm supportive of this change.

On the other hand, this writer is also used for saving the collected logs of pods, operators, etc. and I think, we should ensure that this change will not cause truncating the logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well this always starts writing from the beginning, so it will either overwrite from the beginning (causing the same bug) or drop the "old" data. The only way to behave differently would be to pass O_APPEND.

Or is there something I am missing?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you @MarSik. Since we are not passing O_APPEND, we are already overwriting on the old data and it would be good to truncate it.

Thanks for fixing this.

@ardaguclu
Copy link
Member

/lgtm
/hold
until checking the must-gather of CI jobs

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 25, 2023
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 25, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 25, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ardaguclu, MarSik

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 25, 2023
@MarSik
Copy link
Contributor Author

MarSik commented Jul 25, 2023

e2e-aws-ovn looks good to me, the bug is not present in the generated must-gather and logs are there.

@ardaguclu
Copy link
Member

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 25, 2023
@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD 643b040 and 2 for PR HEAD 5d39398 in total

@MarSik
Copy link
Contributor Author

MarSik commented Jul 26, 2023

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 26, 2023

@MarSik: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot merged commit 13225e0 into openshift:master Jul 26, 2023
12 checks passed
@openshift-ci-robot
Copy link

@MarSik: Jira Issue OCPBUGS-16735: All pull requests linked via external trackers have merged:

Jira Issue OCPBUGS-16735 has been moved to the MODIFIED state.

In response to this:

oc adm inspect generated files sometime have the leading "---" and some time do not. This depends on the order of objects collected. This by itself is not an issue.

However this becomes an issue when combined with multiple invocations of oc adm inspect and collecting data to the same directory like must-gather does.

If an object is collected multiple times then the second time oc might overwrite the original file improperly and leave 4 bytes of the original content behind.

This is happening when not writing the "---\n" in the second invocation as this makes the content 4B shorter and the original tailing 4B are left in the file intact.

This garbage confuses YAML parsers.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sferich888
Copy link
Contributor

/cherry-pick release-4.13

@openshift-cherrypick-robot

@sferich888: new pull request created: #1553

In response to this:

/cherry-pick release-4.13

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/severity-important Referenced Jira bug's severity is important for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants