diff --git a/azure/services/agentpools/spec.go b/azure/services/agentpools/spec.go index 52bf791be24..fe0c9820845 100644 --- a/azure/services/agentpools/spec.go +++ b/azure/services/agentpools/spec.go @@ -294,7 +294,7 @@ func (s *AgentPoolSpec) Parameters(existing interface{}) (params interface{}, er VnetSubnetID: vnetSubnetID, EnableNodePublicIP: s.EnableNodePublicIP, NodePublicIPPrefixID: s.NodePublicIPPrefixID, - Tags: converters.TagsToMap(s.AdditionalTags), + Tags: *to.StringMapPtr(s.AdditionalTags), }, } diff --git a/azure/services/agentpools/spec_test.go b/azure/services/agentpools/spec_test.go index dcbf932ad54..49f6c0ee0e6 100644 --- a/azure/services/agentpools/spec_test.go +++ b/azure/services/agentpools/spec_test.go @@ -26,6 +26,7 @@ import ( "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" "github.com/pkg/errors" + infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -51,6 +52,7 @@ var ( Version: to.StringPtr("fake-version"), VnetSubnetID: "fake-vnet-subnet-id", Headers: map[string]string{"fake-header": "fake-value"}, + AdditionalTags: infrav1.Tags{"fake": "tag"}, } fakeAgentPoolSpecWithoutAutoscaling = AgentPoolSpec{ Name: "fake-agent-pool-name", @@ -73,6 +75,7 @@ var ( Version: to.StringPtr("fake-version"), VnetSubnetID: "fake-vnet-subnet-id", Headers: map[string]string{"fake-header": "fake-value"}, + AdditionalTags: infrav1.Tags{"fake": "tag"}, } fakeAgentPoolSpecWithZeroReplicas = AgentPoolSpec{ Name: "fake-agent-pool-name", @@ -95,6 +98,7 @@ var ( Version: to.StringPtr("fake-version"), VnetSubnetID: "fake-vnet-subnet-id", Headers: map[string]string{"fake-header": "fake-value"}, + AdditionalTags: infrav1.Tags{"fake": "tag"}, } fakeAgentPoolAutoScalingOutOfDate = containerservice.AgentPool{ @@ -241,6 +245,7 @@ func fakeAgentPoolWithProvisioningStateAndCountAndAutoscaling(provisioningState OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), ProvisioningState: state, + Tags: map[string]*string{"fake": to.StringPtr("tag")}, Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, VMSize: to.StringPtr("fake-sku"), VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), @@ -266,6 +271,7 @@ func fakeAgentPoolWithAutoscalingAndCount(enableAutoScaling bool, count int32) c OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), ProvisioningState: to.StringPtr("Succeeded"), + Tags: map[string]*string{"fake": to.StringPtr("tag")}, Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, VMSize: to.StringPtr("fake-sku"), VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), diff --git a/azure/services/managedclusters/spec.go b/azure/services/managedclusters/spec.go index 2295e3760a8..b3add74f0aa 100644 --- a/azure/services/managedclusters/spec.go +++ b/azure/services/managedclusters/spec.go @@ -190,6 +190,7 @@ func (s *ManagedClusterSpec) Parameters(existing interface{}) (params interface{ Type: containerservice.ResourceIdentityTypeSystemAssigned, }, Location: &s.Location, + Tags: *to.StringMapPtr(s.Tags), ManagedClusterProperties: &containerservice.ManagedClusterProperties{ NodeResourceGroup: &s.NodeResourceGroup, EnableRBAC: to.BoolPtr(true), @@ -217,10 +218,6 @@ func (s *ManagedClusterSpec) Parameters(existing interface{}) (params interface{ }, } - if tags := *to.StringMapPtr(s.Tags); len(tags) != 0 { - managedCluster.Tags = tags - } - if s.PodCIDR != "" { managedCluster.NetworkProfile.PodCidr = &s.PodCIDR } @@ -327,6 +324,12 @@ 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 = nil + managedCluster.Tags = nil + } + diff := computeDiffOfNormalizedClusters(managedCluster, existingMC) if diff == "" { return nil, nil diff --git a/azure/services/managedclusters/spec_test.go b/azure/services/managedclusters/spec_test.go index 7ec44439139..74743b3740d 100644 --- a/azure/services/managedclusters/spec_test.go +++ b/azure/services/managedclusters/spec_test.go @@ -134,6 +134,19 @@ func TestParameters(t *testing.T) { g.Expect(result.(containerservice.ManagedCluster).KubernetesVersion).To(Equal(to.StringPtr("v1.22.99"))) }, }, + { + name: "delete all tags", + existing: getExistingCluster(), + spec: &ManagedClusterSpec{ + Tags: nil, + }, + expect: func(g *WithT, result interface{}) { + g.Expect(result).To(BeAssignableToTypeOf(containerservice.ManagedCluster{})) + tags := result.(containerservice.ManagedCluster).Tags + g.Expect(tags).NotTo(BeNil()) + g.Expect(tags).To(BeEmpty()) + }, + }, } for _, tc := range testcases { tc := tc