Skip to content

Commit

Permalink
fix deleting all tags on AKS resources
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Dec 9, 2022
1 parent e0d9257 commit 3263a28
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion azure/services/agentpools/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}

Expand Down
6 changes: 6 additions & 0 deletions azure/services/agentpools/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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{
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
11 changes: 7 additions & 4 deletions azure/services/managedclusters/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions azure/services/managedclusters/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3263a28

Please sign in to comment.