Skip to content

Remove the direct depedency on gopkg.in/yaml.v2. #1027

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

Merged
merged 3 commits into from
Mar 12, 2025

Conversation

renormalize
Copy link
Member

@renormalize renormalize commented Mar 11, 2025

How to categorize this PR?

/area dev-productivity
/kind cleanup

What this PR does / why we need it:

  • gopkg.in/yaml.v2 was a direct dependency only because one file internal/component/configmap/configmap.go used it to marshal yaml. This direct depdendency is removed by replacing it with the package sigs.k8s.io/yaml used everywhere else in the repository to maintain consistency.

  • Replace yaml with json struct tags since sigs.k8s.io/yaml first marshals the struct to a json, and then yaml. When yaml tags are specified, the specified tags are not used when marshalling to json, which causes the intermediate json values to have the keys as the struct field names, causing the final yaml also to have the struct field names as the keys.

  • Make omitempty fields pointers. The general convention for fields which are omitempty is to make them pointers. If not, the fields will be their zero values which is not the intended marshalled output.

  • Replace C-like for loops with range for loops for readability.

Release note:

Remove the direct depedency on `gopkg.in/yaml.v2`.

@renormalize renormalize added the dependencies Pull requests that update a dependency file label Mar 11, 2025
@renormalize renormalize self-assigned this Mar 11, 2025
@renormalize renormalize requested a review from a team as a code owner March 11, 2025 08:30
@gardener-robot gardener-robot added needs/review Needs review area/dev-productivity Developer productivity related (how to improve development) kind/cleanup Something that is not needed anymore and can be cleaned up size/xs Size of pull request is tiny (see gardener-robot robot/bots/size.py) labels Mar 11, 2025
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 11, 2025
@gardener gardener deleted a comment from gardener-prow bot Mar 11, 2025
* `gopkg.in/yaml.v2` was a direct dependency only because one file
  `internal/component/configmap/configmap.go` used it to marshal yaml.
  This direct depdendency is removed by replacing it with the package
  `sigs.k8s.io/yaml` used everywhere else in the repository to maintain
  consistency.

* Replace `yaml` with `json` struct tags since `sigs.k8s.io/yaml`
  first marshals the `struct` to a json, and then yaml.
  When `yaml` tags are specified, the specified tags are not
  used when marshalling to `json`, which causes the intermediate
  json values to have the keys as the `struct` field names, causing
  the final yaml also to have the struct field names as the keys.
Copy link
Contributor

@seshachalam-yv seshachalam-yv left a comment

Choose a reason for hiding this comment

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

Thanks, @renormalize, for replacing the direct dependency with sigs.k8s.io/yaml!

/lgtm
/approve

@gardener-robot gardener-robot added the reviewed/lgtm Has approval for merging label Mar 12, 2025
@gardener gardener deleted a comment from gardener-robot Mar 12, 2025
@gardener-robot gardener-robot removed the needs/review Needs review label Mar 12, 2025
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 12, 2025
@seshachalam-yv

This comment was marked as outdated.

@gardener-robot gardener-robot added size/s Size of pull request is small (see gardener-robot robot/bots/size.py) and removed size/xs Size of pull request is tiny (see gardener-robot robot/bots/size.py) labels Mar 12, 2025
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 12, 2025
* The general convention for fields which are
  `omitempty` is to make them pointers. If not,
  the fields will be their zero values which is not
  the intended marshalled output.
@gardener-robot-ci-1 gardener-robot-ci-1 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 12, 2025
@seshachalam-yv seshachalam-yv merged commit 49df2dc into gardener:master Mar 12, 2025
15 checks passed
@gardener-robot gardener-robot added the status/closed Issue is closed (either delivered or triaged) label Mar 12, 2025
@renormalize renormalize deleted the yaml branch March 12, 2025 09:22
@shreyas-s-rao shreyas-s-rao added this to the v0.28.0 milestone Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dev-productivity Developer productivity related (how to improve development) dependencies Pull requests that update a dependency file kind/cleanup Something that is not needed anymore and can be cleaned up needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) reviewed/lgtm Has approval for merging size/s Size of pull request is small (see gardener-robot robot/bots/size.py) status/closed Issue is closed (either delivered or triaged)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants