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

wait for ASO tags to converge before updating #4149

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

nojnhuh
Copy link
Contributor

@nojnhuh nojnhuh commented Oct 17, 2023

What type of PR is this?
/kind bug

What this PR does / why we need it:

From https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/4069/files#r1344633228:

I had noticed a race condition while running the tags e2e test where if the tags have not converged, then CAPZ could lose track of some tags that have been deleted from spec.additionalTags and treat them like tags that existed outside of spec.additionalTags and keep them around without ever deleting them. Waiting for the tags to converge on the ASO resource fixes that issue AFAICT.

Overall, this makes tags reconciliation work more similarly to the more synchronous method used before when calling the tags APIs directly.

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:

Fixed a bug causing some tags on ASO resources not to be deleted

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 17, 2023
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 17, 2023
@nojnhuh
Copy link
Contributor Author

nojnhuh commented Oct 17, 2023

/cherry-pick release-1.11

@k8s-infra-cherrypick-robot

@nojnhuh: once the present PR merges, I will cherry-pick it on top of release-1.11 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.11

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.

@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (5c6f04d) 57.82% compared to head (5b35816) 57.85%.
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4149      +/-   ##
==========================================
+ Coverage   57.82%   57.85%   +0.03%     
==========================================
  Files         187      187              
  Lines       19195    19205      +10     
==========================================
+ Hits        11099    11111      +12     
+ Misses       7468     7466       -2     
  Partials      628      628              
Files Coverage Δ
azure/services/aso/tags.go 93.18% <100.00%> (+2.00%) ⬆️

... and 1 file with indirect coverage changes

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

Copy link
Member

@nawazkh nawazkh left a comment

Choose a reason for hiding this comment

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

Some questions inline.

@@ -710,7 +710,7 @@ func TestCreateOrUpdateResource(t *testing.T) {

specMock.MockTagsGetterSetter.EXPECT().GetActualTags(gomock.Any()).Return(nil)
specMock.MockTagsGetterSetter.EXPECT().GetAdditionalTags().Return(nil)
specMock.MockTagsGetterSetter.EXPECT().GetDesiredTags(gomock.Any()).Return(nil)
specMock.MockTagsGetterSetter.EXPECT().GetDesiredTags(gomock.Any()).Return(nil).Times(2)
Copy link
Member

Choose a reason for hiding this comment

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

specMock.MockTagsGetterSetter.EXPECT().GetDesiredTags(gomock.Any()).Return(nil).Times(2) Does this mean that the test will try to check the chain twice?

Copy link
Member

Choose a reason for hiding this comment

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

Trying to understand, why are we checking two times specifically ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That means this will be called twice or else the test should fail. gomock complains if no count is specified this way and the function is called more than once. Whether we specify .Times(2) or .AnyTimes() doesn't matter to me since the "2" isn't significant other than to get the test to pass.

Copy link
Member

@nawazkh nawazkh Oct 17, 2023

Choose a reason for hiding this comment

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

Okay, I see the reason why we are testing for .Times(2) in this chain.
That is because the func .GetDesiredTags() gets called twice in tags.go. Good granular check. Thanks for adding.

@@ -47,6 +50,14 @@ func reconcileTags[T genruntime.MetaObject](t TagsGetterSetter[T], existing T, r
}

existingTags = t.GetActualTags(existing)
if !reflect.DeepEqual(t.GetDesiredTags(existing), existingTags) &&
Copy link
Member

Choose a reason for hiding this comment

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

Asking out of curiosity since I have not touched this piece of code; How do the tags get merged?
Does this transient error being returned here reflect that CAPZ is waiting for some external agent to "merge" the tags for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tags get merged based on the CAPZ resource and ASO spec and status as defined further down in this function. The tests might help clarify.

A transient error gets returned when we're assuming ASO is actively doing work to reconcile spec.tags and then update status.tags.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense after going over the code below this change.
It would be good to have a short comment summarizing the reason for early return however.

@nawazkh
Copy link
Member

nawazkh commented Oct 17, 2023

/lgtm

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

LGTM label has been added.

Git tree hash: 2b01d27b24620fd9713d7cc3415e1befb736ea27

Copy link
Contributor

@Jont828 Jont828 left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Contributor

@mboersma mboersma left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mboersma

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 Oct 18, 2023
@k8s-ci-robot k8s-ci-robot merged commit 925e7ad into kubernetes-sigs:main Oct 18, 2023
10 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.12 milestone Oct 18, 2023
@k8s-infra-cherrypick-robot

@nojnhuh: #4149 failed to apply on top of branch "release-1.11":

Applying: wait for ASO tags to converge before updating
Using index info to reconstruct a base tree...
M	azure/services/aso/aso_test.go
M	azure/services/aso/tags.go
M	azure/services/aso/tags_test.go
Falling back to patching base and 3-way merge...
Auto-merging azure/services/aso/tags_test.go
CONFLICT (content): Merge conflict in azure/services/aso/tags_test.go
Auto-merging azure/services/aso/tags.go
CONFLICT (content): Merge conflict in azure/services/aso/tags.go
Auto-merging azure/services/aso/aso_test.go
CONFLICT (content): Merge conflict in azure/services/aso/aso_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 wait for ASO tags to converge before updating
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-1.11

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants