From c543865eca522c72c275073a86b158464c4d124f Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Wed, 17 Jan 2024 11:30:45 +0000 Subject: [PATCH] Dual-stack: Fix conversion restore with multiple subnets --- api/v1alpha6/conversion.go | 18 ++++++++++++++++++ api/v1alpha7/conversion.go | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/api/v1alpha6/conversion.go b/api/v1alpha6/conversion.go index dfee3a6290..c2170b980b 100644 --- a/api/v1alpha6/conversion.go +++ b/api/v1alpha6/conversion.go @@ -75,6 +75,12 @@ func restorev1alpha8Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) { } } +func restorev1alpha8Subnets(previous *[]infrav1.SubnetFilter, dst *[]infrav1.SubnetFilter) { + if len(*previous) > 1 { + *dst = append(*dst, (*previous)[1:]...) + } +} + func restorev1alpha8ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *infrav1.OpenStackClusterStatus) { // It's (theoretically) possible in v1alpha8 to have Network nil but // Router or APIServerLoadBalancer not nil. In hub-spoke-hub conversion this will @@ -154,6 +160,12 @@ var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStack }, restorev1alpha8Bastion, ), + "subnets": conversion.HashedFieldRestorer( + func(c *infrav1.OpenStackCluster) *[]infrav1.SubnetFilter { + return &c.Spec.Subnets + }, + restorev1alpha8Subnets, + ), "status": conversion.HashedFieldRestorer( func(c *infrav1.OpenStackCluster) *infrav1.OpenStackClusterStatus { return &c.Status @@ -234,6 +246,12 @@ var v1alpha8OpenStackClusterTemplateRestorer = conversion.RestorerFor[*infrav1.O }, restorev1alpha8Bastion, ), + "subnets": conversion.HashedFieldRestorer( + func(c *infrav1.OpenStackClusterTemplate) *[]infrav1.SubnetFilter { + return &c.Spec.Template.Spec.Subnets + }, + restorev1alpha8Subnets, + ), } func (r *OpenStackClusterTemplate) ConvertTo(dstRaw ctrlconversion.Hub) error { diff --git a/api/v1alpha7/conversion.go b/api/v1alpha7/conversion.go index fe58245113..e51c698e29 100644 --- a/api/v1alpha7/conversion.go +++ b/api/v1alpha7/conversion.go @@ -97,6 +97,10 @@ func restorev1alpha8ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *inf dst.ExternalNetwork.NotTagsAny = previous.ExternalNetwork.NotTagsAny dst.DisableExternalNetwork = previous.DisableExternalNetwork + + if len(previous.Subnets) > 1 { + dst.Subnets = append(dst.Subnets, previous.Subnets[1:]...) + } } func (r *OpenStackCluster) ConvertTo(dstRaw ctrlconversion.Hub) error {