Skip to content

Commit f393bc9

Browse files
committed
Allow explicitly empty volume AZ
Replaces an AvailabilityZone string for volumes with a VolumeAvailabilityZone struct which allows more flexibility in defaulting behaviour. Specifically it enables us to express both the current default behaviour where we take the volume AZ from the Machine, and a new default behaviour where to don't specify a volume AZ at all. In making this change to both RootVolume and AdditionalBlockDevices we use common code for both APIs. This has the result of updating RootVolume to be consistent with AdditionalBlockDevices.
1 parent 626738a commit f393bc9

27 files changed

+1246
-231
lines changed

.golangci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ issues:
172172
- stylecheck
173173
text: "ST1003: should not use underscores in Go names;"
174174
path: (api\/.*|pkg/utils/optional)\/.*conversion.*\.go$
175+
- linters:
176+
- stylecheck
177+
text: "ST1003: should not use underscores in Go names;"
178+
path: pkg/utils/conversioncommon/.*.go
175179

176180
run:
177181
timeout: 10m

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ generate-conversion-gen: $(CONVERSION_GEN)
269269
--input-dirs=$(capo_module)/api/v1alpha6 \
270270
--input-dirs=$(capo_module)/api/v1alpha7 \
271271
--extra-dirs=$(capo_module)/pkg/utils/optional \
272+
--extra-dirs=$(capo_module)/pkg/utils/conversioncommon \
272273
--output-file-base=zz_generated.conversion \
273274
--trim-path-prefix=$(capo_module)/ \
274275
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

api/v1alpha5/conversion.go

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
2727

2828
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
29+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/conversioncommon"
2930
)
3031

3132
var _ ctrlconversion.Convertible = &OpenStackCluster{}
@@ -813,6 +814,18 @@ func Convert_v1beta1_NetworkParam_To_v1alpha5_NetworkFilter(in *infrav1.NetworkP
813814
return nil
814815
}
815816

817+
func Convert_v1alpha5_RootVolume_To_v1beta1_RootVolume(in *RootVolume, out *infrav1.RootVolume, s conversion.Scope) error {
818+
out.SizeGiB = in.Size
819+
out.Type = in.VolumeType
820+
return conversioncommon.Convert_string_To_Pointer_v1beta1_VolumeAvailabilityZone(&in.AvailabilityZone, &out.AvailabilityZone, s)
821+
}
822+
823+
func Convert_v1beta1_RootVolume_To_v1alpha5_RootVolume(in *infrav1.RootVolume, out *RootVolume, s conversion.Scope) error {
824+
out.Size = in.SizeGiB
825+
out.VolumeType = in.Type
826+
return conversioncommon.Convert_Pointer_v1beta1_VolumeAvailabilityZone_To_string(&in.AvailabilityZone, &out.AvailabilityZone, s)
827+
}
828+
816829
// conversion-gen registers the following functions so we have to define them, but nothing should ever call them.
817830
func Convert_v1alpha5_NetworkFilter_To_v1beta1_NetworkFilter(_ *NetworkFilter, _ *infrav1.NetworkFilter, _ conversion.Scope) error {
818831
return errors.New("Convert_v1alpha6_NetworkFilter_To_v1beta1_NetworkFilter should not be called")

api/v1alpha5/zz_generated.conversion.go

+33-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha6/conversion_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -792,5 +792,6 @@ func Test_FuzzRestorers(t *testing.T) {
792792
testhelpers.FuzzRestorer(t, "restorev1alpha6SubnetParam", restorev1alpha6SubnetParam)
793793
testhelpers.FuzzRestorer(t, "restorev1beta1SubnetParam", restorev1beta1SubnetParam)
794794
testhelpers.FuzzRestorer(t, "restorev1alpha6Port", restorev1alpha6Port)
795+
testhelpers.FuzzRestorer(t, "restorev1beta1BlockDeviceVolume", restorev1beta1BlockDeviceVolume)
795796
testhelpers.FuzzRestorer(t, "restorev1alpha6SecurityGroup", restorev1alpha6SecurityGroup)
796797
}

api/v1alpha6/openstackmachine_conversion.go

+16
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ func restorev1beta1MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infr
196196
restorev1beta1SecurityGroupParam(&previous.SecurityGroups[i], &dst.SecurityGroups[i])
197197
}
198198
}
199+
200+
if dst.RootVolume != nil && previous.RootVolume != nil {
201+
restorev1beta1BlockDeviceVolume(
202+
&previous.RootVolume.BlockDeviceVolume,
203+
&dst.RootVolume.BlockDeviceVolume,
204+
)
205+
}
206+
207+
if len(dst.AdditionalBlockDevices) == len(previous.AdditionalBlockDevices) {
208+
for i := range dst.AdditionalBlockDevices {
209+
restorev1beta1BlockDeviceVolume(
210+
previous.AdditionalBlockDevices[i].Storage.Volume,
211+
dst.AdditionalBlockDevices[i].Storage.Volume,
212+
)
213+
}
214+
}
199215
}
200216

201217
func convertNetworksToPorts(networks []NetworkParam, s apiconversion.Scope) ([]infrav1.PortOpts, error) {

api/v1alpha6/types_conversion.go

+28
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"k8s.io/utils/pointer"
2525

2626
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
27+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/conversioncommon"
2728
optional "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2829
)
2930

@@ -426,6 +427,33 @@ func Convert_v1beta1_BindingProfile_To_Map_string_To_Interface(in *infrav1.Bindi
426427
/* AddressPair */
427428
/* Instance */
428429
/* RootVolume */
430+
431+
func restorev1beta1BlockDeviceVolume(previous *infrav1.BlockDeviceVolume, dst *infrav1.BlockDeviceVolume) {
432+
if previous == nil || dst == nil {
433+
return
434+
}
435+
436+
dstAZ := dst.AvailabilityZone
437+
previousAZ := previous.AvailabilityZone
438+
439+
// Empty From (the default) will be converted to the explicit "Name"
440+
if dstAZ != nil && previousAZ != nil && dstAZ.From == "Name" {
441+
dstAZ.From = previousAZ.From
442+
}
443+
}
444+
445+
func Convert_v1alpha6_RootVolume_To_v1beta1_RootVolume(in *RootVolume, out *infrav1.RootVolume, s apiconversion.Scope) error {
446+
out.SizeGiB = in.Size
447+
out.Type = in.VolumeType
448+
return conversioncommon.Convert_string_To_Pointer_v1beta1_VolumeAvailabilityZone(&in.AvailabilityZone, &out.AvailabilityZone, s)
449+
}
450+
451+
func Convert_v1beta1_RootVolume_To_v1alpha6_RootVolume(in *infrav1.RootVolume, out *RootVolume, s apiconversion.Scope) error {
452+
out.Size = in.SizeGiB
453+
out.VolumeType = in.Type
454+
return conversioncommon.Convert_Pointer_v1beta1_VolumeAvailabilityZone_To_string(&in.AvailabilityZone, &out.AvailabilityZone, s)
455+
}
456+
429457
/* Network */
430458

431459
func Convert_v1alpha6_Network_To_v1beta1_NetworkStatusWithSubnets(in *Network, out *infrav1.NetworkStatusWithSubnets, s apiconversion.Scope) error {

api/v1alpha6/zz_generated.conversion.go

+33-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha7/conversion_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,5 @@ func Test_FuzzRestorers(t *testing.T) {
405405
testhelpers.FuzzRestorer(t, "restorev1beta1RouterParam", restorev1beta1RouterParam)
406406
testhelpers.FuzzRestorer(t, "restorev1alpha7Port", restorev1alpha7Port)
407407
testhelpers.FuzzRestorer(t, "restorev1beta1Port", restorev1beta1Port)
408+
testhelpers.FuzzRestorer(t, "restorev1beta1BlockDeviceVolume", restorev1beta1BlockDeviceVolume)
408409
}

api/v1alpha7/openstackmachine_conversion.go

+16
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ func restorev1beta1MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infr
191191
}
192192
}
193193
dst.FloatingIPPoolRef = previous.FloatingIPPoolRef
194+
195+
if dst.RootVolume != nil && previous.RootVolume != nil {
196+
restorev1beta1BlockDeviceVolume(
197+
&previous.RootVolume.BlockDeviceVolume,
198+
&dst.RootVolume.BlockDeviceVolume,
199+
)
200+
}
201+
202+
if len(dst.AdditionalBlockDevices) == len(previous.AdditionalBlockDevices) {
203+
for i := range dst.AdditionalBlockDevices {
204+
restorev1beta1BlockDeviceVolume(
205+
previous.AdditionalBlockDevices[i].Storage.Volume,
206+
dst.AdditionalBlockDevices[i].Storage.Volume,
207+
)
208+
}
209+
}
194210
}
195211

196212
func Convert_v1alpha7_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *OpenStackMachineSpec, out *infrav1.OpenStackMachineSpec, s apiconversion.Scope) error {

0 commit comments

Comments
 (0)