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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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