Skip to content

Commit

Permalink
update the node labels for AKS nodepools
Browse files Browse the repository at this point in the history
  • Loading branch information
zmalik authored and jackfrancis committed Aug 24, 2022
1 parent 832c1f7 commit f43cb1c
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
EnableAutoScaling: existingPool.EnableAutoScaling,
MinCount: existingPool.MinCount,
MaxCount: existingPool.MaxCount,
NodeLabels: existingPool.NodeLabels,
},
}

Expand All @@ -122,6 +123,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
EnableAutoScaling: profile.EnableAutoScaling,
MinCount: profile.MinCount,
MaxCount: profile.MaxCount,
NodeLabels: profile.NodeLabels,
},
}

Expand Down
145 changes: 145 additions & 0 deletions azure/services/agentpools/agentpools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,79 @@ func TestReconcile(t *testing.T) {
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"))
},
},
}

for _, tc := range testcases {
t.Logf("Testing " + tc.name)
tc := tc
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
t.Parallel()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

replicas := tc.agentPoolsSpec.Replicas
osDiskSizeGB := tc.agentPoolsSpec.OSDiskSizeGB

agentpoolsMock := mock_agentpools.NewMockClient(mockCtrl)
machinePoolScope := &scope.ManagedMachinePoolScope{
ControlPlane: &infraexpv1.AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: tc.agentPoolsSpec.Cluster,
},
Spec: infraexpv1.AzureManagedControlPlaneSpec{
ResourceGroupName: tc.agentPoolsSpec.ResourceGroup,
},
},
MachinePool: &capiexp.MachinePool{
Spec: capiexp.MachinePoolSpec{
Replicas: &replicas,
Template: capi.MachineTemplateSpec{
Spec: capi.MachineSpec{
Version: tc.agentPoolsSpec.Version,
},
},
},
},
InfraMachinePool: &infraexpv1.AzureManagedMachinePool{
ObjectMeta: metav1.ObjectMeta{
Name: tc.agentPoolsSpec.Name,
},
Spec: infraexpv1.AzureManagedMachinePoolSpec{
Name: &tc.agentPoolsSpec.Name,
SKU: tc.agentPoolsSpec.SKU,
OSDiskSizeGB: &osDiskSizeGB,
MaxPods: to.Int32Ptr(12),
OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeManaged)),
},
},
}

tc.expect(agentpoolsMock.EXPECT())

s := &Service{
Client: agentpoolsMock,
scope: machinePoolScope,
}

err := s.Reconcile(context.TODO())
if tc.expectedError != "" {
g.Expect(err).To(HaveOccurred())
g.Expect(err).To(MatchError(tc.expectedError))
} else {
g.Expect(err).NotTo(HaveOccurred())
}
})
}
}

func TestNormalizedDiff(t *testing.T) {
testcases := []struct {
name string
agentPoolsSpec azure.AgentPoolSpec
expectedError string
expect func(m *mock_agentpools.MockClientMockRecorder)
}{
{
name: "no update needed on Agent Pool",
agentPoolsSpec: azure.AgentPoolSpec{
Expand Down Expand Up @@ -261,6 +334,78 @@ func TestReconcile(t *testing.T) {
}, nil)
},
},
{
name: "update needed on autoscaler configuration change",
agentPoolsSpec: azure.AgentPoolSpec{
Name: "my-agent-pool",
ResourceGroup: "my-rg",
Cluster: "my-cluster",
SKU: "Standard_D2s_v3",
Version: to.StringPtr("9.99.9999"),
EnableAutoScaling: to.BoolPtr(true),
MinCount: to.Int32Ptr(1),
MaxCount: to.Int32Ptr(3),
OSDiskSizeGB: 100,
MaxPods: to.Int32Ptr(12),
OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeEphemeral)),
},
expectedError: "",
expect: func(m *mock_agentpools.MockClientMockRecorder) {
m.Get(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool").Return(containerservice.AgentPool{
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
EnableAutoScaling: to.BoolPtr(true),
MinCount: to.Int32Ptr(1),
MaxCount: to.Int32Ptr(5),
OsDiskSizeGB: to.Int32Ptr(100),
VMSize: to.StringPtr(string(containerservice.VMSizeTypesStandardD2sV3)),
OsType: containerservice.OSTypeLinux,
OrchestratorVersion: to.StringPtr("9.99.9999"),
ProvisioningState: to.StringPtr("Succeeded"),
VnetSubnetID: to.StringPtr(""),
MaxPods: to.Int32Ptr(12),
OsDiskType: containerservice.OSDiskTypeEphemeral,
},
}, nil)
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool", gomock.AssignableToTypeOf(containerservice.AgentPool{}), gomock.Any()).Return(nil)
},
},
{
name: "update needed on nodepool labels change",
agentPoolsSpec: azure.AgentPoolSpec{
Name: "my-agent-pool",
ResourceGroup: "my-rg",
Cluster: "my-cluster",
SKU: "Standard_D2s_v3",
Version: to.StringPtr("9.99.9999"),
EnableAutoScaling: to.BoolPtr(true),
MinCount: to.Int32Ptr(1),
MaxCount: to.Int32Ptr(3),
OSDiskSizeGB: 100,
MaxPods: to.Int32Ptr(12),
OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeEphemeral)),
NodeLabels: map[string]*string{"workload": to.StringPtr("stateless")},
},
expectedError: "",
expect: func(m *mock_agentpools.MockClientMockRecorder) {
m.Get(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool").Return(containerservice.AgentPool{
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
EnableAutoScaling: to.BoolPtr(true),
MinCount: to.Int32Ptr(1),
MaxCount: to.Int32Ptr(3),
OsDiskSizeGB: to.Int32Ptr(100),
VMSize: to.StringPtr(string(containerservice.VMSizeTypesStandardD2sV3)),
OsType: containerservice.OSTypeLinux,
OrchestratorVersion: to.StringPtr("9.99.9999"),
ProvisioningState: to.StringPtr("Succeeded"),
VnetSubnetID: to.StringPtr(""),
MaxPods: to.Int32Ptr(12),
OsDiskType: containerservice.OSDiskTypeEphemeral,
NodeLabels: map[string]*string{"workload": to.StringPtr("all")},
},
}, nil)
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-cluster", "my-agent-pool", gomock.AssignableToTypeOf(containerservice.AgentPool{}), gomock.Any()).Return(nil)
},
},
}

for _, tc := range testcases {
Expand Down

0 comments on commit f43cb1c

Please sign in to comment.