@@ -47,109 +47,92 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp
4747 input := inputGetter ()
4848 var wg sync.WaitGroup
4949
50- originalReplicas := map [types.NamespacedName ]int32 {}
51- for _ , mp := range input .MachinePools {
52- originalReplicas [client .ObjectKeyFromObject (mp )] = ptr .Deref (mp .Spec .Replicas , 0 )
53- }
54-
55- By ("Scaling the machine pools out" )
5650 for _ , mp := range input .MachinePools {
5751 wg .Add (1 )
5852 go func (mp * expv1.MachinePool ) {
5953 defer GinkgoRecover ()
6054 defer wg .Done ()
55+
56+ originalReplicas := ptr .Deref (mp .Spec .Replicas , 0 )
57+
58+ Byf ("Scaling machine pool %s out" , mp .Name )
6159 framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
6260 ClusterProxy : bootstrapClusterProxy ,
6361 Cluster : input .Cluster ,
6462 Replicas : ptr .Deref (mp .Spec .Replicas , 0 ) + 1 ,
6563 MachinePools : []* expv1.MachinePool {mp },
6664 WaitForMachinePoolToScale : input .WaitIntervals ,
6765 })
68- }(mp )
69- }
70- wg .Wait ()
7166
72- By ("Scaling the machine pools in" )
73- for _ , mp := range input .MachinePools {
74- wg .Add (1 )
75- go func (mp * expv1.MachinePool ) {
76- defer GinkgoRecover ()
77- defer wg .Done ()
67+ Byf ("Scaling machine pool %s in" , mp .Name )
7868 framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
7969 ClusterProxy : bootstrapClusterProxy ,
8070 Cluster : input .Cluster ,
8171 Replicas : ptr .Deref (mp .Spec .Replicas , 0 ) - 1 ,
8272 MachinePools : []* expv1.MachinePool {mp },
8373 WaitForMachinePoolToScale : input .WaitIntervals ,
8474 })
85- }(mp )
86- }
87- wg .Wait ()
8875
89- By ("Scaling the machine pools to zero" )
90- // System node pools cannot be scaled to 0, so only include user node pools.
91- var machinePoolsToScale []* expv1.MachinePool
92- for _ , mp := range input .MachinePools {
93- switch mp .Spec .Template .Spec .InfrastructureRef .Kind {
94- case infrav1 .AzureManagedMachinePoolKind :
95- ammp := & infrav1.AzureManagedMachinePool {}
96- err := bootstrapClusterProxy .GetClient ().Get (ctx , types.NamespacedName {
97- Namespace : mp .Spec .Template .Spec .InfrastructureRef .Namespace ,
98- Name : mp .Spec .Template .Spec .InfrastructureRef .Name ,
99- }, ammp )
100- Expect (err ).NotTo (HaveOccurred ())
101-
102- if ammp .Spec .Mode != string (infrav1 .NodePoolModeSystem ) {
103- machinePoolsToScale = append (machinePoolsToScale , mp )
104- }
105- case infrav1exp .AzureASOManagedMachinePoolKind :
106- ammp := & infrav1exp.AzureASOManagedMachinePool {}
107- err := bootstrapClusterProxy .GetClient ().Get (ctx , types.NamespacedName {
108- Namespace : mp .Spec .Template .Spec .InfrastructureRef .Namespace ,
109- Name : mp .Spec .Template .Spec .InfrastructureRef .Name ,
110- }, ammp )
111- Expect (err ).NotTo (HaveOccurred ())
112-
113- resources , err := mutators .ToUnstructured (ctx , ammp .Spec .Resources )
114- Expect (err ).NotTo (HaveOccurred ())
115- for _ , resource := range resources {
116- if resource .GetKind () != "ManagedClustersAgentPool" {
117- continue
76+ // System node pools cannot be scaled to 0, so only include user node pools.
77+ isUserPool := false
78+ switch mp .Spec .Template .Spec .InfrastructureRef .Kind {
79+ case infrav1 .AzureManagedMachinePoolKind :
80+ ammp := & infrav1.AzureManagedMachinePool {}
81+ err := bootstrapClusterProxy .GetClient ().Get (ctx , types.NamespacedName {
82+ Namespace : mp .Spec .Template .Spec .InfrastructureRef .Namespace ,
83+ Name : mp .Spec .Template .Spec .InfrastructureRef .Name ,
84+ }, ammp )
85+ Expect (err ).NotTo (HaveOccurred ())
86+
87+ if ammp .Spec .Mode != string (infrav1 .NodePoolModeSystem ) {
88+ isUserPool = true
11889 }
119- // mode may not be set in spec. Get the ASO object and check in status.
120- resource .SetNamespace (ammp .Namespace )
121- agentPool := & asocontainerservicev1.ManagedClustersAgentPool {}
122- Expect (bootstrapClusterProxy .GetClient ().Get (ctx , client .ObjectKeyFromObject (resource ), agentPool )).To (Succeed ())
123- if ptr .Deref (agentPool .Status .Mode , "" ) != asocontainerservicev1 .AgentPoolMode_STATUS_System {
124- machinePoolsToScale = append (machinePoolsToScale , mp )
90+ case infrav1exp .AzureASOManagedMachinePoolKind :
91+ ammp := & infrav1exp.AzureASOManagedMachinePool {}
92+ err := bootstrapClusterProxy .GetClient ().Get (ctx , types.NamespacedName {
93+ Namespace : mp .Spec .Template .Spec .InfrastructureRef .Namespace ,
94+ Name : mp .Spec .Template .Spec .InfrastructureRef .Name ,
95+ }, ammp )
96+ Expect (err ).NotTo (HaveOccurred ())
97+
98+ resources , err := mutators .ToUnstructured (ctx , ammp .Spec .Resources )
99+ Expect (err ).NotTo (HaveOccurred ())
100+ for _ , resource := range resources {
101+ if resource .GetKind () != "ManagedClustersAgentPool" {
102+ continue
103+ }
104+ // mode may not be set in spec. Get the ASO object and check in status.
105+ resource .SetNamespace (ammp .Namespace )
106+ agentPool := & asocontainerservicev1.ManagedClustersAgentPool {}
107+ Expect (bootstrapClusterProxy .GetClient ().Get (ctx , client .ObjectKeyFromObject (resource ), agentPool )).To (Succeed ())
108+ if ptr .Deref (agentPool .Status .Mode , "" ) != asocontainerservicev1 .AgentPoolMode_STATUS_System {
109+ isUserPool = true
110+ }
111+ break
125112 }
126- break
127113 }
128- }
129- }
130114
131- framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
132- ClusterProxy : bootstrapClusterProxy ,
133- Cluster : input .Cluster ,
134- Replicas : 0 ,
135- MachinePools : machinePoolsToScale ,
136- WaitForMachinePoolToScale : input .WaitIntervals ,
137- })
115+ if isUserPool {
116+ Byf ("Scaling the machine pool %s to zero" , mp .Name )
117+ framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
118+ ClusterProxy : bootstrapClusterProxy ,
119+ Cluster : input .Cluster ,
120+ Replicas : 0 ,
121+ MachinePools : []* expv1.MachinePool {mp },
122+ WaitForMachinePoolToScale : input .WaitIntervals ,
123+ })
124+ }
138125
139- By ("Restoring initial replica count" )
140- for _ , mp := range input .MachinePools {
141- wg .Add (1 )
142- go func (mp * expv1.MachinePool ) {
143- defer GinkgoRecover ()
144- defer wg .Done ()
126+ Byf ("Restoring initial replica count for machine pool %s" , mp .Name )
145127 framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
146128 ClusterProxy : bootstrapClusterProxy ,
147129 Cluster : input .Cluster ,
148- Replicas : originalReplicas [ client . ObjectKeyFromObject ( mp )] ,
130+ Replicas : originalReplicas ,
149131 MachinePools : []* expv1.MachinePool {mp },
150132 WaitForMachinePoolToScale : input .WaitIntervals ,
151133 })
152134 }(mp )
153135 }
136+
154137 wg .Wait ()
155138}
0 commit comments