From 936dfc12efb170e2e70da68071a9db832cdfdd8d Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Wed, 26 Jul 2023 16:39:34 -0500 Subject: [PATCH] fix bug preventing AKS autoscaling from being disabled --- azure/scope/managedmachinepool.go | 2 +- azure/scope/managedmachinepool_test.go | 2 +- azure/services/agentpools/spec.go | 8 ++++---- azure/services/agentpools/spec_test.go | 4 ++-- azure/services/managedclusters/spec_test.go | 2 ++ controllers/azuremanagedmachinepool_controller_test.go | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/azure/scope/managedmachinepool.go b/azure/scope/managedmachinepool.go index a09cba4a8a7..d2185997341 100644 --- a/azure/scope/managedmachinepool.go +++ b/azure/scope/managedmachinepool.go @@ -209,7 +209,7 @@ func buildAgentPoolSpec(managedControlPlane *infrav1.AzureManagedControlPlane, } if managedMachinePool.Spec.Scaling != nil { - agentPoolSpec.EnableAutoScaling = pointer.Bool(true) + agentPoolSpec.EnableAutoScaling = true agentPoolSpec.MaxCount = managedMachinePool.Spec.Scaling.MaxSize agentPoolSpec.MinCount = managedMachinePool.Spec.Scaling.MinSize } diff --git a/azure/scope/managedmachinepool_test.go b/azure/scope/managedmachinepool_test.go index 971f07ee6b2..56a29dcbae8 100644 --- a/azure/scope/managedmachinepool_test.go +++ b/azure/scope/managedmachinepool_test.go @@ -108,7 +108,7 @@ func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { Mode: "User", Cluster: "cluster1", Replicas: 1, - EnableAutoScaling: pointer.Bool(true), + EnableAutoScaling: true, MinCount: pointer.Int32(2), MaxCount: pointer.Int32(10), VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", diff --git a/azure/services/agentpools/spec.go b/azure/services/agentpools/spec.go index df444f49b0a..296f8c86935 100644 --- a/azure/services/agentpools/spec.go +++ b/azure/services/agentpools/spec.go @@ -101,7 +101,7 @@ type AgentPoolSpec struct { NodeTaints []string `json:"nodeTaints,omitempty"` // EnableAutoScaling - Whether to enable auto-scaler - EnableAutoScaling *bool `json:"enableAutoScaling,omitempty"` + EnableAutoScaling bool `json:"enableAutoScaling,omitempty"` // AvailabilityZones represents the Availability zones for nodes in the AgentPool. AvailabilityZones []string @@ -211,7 +211,7 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p Count: &s.Replicas, OrchestratorVersion: s.Version, Mode: containerservice.AgentPoolMode(s.Mode), - EnableAutoScaling: s.EnableAutoScaling, + EnableAutoScaling: pointer.Bool(s.EnableAutoScaling), MinCount: s.MinCount, MaxCount: s.MaxCount, NodeLabels: s.NodeLabels, @@ -247,7 +247,7 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p // When autoscaling is set, the count of the nodes differ based on the autoscaler and should not depend on the // count present in MachinePool or AzureManagedMachinePool, hence we should not make an update API call based // on difference in count. - if pointer.BoolDeref(s.EnableAutoScaling, false) { + if s.EnableAutoScaling { normalizedProfile.Count = existingProfile.Count } @@ -357,7 +357,7 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ AvailabilityZones: availabilityZones, Count: &s.Replicas, - EnableAutoScaling: s.EnableAutoScaling, + EnableAutoScaling: pointer.Bool(s.EnableAutoScaling), EnableUltraSSD: s.EnableUltraSSD, KubeletConfig: kubeletConfig, KubeletDiskType: containerservice.KubeletDiskType(pointer.StringDeref((*string)(s.KubeletDiskType), "")), diff --git a/azure/services/agentpools/spec_test.go b/azure/services/agentpools/spec_test.go index 38eec9e8039..e519050fad4 100644 --- a/azure/services/agentpools/spec_test.go +++ b/azure/services/agentpools/spec_test.go @@ -38,7 +38,7 @@ func fakeAgentPool(changes ...func(*AgentPoolSpec)) AgentPoolSpec { ResourceGroup: "fake-rg", Cluster: "fake-cluster", AvailabilityZones: []string{"fake-zone"}, - EnableAutoScaling: pointer.Bool(true), + EnableAutoScaling: true, EnableUltraSSD: pointer.Bool(true), KubeletDiskType: (*infrav1.KubeletDiskType)(pointer.String("fake-kubelet-disk-type")), MaxCount: pointer.Int32(5), @@ -73,7 +73,7 @@ func withReplicas(replicas int32) func(*AgentPoolSpec) { func withAutoscaling(enabled bool) func(*AgentPoolSpec) { return func(pool *AgentPoolSpec) { - pool.EnableAutoScaling = pointer.Bool(enabled) + pool.EnableAutoScaling = enabled } } diff --git a/azure/services/managedclusters/spec_test.go b/azure/services/managedclusters/spec_test.go index 0f94e7deaf5..3e902305528 100644 --- a/azure/services/managedclusters/spec_test.go +++ b/azure/services/managedclusters/spec_test.go @@ -348,6 +348,7 @@ func getSampleManagedCluster() containerservice.ManagedCluster { Tags: map[string]*string{ "test-tag": pointer.String("test-value"), }, + EnableAutoScaling: pointer.Bool(false), }, { Name: pointer.String("test-agentpool-1"), @@ -363,6 +364,7 @@ func getSampleManagedCluster() containerservice.ManagedCluster { Tags: map[string]*string{ "test-tag": pointer.String("test-value"), }, + EnableAutoScaling: pointer.Bool(false), }, }, LinuxProfile: &containerservice.LinuxProfile{ diff --git a/controllers/azuremanagedmachinepool_controller_test.go b/controllers/azuremanagedmachinepool_controller_test.go index 629b6b923d1..6c0fae2b4a5 100644 --- a/controllers/azuremanagedmachinepool_controller_test.go +++ b/controllers/azuremanagedmachinepool_controller_test.go @@ -263,7 +263,7 @@ func fakeAgentPool(changes ...func(*agentpools.AgentPoolSpec)) agentpools.AgentP ResourceGroup: "fake-rg", Cluster: "fake-cluster", AvailabilityZones: []string{"fake-zone"}, - EnableAutoScaling: pointer.Bool(true), + EnableAutoScaling: true, EnableUltraSSD: pointer.Bool(true), KubeletDiskType: (*infrav1.KubeletDiskType)(pointer.String("fake-kubelet-disk-type")), MaxCount: pointer.Int32(5),