mirror of https://github.com/kubernetes/kops.git
Fix Azure zone number format passed to VMSS API
This commit is contained in:
parent
9552b25050
commit
affbeb3c5b
|
@ -26,6 +26,7 @@ import (
|
|||
"k8s.io/kops/pkg/model"
|
||||
"k8s.io/kops/pkg/model/defaults"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/azure"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/azuretasks"
|
||||
)
|
||||
|
||||
|
@ -70,6 +71,14 @@ func (b *VMScaleSetModelBuilder) buildVMScaleSetTask(
|
|||
name string,
|
||||
ig *kops.InstanceGroup,
|
||||
) (*azuretasks.VMScaleSet, error) {
|
||||
var azNumbers []string
|
||||
for _, zone := range ig.Spec.Zones {
|
||||
az, err := azure.ZoneToAvailabilityZoneNumber(zone)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
azNumbers = append(azNumbers, az)
|
||||
}
|
||||
t := &azuretasks.VMScaleSet{
|
||||
Name: fi.String(name),
|
||||
Lifecycle: b.Lifecycle,
|
||||
|
@ -78,7 +87,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,
|
||||
Zones: azNumbers,
|
||||
}
|
||||
|
||||
var err error
|
||||
|
|
|
@ -30,3 +30,13 @@ func ZoneToLocation(zone string) (string, error) {
|
|||
}
|
||||
return l[0], nil
|
||||
}
|
||||
|
||||
// ZoneToAvailabilityZoneNumber extracts the availability zone number from a zone of the
|
||||
// form <location>-<available-zone-number>..
|
||||
func ZoneToAvailabilityZoneNumber(zone string) (string, error) {
|
||||
l := strings.Split(zone, "-")
|
||||
if len(l) != 2 {
|
||||
return "", fmt.Errorf("invalid Azure zone: %q ", zone)
|
||||
}
|
||||
return l[1], nil
|
||||
}
|
||||
|
|
|
@ -61,3 +61,44 @@ func TestZoneToLocation(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestZoneToAvailabilityZoneNumber(t *testing.T) {
|
||||
testCases := []struct {
|
||||
zone string
|
||||
success bool
|
||||
azNumber string
|
||||
}{
|
||||
{
|
||||
zone: "eastus-1",
|
||||
success: true,
|
||||
azNumber: "1",
|
||||
},
|
||||
{
|
||||
zone: "eastus",
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
zone: "eastus-1-2",
|
||||
success: false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
|
||||
azNum, err := ZoneToAvailabilityZoneNumber(tc.zone)
|
||||
if !tc.success {
|
||||
if err == nil {
|
||||
t.Fatalf("unexpected success")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
if azNum != tc.azNumber {
|
||||
t.Errorf("expected %s but got %s", tc.azNumber, azNum)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue