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

refactor ASO label/annotation updates #3733

Merged
merged 1 commit into from
Jul 31, 2023

Conversation

nojnhuh
Copy link
Contributor

@nojnhuh nojnhuh commented Jul 17, 2023

What type of PR is this?
/kind cleanup

What this PR does / why we need it:

This PR refactors how labels and annotations applied generically to ASO resources are constructed to enable delete()-ing existing labels or annotations which is planned for #3525. Otherwise this change should be functionally equivalent.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

  • cherry-pick candidate

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

NONE

@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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 17, 2023
@codecov
Copy link

codecov bot commented Jul 17, 2023

Codecov Report

Patch coverage: 85.71% and no project coverage change.

Comparison is base (38f68d0) 54.12% compared to head (fd23170) 54.12%.
Report is 24 commits behind head on main.

❗ Current head fd23170 differs from pull request most recent head fdf0610. Consider uploading reports for the commit fdf0610 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3733   +/-   ##
=======================================
  Coverage   54.12%   54.12%           
=======================================
  Files         187      187           
  Lines       18909    18917    +8     
=======================================
+ Hits        10234    10239    +5     
- Misses       8126     8128    +2     
- Partials      549      550    +1     
Files Changed Coverage Δ
azure/services/aso/aso.go 92.78% <85.71%> (-1.31%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

if len(labels) > 0 {
parameters.SetLabels(maps.Merge(parameters.GetLabels(), labels))
if len(labels) == 0 {
labels = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to set labels and annotations back to nil? Would it make sense instead to call SetLabels() and SetAnnotations() only when existing == nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we want to set labels and annotations back to nil?

Because labels and annotations are both serialized with omitempty, the existing resource will never contain empty, non-nil values for either of those fields. This preemptively emulates omitempty for the values of parameters so when we calculate the diff just below these changes, we don't treat a non-nil and empty map as different from a nil one since they would both be serialized as nil.

Would it make sense instead to call SetLabels() and SetAnnotations() only when existing == nil?

Any update (when existing != nil) may require labels and/or annotations to be updated (like when we notice a resource needs to be adopted), so I don't think that would work in all cases.

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Jul 18, 2023

(squash reminder)
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 18, 2023
Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@willie-yao willie-yao left a comment

Choose a reason for hiding this comment

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

/lgtm

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

LGTM label has been added.

Git tree hash: 2ea8eeb4a1842a99c8c97ab5f2da157063a2e71b

@Jont828
Copy link
Contributor

Jont828 commented Jul 28, 2023

/lgtm

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Jul 31, 2023

(squash reminder) /hold

done!
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 31, 2023
@nojnhuh
Copy link
Contributor Author

nojnhuh commented Jul 31, 2023

/retest

Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CecileRobertMichon

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 Jul 31, 2023
@k8s-ci-robot k8s-ci-robot merged commit b6cde9b into kubernetes-sigs:main Jul 31, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.11 milestone Jul 31, 2023
@nojnhuh nojnhuh deleted the aso-maps branch August 10, 2023 15:25
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. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants