@@ -47,109 +47,92 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp
47
47
input := inputGetter ()
48
48
var wg sync.WaitGroup
49
49
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" )
56
50
for _ , mp := range input .MachinePools {
57
51
wg .Add (1 )
58
52
go func (mp * expv1.MachinePool ) {
59
53
defer GinkgoRecover ()
60
54
defer wg .Done ()
55
+
56
+ originalReplicas := ptr .Deref (mp .Spec .Replicas , 0 )
57
+
58
+ Byf ("Scaling machine pool %s out" , mp .Name )
61
59
framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
62
60
ClusterProxy : bootstrapClusterProxy ,
63
61
Cluster : input .Cluster ,
64
62
Replicas : ptr .Deref (mp .Spec .Replicas , 0 ) + 1 ,
65
63
MachinePools : []* expv1.MachinePool {mp },
66
64
WaitForMachinePoolToScale : input .WaitIntervals ,
67
65
})
68
- }(mp )
69
- }
70
- wg .Wait ()
71
66
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 )
78
68
framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
79
69
ClusterProxy : bootstrapClusterProxy ,
80
70
Cluster : input .Cluster ,
81
71
Replicas : ptr .Deref (mp .Spec .Replicas , 0 ) - 1 ,
82
72
MachinePools : []* expv1.MachinePool {mp },
83
73
WaitForMachinePoolToScale : input .WaitIntervals ,
84
74
})
85
- }(mp )
86
- }
87
- wg .Wait ()
88
75
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
118
89
}
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
125
112
}
126
- break
127
113
}
128
- }
129
- }
130
114
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
+ }
138
125
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 )
145
127
framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
146
128
ClusterProxy : bootstrapClusterProxy ,
147
129
Cluster : input .Cluster ,
148
- Replicas : originalReplicas [ client . ObjectKeyFromObject ( mp )] ,
130
+ Replicas : originalReplicas ,
149
131
MachinePools : []* expv1.MachinePool {mp },
150
132
WaitForMachinePoolToScale : input .WaitIntervals ,
151
133
})
152
134
}(mp )
153
135
}
136
+
154
137
wg .Wait ()
155
138
}
0 commit comments