Skip to content

Commit 17be748

Browse files
zmalikzain.malik
authored andcommitted
add taints to AzureManagedMachinePool
1 parent 0a254d8 commit 17be748

15 files changed

+281
-0
lines changed

azure/scope/managedcontrolplane.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,14 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane
599599
agentPoolSpec.OSDiskSizeGB = *managedMachinePool.Spec.OSDiskSizeGB
600600
}
601601

602+
if len(managedMachinePool.Spec.Taints) > 0 {
603+
nodeTaints := make([]string, 0, len(managedMachinePool.Spec.Taints))
604+
for _, t := range managedMachinePool.Spec.Taints {
605+
nodeTaints = append(nodeTaints, fmt.Sprintf("%s=%s:%s", t.Key, t.Value, t.Effect))
606+
}
607+
agentPoolSpec.NodeTaints = nodeTaints
608+
}
609+
602610
if managedMachinePool.Spec.Scaling != nil {
603611
agentPoolSpec.EnableAutoScaling = to.BoolPtr(true)
604612
agentPoolSpec.MaxCount = managedMachinePool.Spec.Scaling.MaxSize

azure/scope/managedcontrolplane_test.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,114 @@ func TestManagedControlPlaneScope_OSDiskType(t *testing.T) {
562562
}
563563
}
564564

565+
func TestManagedControlPlaneScope_Taints(t *testing.T) {
566+
scheme := runtime.NewScheme()
567+
_ = capiv1exp.AddToScheme(scheme)
568+
_ = infrav1.AddToScheme(scheme)
569+
570+
cases := []struct {
571+
Name string
572+
Input ManagedControlPlaneScopeParams
573+
Expected azure.AgentPoolSpec
574+
}{
575+
{
576+
Name: "Without taints",
577+
Input: ManagedControlPlaneScopeParams{
578+
AzureClients: AzureClients{
579+
Authorizer: autorest.NullAuthorizer{},
580+
},
581+
Cluster: &clusterv1.Cluster{
582+
ObjectMeta: metav1.ObjectMeta{
583+
Name: "cluster1",
584+
Namespace: "default",
585+
},
586+
},
587+
ControlPlane: &infrav1.AzureManagedControlPlane{
588+
ObjectMeta: metav1.ObjectMeta{
589+
Name: "cluster1",
590+
Namespace: "default",
591+
},
592+
Spec: infrav1.AzureManagedControlPlaneSpec{
593+
SubscriptionID: "00000000-0000-0000-0000-000000000000",
594+
},
595+
},
596+
MachinePool: getMachinePool("pool0"),
597+
InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem),
598+
PatchTarget: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem),
599+
},
600+
Expected: azure.AgentPoolSpec{
601+
602+
Name: "pool0",
603+
SKU: "Standard_D2s_v3",
604+
Replicas: 1,
605+
Mode: "System",
606+
Cluster: "cluster1",
607+
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
608+
},
609+
},
610+
{
611+
Name: "With taints",
612+
Input: ManagedControlPlaneScopeParams{
613+
AzureClients: AzureClients{
614+
Authorizer: autorest.NullAuthorizer{},
615+
},
616+
Cluster: &clusterv1.Cluster{
617+
ObjectMeta: metav1.ObjectMeta{
618+
Name: "cluster1",
619+
Namespace: "default",
620+
},
621+
},
622+
ControlPlane: &infrav1.AzureManagedControlPlane{
623+
ObjectMeta: metav1.ObjectMeta{
624+
Name: "cluster1",
625+
Namespace: "default",
626+
},
627+
Spec: infrav1.AzureManagedControlPlaneSpec{
628+
SubscriptionID: "00000000-0000-0000-0000-000000000000",
629+
},
630+
},
631+
MachinePool: getMachinePool("pool1"),
632+
InfraMachinePool: getAzureMachinePoolWithTaints("pool1", infrav1.Taints{
633+
infrav1.Taint{
634+
Key: "key1",
635+
Value: "value1",
636+
Effect: "NoSchedule",
637+
},
638+
}),
639+
PatchTarget: getAzureMachinePoolWithTaints("pool1", infrav1.Taints{
640+
infrav1.Taint{
641+
Key: "key1",
642+
Value: "value1",
643+
Effect: "NoSchedule",
644+
},
645+
}),
646+
},
647+
Expected: azure.AgentPoolSpec{
648+
Name: "pool1",
649+
SKU: "Standard_D2s_v3",
650+
Mode: "User",
651+
Cluster: "cluster1",
652+
Replicas: 1,
653+
NodeTaints: []string{"key1=value1:NoSchedule"},
654+
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
655+
},
656+
},
657+
}
658+
659+
for _, c := range cases {
660+
c := c
661+
t.Run(c.Name, func(t *testing.T) {
662+
g := NewWithT(t)
663+
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build()
664+
c.Input.Client = fakeClient
665+
s, err := NewManagedControlPlaneScope(context.TODO(), c.Input)
666+
g.Expect(err).To(Succeed())
667+
agentPool := s.AgentPoolSpec()
668+
g.Expect(agentPool).To(Equal(c.Expected))
669+
})
670+
}
671+
}
672+
565673
func getAzureMachinePool(name string, mode infrav1.NodePoolMode) *infrav1.AzureManagedMachinePool {
566674
return &infrav1.AzureManagedMachinePool{
567675
ObjectMeta: metav1.ObjectMeta{
@@ -601,6 +709,12 @@ func getAzureMachinePoolWithMaxPods(name string, maxPods int32) *infrav1.AzureMa
601709
return managedPool
602710
}
603711

712+
func getAzureMachinePoolWithTaints(name string, taints infrav1.Taints) *infrav1.AzureManagedMachinePool {
713+
managedPool := getAzureMachinePool(name, infrav1.NodePoolModeUser)
714+
managedPool.Spec.Taints = taints
715+
return managedPool
716+
}
717+
604718
func getAzureMachinePoolWithOsDiskType(name string, osDiskType string) *infrav1.AzureManagedMachinePool {
605719
managedPool := getAzureMachinePool(name, infrav1.NodePoolModeUser)
606720
managedPool.Spec.OsDiskType = to.StringPtr(osDiskType)

azure/services/agentpools/agentpools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
7878
EnableAutoScaling: agentPoolSpec.EnableAutoScaling,
7979
MaxCount: agentPoolSpec.MaxCount,
8080
MinCount: agentPoolSpec.MinCount,
81+
NodeTaints: &agentPoolSpec.NodeTaints,
8182
AvailabilityZones: &agentPoolSpec.AvailabilityZones,
8283
MaxPods: agentPoolSpec.MaxPods,
8384
OsDiskType: containerservice.OSDiskType(to.String(agentPoolSpec.OsDiskType)),

azure/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ type AgentPoolSpec struct {
346346
// Node labels - labels for all of the nodes present in node pool
347347
NodeLabels map[string]*string `json:"nodeLabels,omitempty"`
348348

349+
// NodeTaints specifies the taints for nodes present in this agent pool.
350+
NodeTaints []string `json:"nodeTaints,omitempty"`
351+
349352
// EnableAutoScaling - Whether to enable auto-scaler
350353
EnableAutoScaling *bool `json:"enableAutoScaling,omitempty"`
351354

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,30 @@ spec:
257257
sku:
258258
description: SKU is the size of the VMs in the node pool.
259259
type: string
260+
taints:
261+
description: Taints specifies the taints for nodes present in this
262+
agent pool.
263+
items:
264+
properties:
265+
effect:
266+
description: Effect specifies the effect for the taint
267+
enum:
268+
- NoSchedule
269+
- NoExecute
270+
- PreferNoSchedule
271+
type: string
272+
key:
273+
description: Key is the key of the taint
274+
type: string
275+
value:
276+
description: Value is the value of the taint
277+
type: string
278+
required:
279+
- effect
280+
- key
281+
- value
282+
type: object
283+
type: array
260284
required:
261285
- mode
262286
- sku

docs/book/src/topics/managedcluster.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,27 @@ spec:
317317
osDiskType: "Ephemeral"
318318
```
319319
320+
### AKS Node Pool Taints
321+
322+
You can configure the `Taints` value for each AKS node pool (`AzureManagedMachinePool`) that you define in your spec.
323+
324+
Below is an example of `taints` configuration for the `agentpool0`:
325+
326+
```
327+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
328+
kind: AzureManagedMachinePool
329+
metadata:
330+
name: agentpool0
331+
spec:
332+
mode: System
333+
osDiskSizeGB: 512
334+
sku: Standard_D2s_v3
335+
taints:
336+
- effect: no-schedule
337+
key: dedicated
338+
value: kafka
339+
```
340+
320341
### Use a public Standard Load Balancer
321342
322343
A public Load Balancer when integrated with AKS serves two purposes:
@@ -371,6 +392,32 @@ spec:
371392
enablePrivateClusterPublicFQDN: false # Allowed only when enablePrivateCluster is true
372393
```
373394
395+
## Immutable fields for Managed Clusters (AKS)
396+
397+
Some fields from the family of Managed Clusters CRD are immutable. Which means
398+
those can only be set during the creation time.
399+
400+
Following is the list of immutable fields for managed clusters:
401+
402+
| CRD | jsonPath | Comment |
403+
|--------------------------|------------------------------------|---------------------------|
404+
| AzureManagedControlPlane | .spec.subscriptionID | |
405+
| AzureManagedControlPlane | .spec.resourceGroupName | |
406+
| AzureManagedControlPlane | .spec.nodeResourceGroupName | |
407+
| AzureManagedControlPlane | .spec.location | |
408+
| AzureManagedControlPlane | .spec.sshPublicKey | |
409+
| AzureManagedControlPlane | .spec.dnsServiceIP | |
410+
| AzureManagedControlPlane | .spec.networkPlugin | |
411+
| AzureManagedControlPlane | .spec.networkPolicy | |
412+
| AzureManagedControlPlane | .spec.loadBalancerSKU | |
413+
| AzureManagedControlPlane | .spec.apiServerAccessProfile | except AuthorizedIPRanges |
414+
| AzureManagedMachinePool | .spec.sku | |
415+
| AzureManagedMachinePool | .spec.osDiskSizeGB | |
416+
| AzureManagedMachinePool | .spec.osDiskType | |
417+
| AzureManagedMachinePool | .spec.taints | |
418+
| AzureManagedMachinePool | .spec.availabilityZones | |
419+
| AzureManagedMachinePool | .spec.maxPods | |
420+
374421
## Features
375422
376423
AKS clusters deployed from CAPZ currently only support a limited,

exp/api/v1alpha3/azuremanagedmachinepool_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (src *AzureManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
3838

3939
dst.Spec.Name = restored.Spec.Name
4040
dst.Spec.Scaling = restored.Spec.Scaling
41+
dst.Spec.Taints = restored.Spec.Taints
4142
dst.Spec.AvailabilityZones = restored.Spec.AvailabilityZones
4243
dst.Spec.MaxPods = restored.Spec.MaxPods
4344
dst.Spec.OsDiskType = restored.Spec.OsDiskType

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
@@ -38,6 +38,7 @@ func (src *AzureManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
3838

3939
dst.Spec.Scaling = restored.Spec.Scaling
4040
dst.Spec.Name = restored.Spec.Name
41+
dst.Spec.Taints = restored.Spec.Taints
4142
dst.Spec.AvailabilityZones = restored.Spec.AvailabilityZones
4243
dst.Spec.MaxPods = restored.Spec.MaxPods
4344
dst.Spec.OsDiskType = restored.Spec.OsDiskType

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)