Skip to content

Commit

Permalink
availability zones support for managedclusters
Browse files Browse the repository at this point in the history
removed az in v1a3 and v1a4
  • Loading branch information
LochanRn committed Nov 20, 2021
1 parent ea26d56 commit 3848ded
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 15 deletions.
14 changes: 8 additions & 6 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,12 @@ func (s *ManagedControlPlaneScope) GetAgentPoolSpecs(ctx context.Context) ([]azu
}

ammp := azure.AgentPoolSpec{
Name: to.String(pool.Spec.Name),
SKU: pool.Spec.SKU,
Replicas: 1,
OSDiskSizeGB: 0,
Mode: pool.Spec.Mode,
Name: to.String(pool.Spec.Name),
SKU: pool.Spec.SKU,
Replicas: 1,
OSDiskSizeGB: 0,
Mode: pool.Spec.Mode,
AvailabilityZones: pool.Spec.AvailabilityZones,
}

// Set optional values
Expand Down Expand Up @@ -541,7 +542,8 @@ func (s *ManagedControlPlaneScope) AgentPoolSpec() azure.AgentPoolSpec {
s.ControlPlane.Spec.VirtualNetwork.Name,
s.ControlPlane.Spec.VirtualNetwork.Subnet.Name,
),
Mode: s.InfraMachinePool.Spec.Mode,
Mode: s.InfraMachinePool.Spec.Mode,
AvailabilityZones: s.InfraMachinePool.Spec.AvailabilityZones,
}

if s.InfraMachinePool.Spec.OSDiskSizeGB != nil {
Expand Down
3 changes: 2 additions & 1 deletion azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
EnableAutoScaling: agentPoolSpec.EnableAutoScaling,
MaxCount: agentPoolSpec.MaxCount,
MinCount: agentPoolSpec.MinCount,
AvailabilityZones: &agentPoolSpec.AvailabilityZones,
},
}

Expand Down Expand Up @@ -131,7 +132,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
}

// Diff and check if we require an update
diff := cmp.Diff(existingProfile, normalizedProfile)
diff := cmp.Diff(normalizedProfile, existingProfile)
if diff != "" {
log.V(2).Info(fmt.Sprintf("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 @@ -235,13 +235,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.AgentPoolMode(pool.Mode),
Name: &pool.Name,
VMSize: &pool.SKU,
OsDiskSizeGB: &pool.OSDiskSizeGB,
Count: &pool.Replicas,
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
VnetSubnetID: &managedClusterSpec.VnetSubnetID,
Mode: containerservice.AgentPoolMode(pool.Mode),
AvailabilityZones: &pool.AvailabilityZones,
}
*managedCluster.AgentPoolProfiles = append(*managedCluster.AgentPoolProfiles, profile)
}
Expand Down
3 changes: 3 additions & 0 deletions azure/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,7 @@ type AgentPoolSpec struct {

// EnableAutoScaling - Whether to enable auto-scaler
EnableAutoScaling *bool `json:"enableAutoScaling,omitempty"`

// AvailabilityZones represents the Availability zones for nodes in the AgentPool.
AvailabilityZones []string
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,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
1 change: 1 addition & 0 deletions exp/api/v1alpha3/azuremanagedmachinepool_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (src *AzureManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error { //

dst.Spec.Name = restored.Spec.Name
dst.Spec.Scaling = restored.Spec.Scaling
dst.Spec.AvailabilityZones = restored.Spec.AvailabilityZones

return nil
}
Expand Down
1 change: 1 addition & 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.

7 changes: 6 additions & 1 deletion exp/api/v1alpha4/azuremanagedmachinepool_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ func (src *AzureManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.Scaling = restored.Spec.Scaling
return Convert_v1alpha4_AzureManagedMachinePool_To_v1beta1_AzureManagedMachinePool(src, dst, nil)
dst.Spec.Name = restored.Spec.Name
dst.Spec.AvailabilityZones = restored.Spec.AvailabilityZones

return nil
}

// ConvertFrom converts from the Hub version (v1beta1) to this version.
Expand All @@ -56,6 +60,7 @@ func (dst *AzureManagedMachinePool) ConvertFrom(srcRaw conversion.Hub) error {
return nil
}

// Convert_v1beta1_AzureManagedMachinePoolSpec_To_v1alpha4_AzureManagedMachinePoolSpec is an autogenerated conversion function.
func Convert_v1beta1_AzureManagedMachinePoolSpec_To_v1alpha4_AzureManagedMachinePoolSpec(in *expv1beta1.AzureManagedMachinePoolSpec, out *AzureManagedMachinePoolSpec, s apiconversion.Scope) error {
return autoConvert_v1beta1_AzureManagedMachinePoolSpec_To_v1alpha4_AzureManagedMachinePoolSpec(in, out, s)
}
1 change: 1 addition & 0 deletions exp/api/v1alpha4/zz_generated.conversion.go

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

4 changes: 4 additions & 0 deletions exp/api/v1beta1/azuremanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ type AzureManagedMachinePoolSpec struct {
// +optional
OSDiskSizeGB *int32 `json:"osDiskSizeGB,omitempty"`

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

// ProviderIDList is the unique identifier as specified by the cloud provider.
// +optional
ProviderIDList []string `json:"providerIDList,omitempty"`
Expand Down
26 changes: 26 additions & 0 deletions exp/api/v1beta1/azuremanagedmachinepool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func (r *AzureManagedMachinePool) ValidateUpdate(oldRaw runtime.Object, client c
}
}

if !ensureStringSlicesAreEqual(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 Expand Up @@ -162,3 +170,21 @@ func (r *AzureManagedMachinePool) validateLastSystemNodePool(cli client.Client)
}
return nil
}

func ensureStringSlicesAreEqual(a []string, b []string) bool {
if len(a) != len(b) {
return false
}

m := map[string]bool{}
for _, v := range a {
m[v] = true
}

for _, v := range b {
if _, ok := m[v]; !ok {
return false
}
}
return true
}
78 changes: 78 additions & 0 deletions exp/api/v1beta1/azuremanagedmachinepool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,84 @@ 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),
AvailabilityZones: []string{"1", "2", "3"},
},
},
old: &AzureManagedMachinePool{
Spec: AzureManagedMachinePoolSpec{
Mode: "System",
SKU: "StandardD2S_V3",
OSDiskSizeGB: to.Int32Ptr(512),
},
},
wantErr: true,
},
{
name: "Cannot remove 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,
},
{
name: "AvailabilityZones order can be different",
new: &AzureManagedMachinePool{
Spec: AzureManagedMachinePoolSpec{
Mode: "System",
SKU: "StandardD2S_V3",
OSDiskSizeGB: to.Int32Ptr(512),
AvailabilityZones: []string{"1", "3", "2"},
},
},
old: &AzureManagedMachinePool{
Spec: AzureManagedMachinePoolSpec{
Mode: "System",
SKU: "StandardD2S_V3",
OSDiskSizeGB: to.Int32Ptr(512),
AvailabilityZones: []string{"1", "2", "3"},
},
},
wantErr: false,
},
}
var client client.Client
for _, tc := range tests {
Expand Down
5 changes: 5 additions & 0 deletions exp/api/v1beta1/zz_generated.deepcopy.go

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

0 comments on commit 3848ded

Please sign in to comment.