Azure - support VMSS availability zones

Azure's subnets are regional so we use similar functionality to GCE where we reference the InstanceGroup's zones rather than a subnet's zone.
IG Zones are already populated on cluster creation here: b358037896/upup/pkg/fi/cloudup/new_cluster.go (L682-L684)
This commit is contained in:
Peter Rifel 2021-07-08 22:41:00 -04:00
parent b358037896
commit 9552b25050
No known key found for this signature in database
GPG Key ID: BC6469E5B16DB2B6
3 changed files with 16 additions and 1 deletions

View File

@ -78,6 +78,7 @@ func (b *VMScaleSetModelBuilder) buildVMScaleSetTask(
SKUName: fi.String(ig.Spec.MachineType),
ComputerNamePrefix: fi.String(ig.Name),
AdminUser: fi.String(b.Cluster.Spec.CloudConfig.Azure.AdminUser),
Zones: ig.Spec.Zones,
}
var err error

View File

@ -116,6 +116,7 @@ type VMScaleSet struct {
// CustomData is the user data configuration
CustomData fi.Resource
Tags map[string]*string
Zones []string
PrincipalID *string
}
@ -231,6 +232,9 @@ func (s *VMScaleSet) Find(c *fi.Context) (*VMScaleSet, error) {
Name: to.StringPtr(loadBalancerID.LoadBalancerName),
}
}
if found.Zones != nil {
vmss.Zones = *found.Zones
}
return vmss, nil
}
@ -367,7 +371,8 @@ func (s *VMScaleSet) RenderAzure(t *azure.AzureAPITarget, a, e, changes *VMScale
Identity: &compute.VirtualMachineScaleSetIdentity{
Type: compute.ResourceIdentityTypeSystemAssigned,
},
Tags: e.Tags,
Tags: e.Tags,
Zones: &e.Zones,
}
result, err := t.Cloud.VMScaleSet().CreateOrUpdate(

View File

@ -86,6 +86,7 @@ func newTestVMScaleSet() *VMScaleSet {
SSHPublicKey: to.StringPtr("ssh"),
CustomData: fi.NewStringResource("custom"),
Tags: map[string]*string{},
Zones: []string{"zone1"},
}
}
@ -128,6 +129,10 @@ func TestVMScaleSetRenderAzure(t *testing.T) {
if expected.PrincipalID == nil {
t.Errorf("unexpected nil principalID")
}
if a, e := *actual.Zones, expected.Zones; !reflect.DeepEqual(a, e) {
t.Errorf("unexpected Zone: expected %s, but got %s", e, a)
}
}
func TestVMScaleSetFind(t *testing.T) {
@ -253,6 +258,7 @@ func TestVMScaleSetFind(t *testing.T) {
Identity: &compute.VirtualMachineScaleSetIdentity{
Type: compute.ResourceIdentityTypeSystemAssigned,
},
Zones: &[]string{"zone1"},
}
if _, err := cloud.VMScaleSet().CreateOrUpdate(context.Background(), *rg.Name, *vmss.Name, vmssParameters); err != nil {
t.Fatalf("failed to create: %s", err)
@ -288,6 +294,9 @@ func TestVMScaleSetFind(t *testing.T) {
if !*actual.RequirePublicIP {
t.Errorf("unexpected require public IP")
}
if a, e := actual.Zones, *vmssParameters.Zones; !reflect.DeepEqual(a, e) {
t.Errorf("unexpected Zone: expected %s, but got %s", e, a)
}
}
func TestVMScaleSetRun(t *testing.T) {