Skip to content

Commit

Permalink
Replace SubnetParam with SubnetFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbooth committed May 17, 2023
1 parent f0da60b commit 06f81e5
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 179 deletions.
15 changes: 15 additions & 0 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,18 @@ func Convert_v1alpha5_Network_To_v1alpha7_Network(in *Network, out *infrav1.Netw
// PortOpts has been removed in v1alpha7
return autoConvert_v1alpha5_Network_To_v1alpha7_Network(in, out, s)
}

func Convert_v1alpha5_SubnetParam_To_v1alpha7_SubnetFilter(in *SubnetParam, out *infrav1.SubnetFilter, _ conversion.Scope) error {
*out = infrav1.SubnetFilter(in.Filter)
if in.UUID != "" {
out.ID = in.UUID
}
return nil
}

func Convert_v1alpha7_SubnetFilter_To_v1alpha5_SubnetParam(in *infrav1.SubnetFilter, out *SubnetParam, _ conversion.Scope) error {
out.Filter = SubnetFilter(*in)
out.UUID = in.ID

return nil
}
74 changes: 34 additions & 40 deletions api/v1alpha5/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions api/v1alpha6/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ func restorev1alpha7ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *inf
}
}

func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackClusterSpec) {
for i := range previous.ExternalRouterIPs {
dstIP := &dst.ExternalRouterIPs[i]
previousIP := &previous.ExternalRouterIPs[i]

// Subnet.Filter.ID was overwritten in up-conversion by Subnet.UUID
dstIP.Subnet.Filter.ID = previousIP.Subnet.Filter.ID

// If Subnet.UUID was previously unset, we overwrote it with the value of Subnet.Filter.ID
// Don't unset it again if it doesn't have the previous value of Subnet.Filter.ID, because that means it was genuinely changed
if previousIP.Subnet.UUID == "" && dstIP.Subnet.UUID == previousIP.Subnet.Filter.ID {
dstIP.Subnet.UUID = ""
}
}
}

var _ ctrlconversion.Convertible = &OpenStackCluster{}

func (r *OpenStackCluster) ConvertTo(dstRaw ctrlconversion.Hub) error {
Expand Down Expand Up @@ -155,6 +171,7 @@ func (r *OpenStackCluster) ConvertFrom(srcRaw ctrlconversion.Hub) error {
if prevBastion != nil {
restorev1alpha6MachineSpec(&prevBastion.Instance, &r.Spec.Bastion.Instance)
}
restorev1alpha6ClusterSpec(&previous.Spec, &r.Spec)
restorev1alpha6ClusterStatus(&previous.Status, &r.Status)
}

Expand Down Expand Up @@ -205,6 +222,7 @@ func (r *OpenStackClusterTemplate) ConvertFrom(srcRaw ctrlconversion.Hub) error
if prevBastion != nil {
restorev1alpha6MachineSpec(&prevBastion.Instance, &r.Spec.Template.Spec.Bastion.Instance)
}
restorev1alpha6ClusterSpec(&previous.Spec.Template.Spec, &r.Spec.Template.Spec)
}

return nil
Expand Down Expand Up @@ -436,3 +454,18 @@ func Convert_v1alpha6_Network_To_v1alpha7_Network(in *Network, out *infrav1.Netw
// PortOpts has been removed in v1alpha7
return autoConvert_v1alpha6_Network_To_v1alpha7_Network(in, out, s)
}

func Convert_v1alpha6_SubnetParam_To_v1alpha7_SubnetFilter(in *SubnetParam, out *infrav1.SubnetFilter, _ conversion.Scope) error {
*out = infrav1.SubnetFilter(in.Filter)
if in.UUID != "" {
out.ID = in.UUID
}
return nil
}

func Convert_v1alpha7_SubnetFilter_To_v1alpha6_SubnetParam(in *infrav1.SubnetFilter, out *SubnetParam, _ conversion.Scope) error {
out.Filter = SubnetFilter(*in)
out.UUID = in.ID

return nil
}
74 changes: 34 additions & 40 deletions api/v1alpha6/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions api/v1alpha7/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ExternalRouterIPParam struct {
// The FixedIP in the corresponding subnet
FixedIP string `json:"fixedIP,omitempty"`
// The subnet in which the FixedIP is used for the Gateway of this router
Subnet SubnetParam `json:"subnet"`
Subnet SubnetFilter `json:"subnet"`
}

type SecurityGroupParam struct {
Expand Down Expand Up @@ -65,16 +65,6 @@ type NetworkFilter struct {
NotTagsAny string `json:"notTagsAny,omitempty"`
}

type SubnetParam struct {
// Optional UUID of the subnet.
// If specified this will not be validated prior to server creation.
// If specified, the enclosing `NetworkParam` must also be specified by UUID.
UUID string `json:"uuid,omitempty"`

// Filters for optional subnet query
Filter SubnetFilter `json:"filter,omitempty"`
}

type SubnetFilter struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Expand Down
16 changes: 0 additions & 16 deletions api/v1alpha7/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 06f81e5

Please sign in to comment.