Skip to content

Commit

Permalink
Dual-stack: Fix conversion restore with multiple subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbooth committed Jan 17, 2024
1 parent e98b7f5 commit c543865
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/v1alpha6/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha7/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c543865

Please sign in to comment.