Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.4] update the node labels for existing AKS nodepools #2569

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
EnableAutoScaling: existingPool.EnableAutoScaling,
MinCount: existingPool.MinCount,
MaxCount: existingPool.MaxCount,
NodeLabels: existingPool.NodeLabels,
},
}

Expand All @@ -127,6 +128,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