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

keps: centralize yaml calls, use UnmarshalStrict #2870

Merged
merged 3 commits into from
Aug 17, 2021

Conversation

spiffxp
Copy link
Member

@spiffxp spiffxp commented Aug 17, 2021

Prompted by
#2867 (comment)
I decided it would be worth having tests enforce that fields in
KEP-related yaml are well known (vs. allowing addition of unknown
fields)

This codebase largely used gopkg.in/yaml.v3 but also sigs.k8s.io/yaml in
some places, which each have different ways of accomplishing "return
error if there are unknown or duplicate fields" functionality. I opted
to pull calls to yaml.Unmarshal and yaml.Marshal into a helper
package, k8s.io/enhancements/pkg/yaml, so there's only one place to
change for yaml-related changes.

I then converged on a gopkg.in/yaml.v3 implementation of
yaml.UnmarshalStrict to accomplish erroring on unknown fields, and
corrected the KEPs that failed tests as a result. The reasoning for
choice of library was: most everything already used it, and it supports
preserving comments (not that the code as-written does). I don't feel
strongly about switching it back to sigs.k8s.io/yaml though if that's
the preference

The ony controversial change was to support the KEP that added
"deprecated" and "removed" milestones. I opted to add those to the API
but am open to suggestion on how that could be better encoded in the
Proposal struct that we have today.

Centralize yaml unmarshalling to k8s.io/enhancements/yaml and add an
UnmarshalStrict() function implemented using gopkg.in/yaml.v3

Somehow all of gopkg.in/yaml.v2, gopkg.in/yaml.v3 and sigs.k8s.io/yaml
were being used across the code. Hopefully this unifies and lets us
choose just one.

Update KEPs to fix unmarshalling failures. The one controversial change
would be to support the KEP that added "deprecated" and "removed"
milestones. I opted to add those to the API, but am open to suggestion
on how that planned lifecycle should be encoded in the KEP instead.
In service of centralizing the one package that decides which yaml
library to use
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/enhancements Issues or PRs related to the Enhancements subproject labels Aug 17, 2021
@k8s-ci-robot k8s-ci-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. labels Aug 17, 2021
@spiffxp
Copy link
Member Author

spiffxp commented Aug 17, 2021

/cc @kikisdeliveryservice

@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@justaugustus
Copy link
Member

The ony controversial change was to support the KEP that added
"deprecated" and "removed" milestones. I opted to add those to the API
but am open to suggestion on how that could be better encoded in the
Proposal struct that we have today.

Fine to move forward with that change and iterate as needed.
Thanks for the fixes, @spiffxp!!

/lgtm
/approve

@justaugustus justaugustus added this to the keps-beta milestone Aug 17, 2021
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 17, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justaugustus, spiffxp

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 17, 2021
@k8s-ci-robot k8s-ci-robot merged commit d037553 into kubernetes:master Aug 17, 2021
@k8s-ci-robot k8s-ci-robot modified the milestones: keps-beta, v1.23 Aug 17, 2021
@spiffxp spiffxp deleted the unmarshal-strict branch August 27, 2021 11:18
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. area/enhancements Issues or PRs related to the Enhancements subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants