Skip to content

Commit

Permalink
availability zones support for managedclusters
Browse files Browse the repository at this point in the history
  • Loading branch information
LochanRn committed Aug 9, 2021
1 parent 7f6a9ca commit 29fe21a
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 22 deletions.
22 changes: 12 additions & 10 deletions azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ import (

// Spec contains properties to create a agent pool.
type Spec struct {
Name string
ResourceGroup string
Cluster string
Version *string
SKU string
Replicas int32
OSDiskSizeGB int32
VnetSubnetID string
Mode string
Name string
ResourceGroup string
Cluster string
Version *string
SKU string
Replicas int32
OSDiskSizeGB int32
VnetSubnetID string
Mode string
AvailabilityZones []string
}

// Reconcile idempotently creates or updates a agent pool, if possible.
Expand All @@ -63,6 +64,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
OrchestratorVersion: agentPoolSpec.Version,
VnetSubnetID: &agentPoolSpec.VnetSubnetID,
Mode: containerservice.AgentPoolMode(agentPoolSpec.Mode),
AvailabilityZones: &agentPoolSpec.AvailabilityZones,
},
}

Expand Down Expand Up @@ -107,7 +109,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
}

// Diff and check if we require an update
diff := cmp.Diff(existingProfile, normalizedProfile)
diff := cmp.Diff(normalizedProfile, existingProfile)
if diff != "" {
klog.V(2).Infof("Update required (+new -old):\n%s", diff)
err = s.Client.CreateOrUpdate(ctx, agentPoolSpec.ResourceGroup, agentPoolSpec.Cluster, agentPoolSpec.Name, profile)
Expand Down
15 changes: 8 additions & 7 deletions azure/services/managedclusters/managedclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ func (s *Service) Reconcile(ctx context.Context) error {
for i := range managedClusterSpec.AgentPools {
pool := managedClusterSpec.AgentPools[i]
profile := containerservice.ManagedClusterAgentPoolProfile{
Name: &pool.Name,
VMSize: &pool.SKU,
OsDiskSizeGB: &pool.OSDiskSizeGB,
Count: &pool.Replicas,
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
VnetSubnetID: &managedClusterSpec.VnetSubnetID,
Mode: containerservice.AgentPoolModeSystem,
Name: &pool.Name,
VMSize: &pool.SKU,
OsDiskSizeGB: &pool.OSDiskSizeGB,
Count: &pool.Replicas,
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
VnetSubnetID: &managedClusterSpec.VnetSubnetID,
Mode: containerservice.AgentPoolModeSystem,
AvailabilityZones: &pool.AvailabilityZones,
}
*managedCluster.AgentPoolProfiles = append(*managedCluster.AgentPoolProfiles, profile)
}
Expand Down
9 changes: 5 additions & 4 deletions azure/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ type ManagedClusterSpec struct {

// AgentPoolSpec contains agent pool specification details.
type AgentPoolSpec struct {
Name string
SKU string
Replicas int32
OSDiskSizeGB int32
Name string
SKU string
Replicas int32
OSDiskSizeGB int32
AvailabilityZones []string
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ spec:
description: AzureManagedMachinePoolSpec defines the desired state of
AzureManagedMachinePool.
properties:
availabilityZones:
description: AvailabilityZones - Availability zones for nodes. Must
use VirtualMachineScaleSets AgentPoolType.
items:
type: string
type: array
mode:
description: 'Mode - represents mode of an agent pool. Possible values
include: System, User.'
Expand Down Expand Up @@ -117,6 +123,12 @@ spec:
description: AzureManagedMachinePoolSpec defines the desired state of
AzureManagedMachinePool.
properties:
availabilityZones:
description: AvailabilityZones - Availability zones for nodes. Must
use VirtualMachineScaleSets AgentPoolType.
items:
type: string
type: array
mode:
description: 'Mode - represents mode of an agent pool. Possible values
include: System, User.'
Expand Down
3 changes: 3 additions & 0 deletions exp/api/v1alpha3/azuremanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type AzureManagedMachinePoolSpec struct {
// +kubebuilder:validation:Enum=System;User
Mode string `json:"mode"`

// AvailabilityZones - Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType.
AvailabilityZones []string `json:"availabilityZones,omitempty"`

// SKU is the size of the VMs in the node pool.
SKU string `json:"sku"`

Expand Down
2 changes: 2 additions & 0 deletions exp/api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions exp/api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions exp/api/v1alpha4/azuremanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type AzureManagedMachinePoolSpec struct {
// +kubebuilder:validation:Enum=System;User
Mode string `json:"mode"`

// AvailabilityZones - Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType.
AvailabilityZones []string `json:"availabilityZones,omitempty"`

// SKU is the size of the VMs in the node pool.
SKU string `json:"sku"`

Expand Down
9 changes: 9 additions & 0 deletions exp/api/v1alpha4/azuremanagedmachinepool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha4

import (
"context"
"reflect"

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -86,6 +87,14 @@ func (r *AzureManagedMachinePool) ValidateUpdate(oldRaw runtime.Object, client c
}
}

if !reflect.DeepEqual(r.Spec.AvailabilityZones, old.Spec.AvailabilityZones) {
allErrs = append(allErrs,
field.Invalid(
field.NewPath("Spec", "AvailabilityZones"),
r.Spec.AvailabilityZones,
"field is immutable"))
}

if r.Spec.Mode != string(NodePoolModeSystem) && old.Spec.Mode == string(NodePoolModeSystem) {
// validate for last system node pool
if err := r.validateLastSystemNodePool(client); err != nil {
Expand Down
39 changes: 39 additions & 0 deletions exp/api/v1alpha4/azuremanagedmachinepool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,45 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) {
},
wantErr: true,
},
{
name: "Cannot add AvailabilityZones after creating agentpool",
new: &AzureManagedMachinePool{
Spec: AzureManagedMachinePoolSpec{
Mode: "System",
SKU: "StandardD2S_V3",
OSDiskSizeGB: to.Int32Ptr(512),
},
},
old: &AzureManagedMachinePool{
Spec: AzureManagedMachinePoolSpec{
Mode: "System",
SKU: "StandardD2S_V3",
OSDiskSizeGB: to.Int32Ptr(512),
AvailabilityZones: []string{"1", "2", "3"},
},
},
wantErr: true,
},
{
name: "Cannot change AvailabilityZones of the agentpool",
new: &AzureManagedMachinePool{
Spec: AzureManagedMachinePoolSpec{
Mode: "System",
SKU: "StandardD2S_V3",
OSDiskSizeGB: to.Int32Ptr(512),
AvailabilityZones: []string{"1", "2"},
},
},
old: &AzureManagedMachinePool{
Spec: AzureManagedMachinePoolSpec{
Mode: "System",
SKU: "StandardD2S_V3",
OSDiskSizeGB: to.Int32Ptr(512),
AvailabilityZones: []string{"1", "2", "3"},
},
},
wantErr: true,
},
}
var client client.Client
for _, tc := range tests {
Expand Down
5 changes: 5 additions & 0 deletions exp/api/v1alpha4/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion exp/controllers/azuremanagedmachinepool_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func (s *azureManagedMachinePoolService) Reconcile(ctx context.Context, scope *s
scope.ControlPlane.Spec.VirtualNetwork.Name,
scope.ControlPlane.Spec.VirtualNetwork.Subnet.Name,
),
Mode: scope.InfraMachinePool.Spec.Mode,
Mode: scope.InfraMachinePool.Spec.Mode,
AvailabilityZones: scope.InfraMachinePool.Spec.AvailabilityZones,
}

if scope.InfraMachinePool.Spec.OSDiskSizeGB != nil {
Expand Down

0 comments on commit 29fe21a

Please sign in to comment.