From 400502cc9d041a822d3f2d70f02f648984ae760e Mon Sep 17 00:00:00 2001 From: Sylvain Rabot Date: Thu, 22 Nov 2018 16:42:38 +0100 Subject: [PATCH] Make AvailabilitySet profile for master use Availability Zones Signed-off-by: Sylvain Rabot --- parts/k8s/kubernetesagentresourcesvmas.t | 16 +++++++++++++--- parts/k8s/kubernetesmasterresources.t | 24 ++++++++++++++++++++++-- pkg/api/vlabs/validate.go | 3 --- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/parts/k8s/kubernetesagentresourcesvmas.t b/parts/k8s/kubernetesagentresourcesvmas.t index d1ede435b8..86176322bc 100644 --- a/parts/k8s/kubernetesagentresourcesvmas.t +++ b/parts/k8s/kubernetesagentresourcesvmas.t @@ -77,7 +77,8 @@ "type": "Microsoft.Network/networkInterfaces" }, {{if .IsManagedDisks}} - { + {{if not HasAvailabilityZones .}} + { "location": "[variables('location')]", "name": "[variables('{{.Name}}AvailabilitySet')]", "apiVersion": "[variables('apiVersionCompute')]", @@ -91,6 +92,7 @@ }, "type": "Microsoft.Compute/availabilitySets" }, + {{end}} {{else if .IsStorageAccount}} { "apiVersion": "[variables('apiVersionStorage')]", @@ -134,6 +136,7 @@ "type": "Microsoft.Storage/storageAccounts" }, {{end}} + {{if not HasAvailabilityZones .}} { "location": "[variables('location')]", "name": "[variables('{{.Name}}AvailabilitySet')]", @@ -141,6 +144,7 @@ "properties": {}, "type": "Microsoft.Compute/availabilitySets" }, + {{end}} {{end}} { "apiVersion": "[variables('apiVersionCompute')]", @@ -156,8 +160,10 @@ "[concat('Microsoft.Storage/storageAccounts/',variables('storageAccountPrefixes')[mod(add(add(div(copyIndex(variables('{{.Name}}Offset')),variables('maxVMsPerStorageAccount')),variables('{{.Name}}StorageAccountOffset')),variables('dataStorageAccountPrefixSeed')),variables('storageAccountPrefixesCount'))],variables('storageAccountPrefixes')[div(add(add(div(copyIndex(variables('{{.Name}}Offset')),variables('maxVMsPerStorageAccount')),variables('{{.Name}}StorageAccountOffset')),variables('dataStorageAccountPrefixSeed')),variables('storageAccountPrefixesCount'))],variables('{{.Name}}DataAccountName'))]", {{end}} {{end}} - "[concat('Microsoft.Network/networkInterfaces/', variables('{{.Name}}VMNamePrefix'), 'nic-', copyIndex(variables('{{.Name}}Offset')))]", - "[concat('Microsoft.Compute/availabilitySets/', variables('{{.Name}}AvailabilitySet'))]" + {{if not HasAvailabilityZones .}} + "[concat('Microsoft.Compute/availabilitySets/', variables('{{.Name}}AvailabilitySet'))]", + {{end}} + "[concat('Microsoft.Network/networkInterfaces/', variables('{{.Name}}VMNamePrefix'), 'nic-', copyIndex(variables('{{.Name}}Offset')))]" ], "tags": { @@ -191,9 +197,13 @@ }, {{end}} "properties": { + {{if not HasAvailabilityZones .}} "availabilitySet": { "id": "[resourceId('Microsoft.Compute/availabilitySets',variables('{{.Name}}AvailabilitySet'))]" }, + {{ else}} + "zones": "split(string([parameters('availabilityZones')[mod(copyIndex(variables('{{.Name}}Offset')), length(parameters('availabilityZones')))]]), ',')" + {{end}} "hardwareProfile": { "vmSize": "[variables('{{.Name}}VMSize')]" }, diff --git a/parts/k8s/kubernetesmasterresources.t b/parts/k8s/kubernetesmasterresources.t index 466ede474f..738b7a0ad5 100644 --- a/parts/k8s/kubernetesmasterresources.t +++ b/parts/k8s/kubernetesmasterresources.t @@ -1,4 +1,5 @@ {{if .MasterProfile.IsManagedDisks}} + {{if not .MasterProfile.HasAvailabilityZones}} { "apiVersion": "[variables('apiVersionCompute')]", "location": "[variables('location')]", @@ -13,7 +14,9 @@ }, "type": "Microsoft.Compute/availabilitySets" }, + {{end}} {{else if .MasterProfile.IsStorageAccount}} + {{if not .MasterProfile.HasAvailabilityZones}} { "apiVersion": "[variables('apiVersionCompute')]", "location": "[variables('location')]", @@ -21,6 +24,7 @@ "properties": {}, "type": "Microsoft.Compute/availabilitySets" }, + {{end}} { "apiVersion": "[variables('apiVersionStorage')]", {{if not IsPrivateCluster}} @@ -180,7 +184,10 @@ "dnsSettings": { "domainNameLabel": "[variables('masterFqdnPrefix')]" }, - "publicIPAllocationMethod": "Dynamic" + "publicIPAllocationMethod": "Static" + }, + "sku": { + "name": "[variables('loadBalancerSku')]" }, "type": "Microsoft.Network/publicIPAddresses" }, @@ -241,6 +248,9 @@ } ] }, + "sku": { + "name": "[variables('loadBalancerSku')]" + }, "type": "Microsoft.Network/loadBalancers" }, { @@ -649,6 +659,9 @@ } ] }, + "sku": { + "name": "[variables('loadBalancerSku')]" + }, "type": "Microsoft.Network/loadBalancers" }, {{end}} @@ -696,7 +709,7 @@ "tenantId": "[variables('tenantID')]", {{if UseManagedIdentity}} {{if UserAssignedIDEnabled}} - "accessPolicies": + "accessPolicies": [ { "tenantId": "[variables('tenantID')]", @@ -772,7 +785,9 @@ }, "dependsOn": [ "[concat('Microsoft.Network/networkInterfaces/', variables('masterVMNamePrefix'), 'nic-', copyIndex(variables('masterOffset')))]" + {{if not .MasterProfile.HasAvailabilityZones}} ,"[concat('Microsoft.Compute/availabilitySets/',variables('masterAvailabilitySet'))]" + {{end}} {{if .MasterProfile.IsStorageAccount}} ,"[variables('masterStorageAccountName')]" {{end}} @@ -787,6 +802,9 @@ }, "location": "[variables('location')]", "name": "[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')))]", + {{if .MasterProfile.HasAvailabilityZones}} + "zones": "[split(string(parameters('availabilityZones')[mod(copyIndex(variables('masterOffset')), length(parameters('availabilityZones')))]), ',')]", + {{end}} {{if UseManagedIdentity}} {{if UserAssignedIDEnabled}} "identity": { @@ -809,9 +827,11 @@ }, {{end}} "properties": { + {{if not .MasterProfile.HasAvailabilityZones}} "availabilitySet": { "id": "[resourceId('Microsoft.Compute/availabilitySets',variables('masterAvailabilitySet'))]" }, + {{end}} "hardwareProfile": { "vmSize": "[parameters('masterVMSize')]" }, diff --git a/pkg/api/vlabs/validate.go b/pkg/api/vlabs/validate.go index 8d5dc1c596..d6a24b1bff 100644 --- a/pkg/api/vlabs/validate.go +++ b/pkg/api/vlabs/validate.go @@ -491,9 +491,6 @@ func (a *Properties) validateZones() error { if a.HasAvailabilityZones() { if a.MastersAndAgentsUseAvailabilityZones() { // master profile - if a.MasterProfile.AvailabilityProfile != VirtualMachineScaleSets { - return errors.New("Availability Zones are not supported with an AvailabilitySet. Please set availabilityProfile to VirtualMachineScaleSets") - } if a.MasterProfile.Count < len(a.MasterProfile.AvailabilityZones)*2 { return errors.New("the node count and the number of availability zones provided can result in zone imbalance. To achieve zone balance, each zone should have at least 2 nodes or more") }