Skip to content

Commit

Permalink
fix bug preventing AKS autoscaling from being disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Jul 26, 2023
1 parent 687e66f commit 936dfc1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion azure/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion azure/scope/managedmachinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
8 changes: 4 additions & 4 deletions azure/services/agentpools/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

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

Expand Down
2 changes: 2 additions & 0 deletions azure/services/managedclusters/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion controllers/azuremanagedmachinepool_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 936dfc1

Please sign in to comment.