Skip to content

Commit

Permalink
Merge pull request #1971 from shiftstack/subnetparam
Browse files Browse the repository at this point in the history
⚠️ SubnetFilter to SubnetParam
  • Loading branch information
k8s-ci-robot authored Mar 28, 2024
2 parents 1d5d2d5 + 4d85f6f commit de29a18
Show file tree
Hide file tree
Showing 27 changed files with 1,231 additions and 742 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.

68 changes: 36 additions & 32 deletions api/v1alpha6/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,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 @@ -330,20 +330,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 @@ -390,8 +392,8 @@ func TestNetworksToPorts(t *testing.T) {
},
FixedIPs: []infrav1.FixedIP{
{
Subnet: &infrav1.SubnetFilter{
ID: subnetuuid,
Subnet: &infrav1.SubnetParam{
ID: pointer.String(subnetuuid),
},
},
},
Expand All @@ -402,20 +404,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
19 changes: 14 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 All @@ -179,10 +179,19 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
dst.NetworkMTU = previous.NetworkMTU
dst.DisableExternalNetwork = previous.DisableExternalNetwork

if len(previous.Subnets) > 0 && len(dst.Subnets) > 0 {
restorev1beta1SubnetParam(&previous.Subnets[0], &dst.Subnets[0])
}
if len(previous.Subnets) > 1 {
dst.Subnets = append(dst.Subnets, previous.Subnets[1:]...)
}

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

dst.ManagedSubnets = previous.ManagedSubnets

if previous.ManagedSecurityGroups != nil {
Expand Down Expand Up @@ -232,11 +241,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 +304,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 de29a18

Please sign in to comment.