Skip to content

Commit

Permalink
RouterFilter to RouterParam
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbooth committed Mar 27, 2024
1 parent e0f407f commit 037f10d
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 188 deletions.
16 changes: 16 additions & 0 deletions api/v1alpha6/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ func TestFuzzyConversion(t *testing.T) {
param.ID = nil
}
},

// v1beta1 router param contains exactly one of ID or filter
func(param *infrav1.RouterParam, c fuzz.Continue) {
if c.RandBool() {
id := nonEmptyString(c)
param.ID = &id
param.Filter = nil
} else {
filter := infrav1.RouterFilter{}
for filter.IsZero() {
c.FuzzNoCustom(&filter)
}
param.Filter = &filter
param.ID = nil
}
},
}
}

Expand Down
16 changes: 16 additions & 0 deletions api/v1alpha7/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ func TestFuzzyConversion(t *testing.T) {
param.ID = nil
}
},

// v1beta1 router param contains exactly one of ID or filter
func(param *infrav1.RouterParam, c fuzz.Continue) {
if c.RandBool() {
id := nonEmptyString(c)
param.ID = &id
param.Filter = nil
} else {
filter := infrav1.RouterFilter{}
for filter.IsZero() {
c.FuzzNoCustom(&filter)
}
param.Filter = &filter
param.ID = nil
}
},
}
}

Expand Down
1 change: 1 addition & 0 deletions api/v1alpha7/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr

dst.DisableExternalNetwork = previous.DisableExternalNetwork

restorev1beta1RouterParam(previous.Router, dst.Router)
restorev1beta1NetworkParam(previous.Network, dst.Network)

if len(previous.Subnets) > 0 && len(dst.Subnets) > 0 {
Expand Down
56 changes: 49 additions & 7 deletions api/v1alpha7/types_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,55 @@ func restorev1alpha7RouterFilter(previous *RouterFilter, dst *RouterFilter) {
dst.TagsAny = previous.TagsAny
dst.NotTags = previous.NotTags
dst.NotTagsAny = previous.NotTagsAny

// If ID was set we lost all other filter params
if dst.ID != "" {
dst.Name = previous.Name
dst.Description = previous.Description
dst.ProjectID = previous.ProjectID
}
}

func restorev1beta1RouterParam(previous *infrav1.RouterParam, dst *infrav1.RouterParam) {
if previous == nil || dst == nil {
return
}

optional.RestoreString(&previous.ID, &dst.ID)
if dst.Filter != nil {
dst.Filter.FilterByNeutronTags = previous.Filter.FilterByNeutronTags
}
}

func Convert_v1alpha7_RouterFilter_To_v1beta1_RouterFilter(in *RouterFilter, out *infrav1.RouterFilter, s apiconversion.Scope) error {
if err := autoConvert_v1alpha7_RouterFilter_To_v1beta1_RouterFilter(in, out, s); err != nil {
func Convert_v1alpha7_RouterFilter_To_v1beta1_RouterParam(in *RouterFilter, out *infrav1.RouterParam, s apiconversion.Scope) error {
if in.ID != "" {
out.ID = &in.ID
return nil
}

filter := &infrav1.RouterFilter{}
if err := autoConvert_v1alpha7_RouterFilter_To_v1beta1_RouterFilter(in, filter, 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, &filter.FilterByNeutronTags)
if !filter.IsZero() {
out.Filter = filter
}
return nil
}

func Convert_v1beta1_RouterFilter_To_v1alpha7_RouterFilter(in *infrav1.RouterFilter, out *RouterFilter, s apiconversion.Scope) error {
if err := autoConvert_v1beta1_RouterFilter_To_v1alpha7_RouterFilter(in, out, s); err != nil {
return err
func Convert_v1beta1_RouterParam_To_v1alpha7_RouterFilter(in *infrav1.RouterParam, out *RouterFilter, s apiconversion.Scope) error {
if in.ID != nil {
out.ID = *in.ID
return nil
}

if in.Filter != nil {
if err := autoConvert_v1beta1_RouterFilter_To_v1alpha7_RouterFilter(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
}

Expand Down Expand Up @@ -504,3 +538,11 @@ func Convert_v1alpha7_SecurityGroupFilter_To_v1beta1_SecurityGroupFilter(_ *Secu
func Convert_v1beta1_SecurityGroupFilter_To_v1alpha7_SecurityGroupFilter(_ *infrav1.SecurityGroupFilter, _ *SecurityGroupFilter, _ apiconversion.Scope) error {
return errors.New("Convert_v1beta1_SecurityGroupFilter_To_v1alpha7_SecurityGroupFilter should not be called")
}

func Convert_v1alpha7_RouterFilter_To_v1beta1_RouterFilter(_ *RouterFilter, _ *infrav1.RouterFilter, _ apiconversion.Scope) error {
return errors.New("Convert_v1alpha7_RouterFilter_To_v1beta1_RouterFilter should not be called")
}

func Convert_v1beta1_RouterFilter_To_v1alpha7_RouterFilter(_ *infrav1.RouterFilter, _ *RouterFilter, _ apiconversion.Scope) error {
return errors.New("Convert_v1beta1_RouterFilter_To_v1alpha7_RouterFilter should not be called")
}
19 changes: 14 additions & 5 deletions api/v1alpha7/zz_generated.conversion.go

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

2 changes: 1 addition & 1 deletion api/v1beta1/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type OpenStackClusterSpec struct {
// Router specifies an existing router to be used if ManagedSubnets are
// specified. If specified, no new router will be created.
// +optional
Router *RouterFilter `json:"router,omitempty"`
Router *RouterParam `json:"router,omitempty"`

// Network specifies an existing network to use if no ManagedSubnets
// are specified.
Expand Down
26 changes: 25 additions & 1 deletion api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,39 @@ func (subnetFilter *SubnetFilter) IsZero() bool {
subnetFilter.FilterByNeutronTags.IsZero()
}

// RouterParam specifies an OpenStack router to use. It may be specified by either ID or filter, but not both.
// +kubebuilder:validation:MaxProperties:=1
// +kubebuilder:validation:MinProperties:=1
type RouterParam struct {
// ID is the ID of the router to use. If ID is provided, the other filters cannot be provided. Must be in UUID format.
// +kubebuilder:validation:Format:=uuid
// +optional
ID optional.String `json:"id,omitempty"`

// Filter specifies a filter to select an OpenStack router. If provided, cannot be empty.
Filter *RouterFilter `json:"filter,omitempty"`
}

// RouterFilter specifies a query to select an OpenStack router. At least one property must be set.
// +kubebuilder:validation:MinProperties:=1
type RouterFilter struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
ProjectID string `json:"projectID,omitempty"`

FilterByNeutronTags `json:",inline"`
}

func (f *RouterFilter) IsZero() bool {
if f == nil {
return true
}
return f.Name == "" &&
f.Description == "" &&
f.ProjectID == "" &&
f.FilterByNeutronTags.IsZero()
}

type SubnetSpec struct {
// CIDR is representing the IP address range used to create the subnet, e.g. 10.0.0.0/24.
// This field is required when defining a subnet.
Expand Down
27 changes: 26 additions & 1 deletion api/v1beta1/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 037f10d

Please sign in to comment.