Skip to content

Commit

Permalink
SubnetFilter to SubnetParam
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbooth committed Mar 27, 2024
1 parent de67a45 commit c4d985b
Show file tree
Hide file tree
Showing 27 changed files with 1,256 additions and 738 deletions.
55 changes: 43 additions & 12 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha5_OpenStackClusterSpec(in *i

if in.Subnets != nil {
if len(in.Subnets) >= 1 {
if err := Convert_v1beta1_SubnetFilter_To_v1alpha5_SubnetFilter(&in.Subnets[0], &out.Subnet, s); err != nil {
if err := Convert_v1beta1_SubnetParam_To_v1alpha5_SubnetFilter(&in.Subnets[0], &out.Subnet, s); err != nil {
return err
}
}
Expand Down Expand Up @@ -254,11 +254,11 @@ func Convert_v1alpha5_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O

emptySubnet := SubnetFilter{}
if in.Subnet != emptySubnet {
subnet := infrav1.SubnetFilter{}
if err := Convert_v1alpha5_SubnetFilter_To_v1beta1_SubnetFilter(&in.Subnet, &subnet, s); err != nil {
subnet := infrav1.SubnetParam{}
if err := Convert_v1alpha5_SubnetFilter_To_v1beta1_SubnetParam(&in.Subnet, &subnet, s); err != nil {
return err
}
out.Subnets = []infrav1.SubnetFilter{subnet}
out.Subnets = []infrav1.SubnetParam{subnet}
}

if len(in.NodeCIDR) > 0 {
Expand Down Expand Up @@ -547,25 +547,56 @@ func Convert_v1beta1_SecurityGroupFilter_To_v1alpha5_SecurityGroupParam(in *infr
return nil
}

func Convert_v1alpha5_SubnetParam_To_v1beta1_SubnetFilter(in *SubnetParam, out *infrav1.SubnetFilter, s conversion.Scope) error {
if err := Convert_v1alpha5_SubnetFilter_To_v1beta1_SubnetFilter(&in.Filter, out, s); err != nil {
func Convert_v1alpha5_SubnetParam_To_v1beta1_SubnetParam(in *SubnetParam, out *infrav1.SubnetParam, s conversion.Scope) error {
if in.UUID != "" {
out.ID = &in.UUID
return nil
}
outFilter := &infrav1.SubnetFilter{}
if err := Convert_v1alpha5_SubnetFilter_To_v1beta1_SubnetFilter(&in.Filter, outFilter, s); err != nil {
return err
}
if in.UUID != "" {
out.ID = in.UUID
if !outFilter.IsZero() {
out.Filter = outFilter
}
return nil
}

func Convert_v1beta1_SubnetFilter_To_v1alpha5_SubnetParam(in *infrav1.SubnetFilter, out *SubnetParam, s conversion.Scope) error {
if err := Convert_v1beta1_SubnetFilter_To_v1alpha5_SubnetFilter(in, &out.Filter, s); err != nil {
return err
func Convert_v1beta1_SubnetParam_To_v1alpha5_SubnetParam(in *infrav1.SubnetParam, out *SubnetParam, s conversion.Scope) error {
if in.ID != nil {
out.UUID = *in.ID
return nil
}

if in.Filter != nil {
if err := Convert_v1beta1_SubnetFilter_To_v1alpha5_SubnetFilter(in.Filter, &out.Filter, s); err != nil {
return err
}
}
out.UUID = in.ID

return nil
}

func Convert_v1alpha5_SubnetFilter_To_v1beta1_SubnetParam(in *SubnetFilter, out *infrav1.SubnetParam, s conversion.Scope) error {
if in.ID != "" {
out.ID = &in.ID
return nil
}
out.Filter = &infrav1.SubnetFilter{}
return Convert_v1alpha5_SubnetFilter_To_v1beta1_SubnetFilter(in, out.Filter, s)
}

func Convert_v1beta1_SubnetParam_To_v1alpha5_SubnetFilter(in *infrav1.SubnetParam, out *SubnetFilter, s conversion.Scope) error {
if in.ID != nil {
out.ID = *in.ID
return nil
}
if in.Filter != nil {
return Convert_v1beta1_SubnetFilter_To_v1alpha5_SubnetFilter(in.Filter, out, s)
}
return nil
}

func Convert_Map_string_To_Interface_To_v1beta1_BindingProfile(in map[string]string, out *infrav1.BindingProfile, _ conversion.Scope) error {
for k, v := range in {
if k == "capabilities" {
Expand Down
43 changes: 32 additions & 11 deletions api/v1alpha5/zz_generated.conversion.go

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

89 changes: 56 additions & 33 deletions api/v1alpha6/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestFuzzyConversion(t *testing.T) {
// length 1, but we need to also test length 2.
// Ensure it is occasionally generated.
if len(spec.Subnets) == 1 && c.RandBool() {
subnet := infrav1.SubnetFilter{}
subnet := infrav1.SubnetParam{}
c.FuzzNoCustom(&subnet)
spec.Subnets = append(spec.Subnets, subnet)
}
Expand Down Expand Up @@ -230,6 +230,25 @@ func TestFuzzyConversion(t *testing.T) {
param.ID = nil
}
},

// v1beta1 subnet param contains exactly one of ID or filter
func(param *infrav1.SubnetParam, c fuzz.Continue) {
if c.RandBool() {
id := func() string {
for {
s := c.RandString()
if len(s) > 0 {
return s
}
}
}()
param.ID = &id
} else {
filter := &infrav1.SubnetFilter{}
c.Fuzz(filter)
param.Filter = filter
}
},
}
}

Expand Down Expand Up @@ -393,8 +412,8 @@ func TestNetworksToPorts(t *testing.T) {
},
FixedIPs: []infrav1.FixedIP{
{
Subnet: &infrav1.SubnetFilter{
ID: subnetuuid,
Subnet: &infrav1.SubnetParam{
ID: pointer.String(subnetuuid),
},
},
},
Expand Down Expand Up @@ -437,20 +456,22 @@ func TestNetworksToPorts(t *testing.T) {
},
FixedIPs: []infrav1.FixedIP{
{
Subnet: &infrav1.SubnetFilter{
Name: "subnet-name",
Description: "subnet-description",
ProjectID: "project-id",
IPVersion: 6,
GatewayIP: "x.x.x.x",
CIDR: "y.y.y.y",
IPv6AddressMode: "address-mode",
IPv6RAMode: "ra-mode",
FilterByNeutronTags: infrav1.FilterByNeutronTags{
Tags: []infrav1.NeutronTag{"tags"},
TagsAny: []infrav1.NeutronTag{"tags-any"},
NotTags: []infrav1.NeutronTag{"not-tags"},
NotTagsAny: []infrav1.NeutronTag{"not-tags-any"},
Subnet: &infrav1.SubnetParam{
Filter: &infrav1.SubnetFilter{
Name: "subnet-name",
Description: "subnet-description",
ProjectID: "project-id",
IPVersion: 6,
GatewayIP: "x.x.x.x",
CIDR: "y.y.y.y",
IPv6AddressMode: "address-mode",
IPv6RAMode: "ra-mode",
FilterByNeutronTags: infrav1.FilterByNeutronTags{
Tags: []infrav1.NeutronTag{"tags"},
TagsAny: []infrav1.NeutronTag{"tags-any"},
NotTags: []infrav1.NeutronTag{"not-tags"},
NotTagsAny: []infrav1.NeutronTag{"not-tags-any"},
},
},
},
},
Expand Down Expand Up @@ -497,8 +518,8 @@ func TestNetworksToPorts(t *testing.T) {
},
FixedIPs: []infrav1.FixedIP{
{
Subnet: &infrav1.SubnetFilter{
ID: subnetuuid,
Subnet: &infrav1.SubnetParam{
ID: pointer.String(subnetuuid),
},
},
},
Expand All @@ -509,20 +530,22 @@ func TestNetworksToPorts(t *testing.T) {
},
FixedIPs: []infrav1.FixedIP{
{
Subnet: &infrav1.SubnetFilter{
Name: "subnet-name",
Description: "subnet-description",
ProjectID: "project-id",
IPVersion: 6,
GatewayIP: "x.x.x.x",
CIDR: "y.y.y.y",
IPv6AddressMode: "address-mode",
IPv6RAMode: "ra-mode",
FilterByNeutronTags: infrav1.FilterByNeutronTags{
Tags: []infrav1.NeutronTag{"tags"},
TagsAny: []infrav1.NeutronTag{"tags-any"},
NotTags: []infrav1.NeutronTag{"not-tags"},
NotTagsAny: []infrav1.NeutronTag{"not-tags-any"},
Subnet: &infrav1.SubnetParam{
Filter: &infrav1.SubnetFilter{
Name: "subnet-name",
Description: "subnet-description",
ProjectID: "project-id",
IPVersion: 6,
GatewayIP: "x.x.x.x",
CIDR: "y.y.y.y",
IPv6AddressMode: "address-mode",
IPv6RAMode: "ra-mode",
FilterByNeutronTags: infrav1.FilterByNeutronTags{
Tags: []infrav1.NeutronTag{"tags"},
TagsAny: []infrav1.NeutronTag{"tags-any"},
NotTags: []infrav1.NeutronTag{"not-tags"},
NotTagsAny: []infrav1.NeutronTag{"not-tags-any"},
},
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions api/v1alpha6/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackCl

if len(dst.ExternalRouterIPs) == len(previous.ExternalRouterIPs) {
for i := range dst.ExternalRouterIPs {
restorev1alpha6SubnetFilter(&previous.ExternalRouterIPs[i].Subnet.Filter, &dst.ExternalRouterIPs[i].Subnet.Filter)
restorev1alpha6SubnetParam(&previous.ExternalRouterIPs[i].Subnet, &dst.ExternalRouterIPs[i].Subnet)
}
}

Expand Down Expand Up @@ -232,11 +232,11 @@ func Convert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O

emptySubnet := SubnetFilter{}
if in.Subnet != emptySubnet {
subnet := infrav1.SubnetFilter{}
if err := Convert_v1alpha6_SubnetFilter_To_v1beta1_SubnetFilter(&in.Subnet, &subnet, s); err != nil {
subnet := infrav1.SubnetParam{}
if err := Convert_v1alpha6_SubnetFilter_To_v1beta1_SubnetParam(&in.Subnet, &subnet, s); err != nil {
return err
}
out.Subnets = []infrav1.SubnetFilter{subnet}
out.Subnets = []infrav1.SubnetParam{subnet}
}

// DNSNameservers without NodeCIDR doesn't make sense, so we drop that.
Expand Down Expand Up @@ -295,7 +295,7 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in *i
}

if len(in.Subnets) >= 1 {
if err := Convert_v1beta1_SubnetFilter_To_v1alpha6_SubnetFilter(&in.Subnets[0], &out.Subnet, s); err != nil {
if err := Convert_v1beta1_SubnetParam_To_v1alpha6_SubnetFilter(&in.Subnets[0], &out.Subnet, s); err != nil {
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha6/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,18 @@ func convertNetworksToPorts(networks []NetworkParam, s apiconversion.Scope) ([]i
ports = append(ports, infrav1.PortOpts{
Network: networkFilter,
FixedIPs: []infrav1.FixedIP{
{Subnet: &infrav1.SubnetFilter{ID: subnet.UUID}},
{Subnet: &infrav1.SubnetParam{ID: &subnet.UUID}},
},
})
} else {
subnetFilter := &infrav1.SubnetFilter{}
if err := Convert_v1alpha6_SubnetFilter_To_v1beta1_SubnetFilter(&subnet.Filter, subnetFilter, s); err != nil {
subnetParam := &infrav1.SubnetParam{}
if err := Convert_v1alpha6_SubnetFilter_To_v1beta1_SubnetParam(&subnet.Filter, subnetParam, s); err != nil {
return nil, err
}
ports = append(ports, infrav1.PortOpts{
Network: networkFilter,
FixedIPs: []infrav1.FixedIP{
{Subnet: subnetFilter},
{Subnet: subnetParam},
},
})
}
Expand Down
Loading

0 comments on commit c4d985b

Please sign in to comment.