Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ NetworkFilter to NetworkParam #1972

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1alpha1/openstackfloatingippool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type OpenStackFloatingIPPoolSpec struct {

// FloatingIPNetwork is the external network to use for floating ips, if there's only one external network it will be used by default
// +optional
FloatingIPNetwork infrav1.NetworkFilter `json:"floatingIPNetwork"`
FloatingIPNetwork infrav1.NetworkParam `json:"floatingIPNetwork"`

// The stratergy to use for reclaiming floating ips when they are released from a machine
// +kubebuilder:validation:Optional
Expand Down
54 changes: 43 additions & 11 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha5

import (
"errors"
"strings"

conversion "k8s.io/apimachinery/pkg/conversion"
Expand Down Expand Up @@ -205,8 +206,8 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha5_OpenStackClusterSpec(in *i
return err
}

if in.ExternalNetwork != nil && in.ExternalNetwork.ID != "" {
out.ExternalNetworkID = in.ExternalNetwork.ID
if in.ExternalNetwork != nil && in.ExternalNetwork.ID != nil {
out.ExternalNetworkID = *in.ExternalNetwork.ID
}

if len(in.ManagedSubnets) > 0 {
Expand Down Expand Up @@ -246,8 +247,8 @@ func Convert_v1alpha5_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
}

if in.ExternalNetworkID != "" {
out.ExternalNetwork = &infrav1.NetworkFilter{
ID: in.ExternalNetworkID,
out.ExternalNetwork = &infrav1.NetworkParam{
ID: &in.ExternalNetworkID,
}
}

Expand Down Expand Up @@ -746,18 +747,49 @@ func Convert_v1beta1_SecurityGroupFilter_To_v1alpha5_SecurityGroupFilter(in *inf
return nil
}

func Convert_v1alpha5_NetworkFilter_To_v1beta1_NetworkFilter(in *NetworkFilter, out *infrav1.NetworkFilter, s conversion.Scope) error {
if err := autoConvert_v1alpha5_NetworkFilter_To_v1beta1_NetworkFilter(in, out, s); err != nil {
func Convert_v1alpha5_NetworkFilter_To_v1beta1_NetworkParam(in *NetworkFilter, out *infrav1.NetworkParam, s conversion.Scope) error {
if in.ID != "" {
out.ID = &in.ID
return nil
}
outFilter := &infrav1.NetworkFilter{}
if err := autoConvert_v1alpha5_NetworkFilter_To_v1beta1_NetworkFilter(in, outFilter, s); err != nil {
return err
}
infrav1.ConvertAllTagsTo(in.Tags, in.TagsAny, in.NotTags, in.NotTagsAny, &out.FilterByNeutronTags)
infrav1.ConvertAllTagsTo(in.Tags, in.TagsAny, in.NotTags, in.NotTagsAny, &outFilter.FilterByNeutronTags)
if !outFilter.IsZero() {
out.Filter = outFilter
}
return nil
}

func Convert_v1beta1_NetworkFilter_To_v1alpha5_NetworkFilter(in *infrav1.NetworkFilter, out *NetworkFilter, s conversion.Scope) error {
if err := autoConvert_v1beta1_NetworkFilter_To_v1alpha5_NetworkFilter(in, out, s); err != nil {
return err
func Convert_v1beta1_NetworkParam_To_v1alpha5_NetworkFilter(in *infrav1.NetworkParam, out *NetworkFilter, s conversion.Scope) error {
if in.ID != nil {
out.ID = *in.ID
return nil
}
if in.Filter != nil {
if err := autoConvert_v1beta1_NetworkFilter_To_v1alpha5_NetworkFilter(in.Filter, out, s); err != nil {
return err
}
infrav1.ConvertAllTagsFrom(&in.Filter.FilterByNeutronTags, &out.Tags, &out.TagsAny, &out.NotTags, &out.NotTagsAny)
}
infrav1.ConvertAllTagsFrom(&in.FilterByNeutronTags, &out.Tags, &out.TagsAny, &out.NotTags, &out.NotTagsAny)
return nil
}

// conversion-gen registers the following functions so we have to define them, but nothing should ever call them.
func Convert_v1alpha5_NetworkFilter_To_v1beta1_NetworkFilter(_ *NetworkFilter, _ *infrav1.NetworkFilter, _ conversion.Scope) error {
return errors.New("Convert_v1alpha6_NetworkFilter_To_v1beta1_NetworkFilter should not be called")
}

func Convert_v1beta1_NetworkFilter_To_v1alpha5_NetworkFilter(_ *infrav1.NetworkFilter, _ *NetworkFilter, _ conversion.Scope) error {
return errors.New("Convert_v1beta1_NetworkFilter_To_v1alpha6_NetworkFilter should not be called")
}

func Convert_v1alpha5_NetworkParam_To_v1beta1_NetworkParam(_ *NetworkParam, _ *infrav1.NetworkParam, _ conversion.Scope) error {
return errors.New("Convert_v1alpha6_NetworkParam_To_v1beta1_NetworkParam should not be called")
}

func Convert_v1beta1_NetworkParam_To_v1alpha5_NetworkParam(_ *infrav1.NetworkParam, _ *NetworkParam, _ conversion.Scope) error {
return errors.New("Convert_v1beta1_NetworkParam_To_v1alpha6_NetworkParam should not be called")
}
47 changes: 40 additions & 7 deletions api/v1alpha5/zz_generated.conversion.go

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

40 changes: 21 additions & 19 deletions api/v1alpha6/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ func TestNetworksToPorts(t *testing.T) {
afterMachineSpec: infrav1.OpenStackMachineSpec{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: networkuuid,
Network: &infrav1.NetworkParam{
ID: pointer.String(networkuuid),
},
},
},
Expand All @@ -247,15 +247,17 @@ func TestNetworksToPorts(t *testing.T) {
afterMachineSpec: infrav1.OpenStackMachineSpec{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
Name: "network-name",
Description: "network-description",
ProjectID: "project-id",
FilterByNeutronTags: infrav1.FilterByNeutronTags{
Tags: []infrav1.NeutronTag{"tags"},
TagsAny: []infrav1.NeutronTag{"tags-any"},
NotTags: []infrav1.NeutronTag{"not-tags"},
NotTagsAny: []infrav1.NeutronTag{"not-tags-any"},
Network: &infrav1.NetworkParam{
Filter: &infrav1.NetworkFilter{
Name: "network-name",
Description: "network-description",
ProjectID: "project-id",
FilterByNeutronTags: infrav1.FilterByNeutronTags{
Tags: []infrav1.NeutronTag{"tags"},
TagsAny: []infrav1.NeutronTag{"tags-any"},
NotTags: []infrav1.NeutronTag{"not-tags"},
NotTagsAny: []infrav1.NeutronTag{"not-tags-any"},
},
},
},
},
Expand All @@ -279,8 +281,8 @@ func TestNetworksToPorts(t *testing.T) {
afterMachineSpec: infrav1.OpenStackMachineSpec{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: networkuuid,
Network: &infrav1.NetworkParam{
ID: pointer.String(networkuuid),
},
FixedIPs: []infrav1.FixedIP{
{
Expand Down Expand Up @@ -323,8 +325,8 @@ func TestNetworksToPorts(t *testing.T) {
afterMachineSpec: infrav1.OpenStackMachineSpec{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: networkuuid,
Network: &infrav1.NetworkParam{
ID: pointer.String(networkuuid),
},
FixedIPs: []infrav1.FixedIP{
{
Expand Down Expand Up @@ -383,8 +385,8 @@ func TestNetworksToPorts(t *testing.T) {
afterMachineSpec: infrav1.OpenStackMachineSpec{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: networkuuid,
Network: &infrav1.NetworkParam{
ID: pointer.String(networkuuid),
},
FixedIPs: []infrav1.FixedIP{
{
Expand All @@ -395,8 +397,8 @@ func TestNetworksToPorts(t *testing.T) {
},
},
{
Network: &infrav1.NetworkFilter{
ID: networkuuid,
Network: &infrav1.NetworkParam{
ID: pointer.String(networkuuid),
},
FixedIPs: []infrav1.FixedIP{
{
Expand Down
31 changes: 11 additions & 20 deletions api/v1alpha6/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,14 @@ func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackCl
func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infrav1.OpenStackClusterSpec) {
// Bastion is restored separately

if dst.Network.IsEmpty() {
dst.Network = previous.Network
}
restorev1beta1NetworkParam(previous.Network, dst.Network)

// Restore all fields except ID, which should have been copied over in conversion
// ExternalNetwork by filter will be been lost in down-conversion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit, not worth a new push IMO, just mentioning since I happened to see it

Suggested change
// ExternalNetwork by filter will be been lost in down-conversion
// ExternalNetwork by filter will be lost in down-conversion

if previous.ExternalNetwork != nil {
if dst.ExternalNetwork == nil {
dst.ExternalNetwork = &infrav1.NetworkFilter{}
dst.ExternalNetwork = &infrav1.NetworkParam{}
}

dst.ExternalNetwork.Name = previous.ExternalNetwork.Name
dst.ExternalNetwork.Description = previous.ExternalNetwork.Description
dst.ExternalNetwork.ProjectID = previous.ExternalNetwork.ProjectID
dst.ExternalNetwork.Tags = previous.ExternalNetwork.Tags
dst.ExternalNetwork.TagsAny = previous.ExternalNetwork.TagsAny
dst.ExternalNetwork.NotTags = previous.ExternalNetwork.NotTags
dst.ExternalNetwork.NotTagsAny = previous.ExternalNetwork.NotTagsAny
dst.ExternalNetwork.Filter = previous.ExternalNetwork.Filter
}

// Restore fields not present in v1alpha6
Expand Down Expand Up @@ -227,15 +218,15 @@ func Convert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
}

if in.Network != (NetworkFilter{}) {
out.Network = &infrav1.NetworkFilter{}
if err := Convert_v1alpha6_NetworkFilter_To_v1beta1_NetworkFilter(&in.Network, out.Network, s); err != nil {
out.Network = &infrav1.NetworkParam{}
if err := Convert_v1alpha6_NetworkFilter_To_v1beta1_NetworkParam(&in.Network, out.Network, s); err != nil {
return err
}
}

if in.ExternalNetworkID != "" {
out.ExternalNetwork = &infrav1.NetworkFilter{
ID: in.ExternalNetworkID,
out.ExternalNetwork = &infrav1.NetworkParam{
ID: &in.ExternalNetworkID,
}
}

Expand Down Expand Up @@ -294,13 +285,13 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in *i
}

if in.Network != nil {
if err := Convert_v1beta1_NetworkFilter_To_v1alpha6_NetworkFilter(in.Network, &out.Network, s); err != nil {
if err := Convert_v1beta1_NetworkParam_To_v1alpha6_NetworkFilter(in.Network, &out.Network, s); err != nil {
return err
}
}

if in.ExternalNetwork != nil && in.ExternalNetwork.ID != "" {
out.ExternalNetworkID = in.ExternalNetwork.ID
if in.ExternalNetwork != nil && in.ExternalNetwork.ID != nil {
out.ExternalNetworkID = *in.ExternalNetwork.ID
}

if len(in.Subnets) >= 1 {
Expand Down
10 changes: 5 additions & 5 deletions api/v1alpha6/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func convertNetworksToPorts(networks []NetworkParam, s apiconversion.Scope) ([]i
network := networks[i]

// This will remain null if the network is not specified in NetworkParam
var networkFilter *infrav1.NetworkFilter
var networkFilter *infrav1.NetworkParam

// In v1alpha6, if network.Filter resolved to multiple networks
// then we would add multiple ports. It is not possible to
Expand All @@ -189,12 +189,12 @@ func convertNetworksToPorts(networks []NetworkParam, s apiconversion.Scope) ([]i
// create the port.
switch {
case network.UUID != "":
networkFilter = &infrav1.NetworkFilter{
ID: network.UUID,
networkFilter = &infrav1.NetworkParam{
ID: &network.UUID,
}
case network.Filter != (NetworkFilter{}):
networkFilter = &infrav1.NetworkFilter{}
if err := Convert_v1alpha6_NetworkFilter_To_v1beta1_NetworkFilter(&network.Filter, networkFilter, s); err != nil {
networkFilter = &infrav1.NetworkParam{}
if err := Convert_v1alpha6_NetworkFilter_To_v1beta1_NetworkParam(&network.Filter, networkFilter, s); err != nil {
return nil, err
}
}
Expand Down
Loading