Skip to content

Commit ba163a2

Browse files
zmalikzain.malik
authored andcommitted
add support for aks node labels
1 parent d41727f commit ba163a2

12 files changed

+162
-0
lines changed

azure/scope/managedcontrolplane.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,13 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane
578578
agentPoolSpec.MinCount = managedMachinePool.Spec.Scaling.MinSize
579579
}
580580

581+
if len(managedMachinePool.Spec.NodeLabels) > 0 {
582+
agentPoolSpec.NodeLabels = make(map[string]*string, len(managedMachinePool.Spec.NodeLabels))
583+
for k, v := range managedMachinePool.Spec.NodeLabels {
584+
agentPoolSpec.NodeLabels[k] = to.StringPtr(v)
585+
}
586+
}
587+
581588
return agentPoolSpec
582589
}
583590

azure/scope/managedcontrolplane_test.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,111 @@ func TestManagedControlPlaneScope_Autoscaling(t *testing.T) {
131131
}
132132
}
133133

134+
func TestManagedControlPlaneScope_NodeLabels(t *testing.T) {
135+
scheme := runtime.NewScheme()
136+
_ = capiv1exp.AddToScheme(scheme)
137+
_ = infrav1.AddToScheme(scheme)
138+
139+
cases := []struct {
140+
Name string
141+
Input ManagedControlPlaneScopeParams
142+
Expected azure.AgentPoolSpec
143+
}{
144+
{
145+
Name: "Without node labels",
146+
Input: ManagedControlPlaneScopeParams{
147+
AzureClients: AzureClients{
148+
Authorizer: autorest.NullAuthorizer{},
149+
},
150+
Cluster: &clusterv1.Cluster{
151+
ObjectMeta: metav1.ObjectMeta{
152+
Name: "cluster1",
153+
Namespace: "default",
154+
},
155+
},
156+
ControlPlane: &infrav1.AzureManagedControlPlane{
157+
ObjectMeta: metav1.ObjectMeta{
158+
Name: "cluster1",
159+
Namespace: "default",
160+
},
161+
Spec: infrav1.AzureManagedControlPlaneSpec{
162+
SubscriptionID: "00000000-0000-0000-0000-000000000000",
163+
},
164+
},
165+
MachinePool: getMachinePool("pool0"),
166+
InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem),
167+
PatchTarget: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem),
168+
},
169+
Expected: azure.AgentPoolSpec{
170+
171+
Name: "pool0",
172+
SKU: "Standard_D2s_v3",
173+
Replicas: 1,
174+
Mode: "System",
175+
Cluster: "cluster1",
176+
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
177+
},
178+
},
179+
{
180+
Name: "With node labels",
181+
Input: ManagedControlPlaneScopeParams{
182+
AzureClients: AzureClients{
183+
Authorizer: autorest.NullAuthorizer{},
184+
},
185+
Cluster: &clusterv1.Cluster{
186+
ObjectMeta: metav1.ObjectMeta{
187+
Name: "cluster1",
188+
Namespace: "default",
189+
},
190+
},
191+
ControlPlane: &infrav1.AzureManagedControlPlane{
192+
ObjectMeta: metav1.ObjectMeta{
193+
Name: "cluster1",
194+
Namespace: "default",
195+
},
196+
Spec: infrav1.AzureManagedControlPlaneSpec{
197+
SubscriptionID: "00000000-0000-0000-0000-000000000000",
198+
},
199+
},
200+
MachinePool: getMachinePool("pool1"),
201+
InfraMachinePool: getAzureMachinePoolWithLabels("pool1", map[string]string{
202+
"custom": "default",
203+
}),
204+
PatchTarget: getAzureMachinePoolWithLabels("pool1", map[string]string{
205+
"custom": "default",
206+
}),
207+
},
208+
Expected: azure.AgentPoolSpec{
209+
Name: "pool1",
210+
SKU: "Standard_D2s_v3",
211+
Mode: "System",
212+
Cluster: "cluster1",
213+
Replicas: 1,
214+
NodeLabels: map[string]*string{
215+
"custom": to.StringPtr("default"),
216+
},
217+
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
218+
},
219+
},
220+
}
221+
222+
for _, c := range cases {
223+
c := c
224+
t.Run(c.Name, func(t *testing.T) {
225+
g := NewWithT(t)
226+
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build()
227+
c.Input.Client = fakeClient
228+
s, err := NewManagedControlPlaneScope(context.TODO(), c.Input)
229+
g.Expect(err).To(Succeed())
230+
agentPool := s.AgentPoolSpec()
231+
g.Expect(agentPool).To(Equal(c.Expected))
232+
agentPools, err := s.GetAllAgentPoolSpecs(context.TODO())
233+
g.Expect(err).To(Succeed())
234+
g.Expect(agentPools[0].NodeLabels).To(Equal(c.Expected.NodeLabels))
235+
})
236+
}
237+
}
238+
134239
func TestManagedControlPlaneScope_PoolVersion(t *testing.T) {
135240
scheme := runtime.NewScheme()
136241
_ = capiv1exp.AddToScheme(scheme)
@@ -502,6 +607,12 @@ func getAzureMachinePoolWithOsDiskType(name string, osDiskType string) *infrav1.
502607
return managedPool
503608
}
504609

610+
func getAzureMachinePoolWithLabels(name string, nodeLabels map[string]string) *infrav1.AzureManagedMachinePool {
611+
managedPool := getAzureMachinePool(name, infrav1.NodePoolModeSystem)
612+
managedPool.Spec.NodeLabels = nodeLabels
613+
return managedPool
614+
}
615+
505616
func getMachinePool(name string) *capiv1exp.MachinePool {
506617
return &capiv1exp.MachinePool{
507618
ObjectMeta: metav1.ObjectMeta{

azure/services/agentpools/agentpools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
8282
AvailabilityZones: &agentPoolSpec.AvailabilityZones,
8383
MaxPods: agentPoolSpec.MaxPods,
8484
OsDiskType: containerservice.OSDiskType(to.String(agentPoolSpec.OsDiskType)),
85+
NodeLabels: agentPoolSpec.NodeLabels,
8586
},
8687
}
8788

azure/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ type AgentPoolSpec struct {
363363
// Minimum number of nodes for auto-scaling
364364
MinCount *int32 `json:"minCount,omitempty"`
365365

366+
// Node labels - labels for all of the nodes present in node pool
367+
NodeLabels map[string]*string `json:"nodeLabels,omitempty"`
368+
366369
// EnableAutoScaling - Whether to enable auto-scaler
367370
EnableAutoScaling *bool `json:"enableAutoScaling,omitempty"`
368371

config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedmachinepools.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ spec:
217217
description: Name - name of the agent pool. If not specified, CAPZ
218218
uses the name of the CR as the agent pool name.
219219
type: string
220+
nodeLabels:
221+
additionalProperties:
222+
type: string
223+
description: Node labels - labels for all of the nodes present in
224+
node pool
225+
type: object
220226
osDiskSizeGB:
221227
description: OSDiskSizeGB is the disk size for every machine in this
222228
agent pool. If you specify 0, it will apply the default osDisk size

docs/book/src/topics/managedcluster.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,25 @@ spec:
263263
maxSize: 10
264264
```
265265
266+
### AKS Node Labels to an Agent Pool
267+
268+
You can configure the `NodeLabels` value for each AKS node pool (`AzureManagedMachinePool`) that you define in your spec.
269+
270+
Below an example `nodeLabels` configuration is assigned to `agentpool0`, specifying that each node in the pool will add a label `dedicated : kafka`
271+
272+
```
273+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
274+
kind: AzureManagedMachinePool
275+
metadata:
276+
name: agentpool0
277+
spec:
278+
mode: System
279+
osDiskSizeGB: 512
280+
sku: Standard_D2s_v3
281+
nodeLabels:
282+
dedicated: kafka
283+
```
284+
266285
### AKS Node Pool MaxPods configuration
267286
268287
You can configure the `MaxPods` value for each AKS node pool (`AzureManagedMachinePool`) that you define in your spec (see [here](https://docs.microsoft.com/en-us/azure/aks/configure-azure-cni#configure-maximum---new-clusters) for the official AKS documentation). This corresponds to the kubelet `--max-pods` configuration (official kubelet configuration documentation can be found [here](https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/)).

exp/api/v1alpha3/azuremanagedmachinepool_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (src *AzureManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error { //
4242
dst.Spec.AvailabilityZones = restored.Spec.AvailabilityZones
4343
dst.Spec.MaxPods = restored.Spec.MaxPods
4444
dst.Spec.OsDiskType = restored.Spec.OsDiskType
45+
dst.Spec.NodeLabels = restored.Spec.NodeLabels
4546

4647
dst.Status.LongRunningOperationStates = restored.Status.LongRunningOperationStates
4748
dst.Status.Conditions = restored.Status.Conditions

exp/api/v1alpha3/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/api/v1alpha4/azuremanagedmachinepool_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (src *AzureManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
4242
dst.Spec.AvailabilityZones = restored.Spec.AvailabilityZones
4343
dst.Spec.MaxPods = restored.Spec.MaxPods
4444
dst.Spec.OsDiskType = restored.Spec.OsDiskType
45+
dst.Spec.NodeLabels = restored.Spec.NodeLabels
4546

4647
dst.Status.LongRunningOperationStates = restored.Status.LongRunningOperationStates
4748
dst.Status.Conditions = restored.Status.Conditions

exp/api/v1alpha4/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)