Skip to content

Commit c61ea15

Browse files
authored
Merge pull request #1488 from k8s-infra-cherrypick-robot/cherry-pick-1479-to-release-0.7
[release-0.7] 🐛 Fix Provisioning to Unavailable AZs
2 parents 5f18966 + 0a31fdc commit c61ea15

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

api/v1alpha6/openstackcluster_webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func (r *OpenStackCluster) ValidateUpdate(oldRaw runtime.Object) error {
115115
r.Spec.APIServerLoadBalancer.AllowedCIDRs = []string{}
116116
}
117117

118+
// Allow changes to the availability zones.
119+
old.Spec.ControlPlaneAvailabilityZones = []string{}
120+
r.Spec.ControlPlaneAvailabilityZones = []string{}
121+
118122
if !reflect.DeepEqual(old.Spec, r.Spec) {
119123
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
120124
}

api/v1alpha6/openstackcluster_webhook_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,65 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
175175
},
176176
wantErr: false,
177177
},
178+
{
179+
name: "Adding OpenStackCluster.Spec.ControlPlaneAvailabilityZones is allowed",
180+
oldTemplate: &OpenStackCluster{
181+
Spec: OpenStackClusterSpec{
182+
CloudName: "foobar",
183+
},
184+
},
185+
newTemplate: &OpenStackCluster{
186+
Spec: OpenStackClusterSpec{
187+
CloudName: "foobar",
188+
ControlPlaneAvailabilityZones: []string{
189+
"alice",
190+
"bob",
191+
},
192+
},
193+
},
194+
wantErr: false,
195+
},
196+
{
197+
name: "Modifying OpenStackCluster.Spec.ControlPlaneAvailabilityZones is allowed",
198+
oldTemplate: &OpenStackCluster{
199+
Spec: OpenStackClusterSpec{
200+
CloudName: "foobar",
201+
ControlPlaneAvailabilityZones: []string{
202+
"alice",
203+
"bob",
204+
},
205+
},
206+
},
207+
newTemplate: &OpenStackCluster{
208+
Spec: OpenStackClusterSpec{
209+
CloudName: "foobar",
210+
ControlPlaneAvailabilityZones: []string{
211+
"alice",
212+
"bob",
213+
"eve",
214+
},
215+
},
216+
},
217+
wantErr: false,
218+
},
219+
{
220+
name: "Removing OpenStackCluster.Spec.ControlPlaneAvailabilityZones is allowed",
221+
oldTemplate: &OpenStackCluster{
222+
Spec: OpenStackClusterSpec{
223+
CloudName: "foobar",
224+
ControlPlaneAvailabilityZones: []string{
225+
"alice",
226+
"bob",
227+
},
228+
},
229+
},
230+
newTemplate: &OpenStackCluster{
231+
Spec: OpenStackClusterSpec{
232+
CloudName: "foobar",
233+
},
234+
},
235+
wantErr: false,
236+
},
178237
}
179238
for _, tt := range tests {
180239
t.Run(tt.name, func(t *testing.T) {

pkg/cloud/services/compute/availabilityzone.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,13 @@ func (s *Service) GetAvailabilityZones() ([]availabilityzones.AvailabilityZone,
2828
return nil, fmt.Errorf("error extracting availability zone list: %v", err)
2929
}
3030

31-
return availabilityZoneList, nil
31+
available := make([]availabilityzones.AvailabilityZone, 0, len(availabilityZoneList))
32+
33+
for _, az := range availabilityZoneList {
34+
if az.ZoneState.Available {
35+
available = append(available, az)
36+
}
37+
}
38+
39+
return available, nil
3240
}

0 commit comments

Comments
 (0)