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

Detect and clean up unneeded after_roundtrip fixtures #116384

Merged
merged 1 commit into from Mar 10, 2023

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented Mar 8, 2023

/kind cleanup

Detects and removes unnecessary "after_roundtrip" fixtures which are identical to their original files.

cleans up four that crept in accidentally, these were identical to their original fixtures:

diff staging/src/k8s.io/api/testdata/v1.25.0/core.v1.ListOptions{,.after_roundtrip}.pb
diff staging/src/k8s.io/api/testdata/v1.26.0/core.v1.ListOptions{,.after_roundtrip}.pb
diff staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy{,.after_roundtrip}.json
diff staging/src/k8s.io/api/testdata/v1.26.0/admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy{,.after_roundtrip}.yaml
NONE

/sig api-machinery
/assign @lavalamp

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 8, 2023
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Mar 8, 2023
@liggitt liggitt marked this pull request as ready for review March 8, 2023 16:39
@k8s-ci-robot k8s-ci-robot requested a review from dims March 8, 2023 16:39
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 8, 2023
@k8s-ci-robot k8s-ci-robot requested a review from sttts March 8, 2023 16:39
@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 8, 2023
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 8, 2023
@liggitt liggitt mentioned this pull request Mar 8, 2023
@@ -364,6 +364,12 @@ func writeFile(t *testing.T, dir string, gvk schema.GroupVersionKind, suffix, ex
}
}

func deleteFile(t *testing.T, dir string, gvk schema.GroupVersionKind, suffix, extension string) {
if err := os.Remove(filepath.Join(dir, makeName(gvk)+suffix+"."+extension)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

File not found errors should probably be tolerated?

Copy link
Member Author

Choose a reason for hiding this comment

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

eh, we only call this if the file exists and we want to remove ... not sure I care

expectedJSONAfterRoundTrip, expectedYAMLAfterRoundTrip, expectedProtoAfterRoundTrip, _ := read(previousVersionDir, gvk, ".after_roundtrip", usedFiles)
if len(expectedJSONAfterRoundTrip) == 0 {
expectedJSONAfterRoundTrip = jsonBeforeRoundTrip
} else if bytes.Equal(jsonBeforeRoundTrip, expectedJSONAfterRoundTrip) {
t.Errorf("JSON after_roundtrip file is identical and should be removed")
Copy link
Member

Choose a reason for hiding this comment

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

How did we get such a file in the first place?

What if one or both buffers is not in canonical form?

Copy link
Member Author

Choose a reason for hiding this comment

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

How did we get such a file in the first place?

probably iterating on a PR in a way that make update created the after_roundtrip (like starting a new optional field as a non-pointer, make update created an after_roundtrip file, then later fixing the new field to be a pointer and make update regenerates after_roundtrip (since it exists) but the content is now identical to the original fixture

Copy link
Member Author

Choose a reason for hiding this comment

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

What if one or both buffers is not in canonical form?

not sure what you mean, the files are generated by our encoding so are canonical

@liggitt
Copy link
Member Author

liggitt commented Mar 8, 2023

#116364 flake
/retest

@liggitt
Copy link
Member Author

liggitt commented Mar 9, 2023

/retest

@lavalamp
Copy link
Member

lavalamp commented Mar 9, 2023

/lgtm
/approve

since it's only devs exercising this once in a while probably don't need to worry about the corner cases

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 9, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: beaf51b0fc4097168e04f9a9d746efaa48486a61

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp, liggitt

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

@cici37
Copy link
Contributor

cici37 commented Mar 9, 2023

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 9, 2023
@k8s-ci-robot k8s-ci-robot merged commit 6105018 into kubernetes:master Mar 10, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.27 milestone Mar 10, 2023
@jiahuif
Copy link
Member

jiahuif commented Mar 10, 2023

Any change to admissionregistration.k8s.io.v1alpha1.ValidatingAdmissionPolicy API would regenerate the deleted files. We need to do this PR again when the API changes are finalized for this release.

@liggitt
Copy link
Member Author

liggitt commented Mar 10, 2023

if there's a change, it's fine to have an after_roundtrip file created. this PR was cleaning up after_roundtrip files that were identical to their original files

@liggitt liggitt deleted the fixup-after-roundtrip branch May 9, 2023 18:26
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants