Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix Provisioning to Unavailable AZs #1479

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1alpha6/openstackcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (r *OpenStackCluster) ValidateUpdate(oldRaw runtime.Object) error {
r.Spec.APIServerLoadBalancer.AllowedCIDRs = []string{}
}

// Allow changes to the availability zones.
old.Spec.ControlPlaneAvailabilityZones = []string{}
r.Spec.ControlPlaneAvailabilityZones = []string{}

spjmurray marked this conversation as resolved.
Show resolved Hide resolved
if !reflect.DeepEqual(old.Spec, r.Spec) {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
}
Expand Down
59 changes: 59 additions & 0 deletions api/v1alpha6/openstackcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,65 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
},
wantErr: false,
},
{
name: "Adding OpenStackCluster.Spec.ControlPlaneAvailabilityZones is allowed",
oldTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
},
},
newTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
ControlPlaneAvailabilityZones: []string{
"alice",
"bob",
},
},
},
wantErr: false,
},
{
name: "Modifying OpenStackCluster.Spec.ControlPlaneAvailabilityZones is allowed",
oldTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
ControlPlaneAvailabilityZones: []string{
"alice",
"bob",
},
},
},
newTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
ControlPlaneAvailabilityZones: []string{
"alice",
"bob",
"eve",
},
},
},
wantErr: false,
},
{
name: "Removing OpenStackCluster.Spec.ControlPlaneAvailabilityZones is allowed",
oldTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
ControlPlaneAvailabilityZones: []string{
"alice",
"bob",
},
},
},
newTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion pkg/cloud/services/compute/availabilityzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ func (s *Service) GetAvailabilityZones() ([]availabilityzones.AvailabilityZone,
return nil, fmt.Errorf("error extracting availability zone list: %v", err)
}

return availabilityZoneList, nil
available := make([]availabilityzones.AvailabilityZone, 0, len(availabilityZoneList))

for _, az := range availabilityZoneList {
if az.ZoneState.Available {
available = append(available, az)
}
}

return available, nil
}