Skip to content

Commit fd15dc3

Browse files
zmalikjackfrancis
authored andcommitted
update the node labels for AKS nodepools
1 parent 057332f commit fd15dc3

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

azure/services/agentpools/agentpools.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
116116
EnableAutoScaling: existingPool.EnableAutoScaling,
117117
MinCount: existingPool.MinCount,
118118
MaxCount: existingPool.MaxCount,
119+
NodeLabels: existingPool.NodeLabels,
119120
},
120121
}
121122

@@ -127,6 +128,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
127128
EnableAutoScaling: profile.EnableAutoScaling,
128129
MinCount: profile.MinCount,
129130
MaxCount: profile.MaxCount,
131+
NodeLabels: profile.NodeLabels,
130132
},
131133
}
132134

azure/services/agentpools/agentpools_test.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,79 @@ func TestReconcile(t *testing.T) {
231231
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool", gomock.AssignableToTypeOf(containerservice.AgentPool{}), gomock.Any()).Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error"))
232232
},
233233
},
234+
}
235+
236+
for _, tc := range testcases {
237+
t.Logf("Testing " + tc.name)
238+
tc := tc
239+
t.Run(tc.name, func(t *testing.T) {
240+
g := NewWithT(t)
241+
t.Parallel()
242+
mockCtrl := gomock.NewController(t)
243+
defer mockCtrl.Finish()
244+
245+
replicas := tc.agentPoolsSpec.Replicas
246+
osDiskSizeGB := tc.agentPoolsSpec.OSDiskSizeGB
247+
248+
agentpoolsMock := mock_agentpools.NewMockClient(mockCtrl)
249+
machinePoolScope := &scope.ManagedMachinePoolScope{
250+
ControlPlane: &infraexpv1.AzureManagedControlPlane{
251+
ObjectMeta: metav1.ObjectMeta{
252+
Name: tc.agentPoolsSpec.Cluster,
253+
},
254+
Spec: infraexpv1.AzureManagedControlPlaneSpec{
255+
ResourceGroupName: tc.agentPoolsSpec.ResourceGroup,
256+
},
257+
},
258+
MachinePool: &capiexp.MachinePool{
259+
Spec: capiexp.MachinePoolSpec{
260+
Replicas: &replicas,
261+
Template: capi.MachineTemplateSpec{
262+
Spec: capi.MachineSpec{
263+
Version: tc.agentPoolsSpec.Version,
264+
},
265+
},
266+
},
267+
},
268+
InfraMachinePool: &infraexpv1.AzureManagedMachinePool{
269+
ObjectMeta: metav1.ObjectMeta{
270+
Name: tc.agentPoolsSpec.Name,
271+
},
272+
Spec: infraexpv1.AzureManagedMachinePoolSpec{
273+
Name: &tc.agentPoolsSpec.Name,
274+
SKU: tc.agentPoolsSpec.SKU,
275+
OSDiskSizeGB: &osDiskSizeGB,
276+
MaxPods: to.Int32Ptr(12),
277+
OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeManaged)),
278+
},
279+
},
280+
}
281+
282+
tc.expect(agentpoolsMock.EXPECT())
283+
284+
s := &Service{
285+
Client: agentpoolsMock,
286+
scope: machinePoolScope,
287+
}
288+
289+
err := s.Reconcile(context.TODO())
290+
if tc.expectedError != "" {
291+
g.Expect(err).To(HaveOccurred())
292+
g.Expect(err).To(MatchError(tc.expectedError))
293+
} else {
294+
g.Expect(err).NotTo(HaveOccurred())
295+
}
296+
})
297+
}
298+
}
299+
300+
func TestNormalizedDiff(t *testing.T) {
301+
testcases := []struct {
302+
name string
303+
agentPoolsSpec azure.AgentPoolSpec
304+
expectedError string
305+
expect func(m *mock_agentpools.MockClientMockRecorder)
306+
}{
234307
{
235308
name: "no update needed on Agent Pool",
236309
agentPoolsSpec: azure.AgentPoolSpec{
@@ -261,6 +334,78 @@ func TestReconcile(t *testing.T) {
261334
}, nil)
262335
},
263336
},
337+
{
338+
name: "update needed on autoscaler configuration change",
339+
agentPoolsSpec: azure.AgentPoolSpec{
340+
Name: "my-agent-pool",
341+
ResourceGroup: "my-rg",
342+
Cluster: "my-cluster",
343+
SKU: "Standard_D2s_v3",
344+
Version: to.StringPtr("9.99.9999"),
345+
EnableAutoScaling: to.BoolPtr(true),
346+
MinCount: to.Int32Ptr(1),
347+
MaxCount: to.Int32Ptr(3),
348+
OSDiskSizeGB: 100,
349+
MaxPods: to.Int32Ptr(12),
350+
OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeEphemeral)),
351+
},
352+
expectedError: "",
353+
expect: func(m *mock_agentpools.MockClientMockRecorder) {
354+
m.Get(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool").Return(containerservice.AgentPool{
355+
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
356+
EnableAutoScaling: to.BoolPtr(true),
357+
MinCount: to.Int32Ptr(1),
358+
MaxCount: to.Int32Ptr(5),
359+
OsDiskSizeGB: to.Int32Ptr(100),
360+
VMSize: to.StringPtr(string(containerservice.VMSizeTypesStandardD2sV3)),
361+
OsType: containerservice.OSTypeLinux,
362+
OrchestratorVersion: to.StringPtr("9.99.9999"),
363+
ProvisioningState: to.StringPtr("Succeeded"),
364+
VnetSubnetID: to.StringPtr(""),
365+
MaxPods: to.Int32Ptr(12),
366+
OsDiskType: containerservice.OSDiskTypeEphemeral,
367+
},
368+
}, nil)
369+
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool", gomock.AssignableToTypeOf(containerservice.AgentPool{}), gomock.Any()).Return(nil)
370+
},
371+
},
372+
{
373+
name: "update needed on nodepool labels change",
374+
agentPoolsSpec: azure.AgentPoolSpec{
375+
Name: "my-agent-pool",
376+
ResourceGroup: "my-rg",
377+
Cluster: "my-cluster",
378+
SKU: "Standard_D2s_v3",
379+
Version: to.StringPtr("9.99.9999"),
380+
EnableAutoScaling: to.BoolPtr(true),
381+
MinCount: to.Int32Ptr(1),
382+
MaxCount: to.Int32Ptr(3),
383+
OSDiskSizeGB: 100,
384+
MaxPods: to.Int32Ptr(12),
385+
OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeEphemeral)),
386+
NodeLabels: map[string]*string{"workload": to.StringPtr("stateless")},
387+
},
388+
expectedError: "",
389+
expect: func(m *mock_agentpools.MockClientMockRecorder) {
390+
m.Get(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool").Return(containerservice.AgentPool{
391+
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
392+
EnableAutoScaling: to.BoolPtr(true),
393+
MinCount: to.Int32Ptr(1),
394+
MaxCount: to.Int32Ptr(3),
395+
OsDiskSizeGB: to.Int32Ptr(100),
396+
VMSize: to.StringPtr(string(containerservice.VMSizeTypesStandardD2sV3)),
397+
OsType: containerservice.OSTypeLinux,
398+
OrchestratorVersion: to.StringPtr("9.99.9999"),
399+
ProvisioningState: to.StringPtr("Succeeded"),
400+
VnetSubnetID: to.StringPtr(""),
401+
MaxPods: to.Int32Ptr(12),
402+
OsDiskType: containerservice.OSDiskTypeEphemeral,
403+
NodeLabels: map[string]*string{"workload": to.StringPtr("all")},
404+
},
405+
}, nil)
406+
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool", gomock.AssignableToTypeOf(containerservice.AgentPool{}), gomock.Any()).Return(nil)
407+
},
408+
},
264409
}
265410

266411
for _, tc := range testcases {

0 commit comments

Comments
 (0)