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

fix deleting all tags on AKS resources #2916

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

nojnhuh
Copy link
Contributor

@nojnhuh nojnhuh commented Dec 8, 2022

What type of PR is this?
/kind bug

What this PR does / why we need it: When spec.additionalTags are defined on AzureManagedControlPlane or AzureManagedMachinePool resources, setting them to null or empty does not delete all tags because the resulting PUT request specifies null tags which seems to be interpreted by AKS as "do not change the tags." This change ensures that if the tags are specified in the CAPZ resources as null, then a non-nil, empty set of tags are sent to the AKS API to express "please delete all of the existing tags."

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: I came across this issue while implementing an e2e test covering this scenario (currently drafted in #2917). Those tests verify this new behavior for me locally. Additional context in #2745 (comment) and #2802.

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

Fixed a bug preventing `spec.additionalTags` from being deleted entirely on AzureManagedControlPlane

Note: spec.additionalTags is not yet implemented for AzureManagedMachinePools in any tagged release

@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 Dec 8, 2022
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 8, 2022
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 8, 2022
@@ -327,6 +324,11 @@ func (s *ManagedClusterSpec) Parameters(existing interface{}) (params interface{
// AgentPool changes are managed through AMMP.
managedCluster.AgentPoolProfiles = existingMC.AgentPoolProfiles

// Do not trigger an update because of nil/empty discrepancies between the two sets of tags.
if len(existingMC.Tags) == 0 && len(managedCluster.Tags) == 0 {
existingMC.Tags = managedCluster.Tags
Copy link
Contributor

Choose a reason for hiding this comment

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

would this be better?

existingMC.Tags, managedCluster.Tags = nil, nil

setting the "existing" to the "local" seems to suggest we're preferring the "local" value, when in fact what we're really trying to do is to ensure that they both have the same value so that a diff isn't computed between them

is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose what I was trying to enforce here is that the resulting managedCluster.Tags always resolves to a non-nil, empty map when the spec.additionalTags are nil or empty. But I see now that it looks fine for managedCluster.Tags to be nil when existingMC.Tags is also empty since our desired state already matches the actual state in that case. Overall I think your suggestion is a bit more clear so I'll test that to make sure it works and make that change unless I run into any issues.

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 9, 2022

/retest

@nawazkh
Copy link
Member

nawazkh commented Dec 9, 2022

Great find!
/lgtm

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jackfrancis

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 Dec 9, 2022
@jackfrancis
Copy link
Contributor

/cherry-pick release-1.5

@k8s-infra-cherrypick-robot

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

In response to this:

/cherry-pick release-1.5

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.

@jackfrancis
Copy link
Contributor

/cherry-pick release-1.6

@k8s-infra-cherrypick-robot

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

In response to this:

/cherry-pick release-1.6

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.

@k8s-ci-robot k8s-ci-robot merged commit 3385690 into kubernetes-sigs:main Dec 9, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.7 milestone Dec 9, 2022
@k8s-infra-cherrypick-robot

@jackfrancis: #2916 failed to apply on top of branch "release-1.5":

Applying: fix deleting all tags on AKS resources
Using index info to reconstruct a base tree...
M	azure/services/agentpools/spec.go
M	azure/services/agentpools/spec_test.go
M	azure/services/managedclusters/spec_test.go
Falling back to patching base and 3-way merge...
Auto-merging azure/services/managedclusters/spec_test.go
Auto-merging azure/services/agentpools/spec_test.go
CONFLICT (content): Merge conflict in azure/services/agentpools/spec_test.go
Auto-merging azure/services/agentpools/spec.go
CONFLICT (content): Merge conflict in azure/services/agentpools/spec.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 fix deleting all tags on AKS resources
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.5

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.

@k8s-infra-cherrypick-robot

@jackfrancis: #2916 failed to apply on top of branch "release-1.6":

Applying: fix deleting all tags on AKS resources
Using index info to reconstruct a base tree...
M	azure/services/agentpools/spec.go
M	azure/services/managedclusters/spec_test.go
Falling back to patching base and 3-way merge...
Auto-merging azure/services/managedclusters/spec_test.go
Auto-merging azure/services/agentpools/spec.go
CONFLICT (content): Merge conflict in azure/services/agentpools/spec.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 fix deleting all tags on AKS resources
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.6

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.

@jackfrancis
Copy link
Contributor

nevermind the cherry-picks, the AdditionalTags feature was only introduced in the current release cycle, it doesn't exist as a feature in 1.6 or below.

@nojnhuh nojnhuh deleted the tag-delete branch December 12, 2022 16:13
@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 12, 2022

nevermind the cherry-picks, the AdditionalTags feature was only introduced in the current release cycle, it doesn't exist as a feature in 1.6 or below.

The field is new for AzureManagedMachinePools, but this issue does affect AzureManagedControlPlane's spec.additionalTags on 1.6 and 1.5, so I'll work on manual cherry-picks for those.

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
None yet
Development

Successfully merging this pull request may close these issues.

5 participants