diff --git a/api/v1alpha5/conversion.go b/api/v1alpha5/conversion.go index b9439a54eb..79b282dfeb 100644 --- a/api/v1alpha5/conversion.go +++ b/api/v1alpha5/conversion.go @@ -351,9 +351,7 @@ func Convert_v1alpha5_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *O } if in.ServerGroupID != "" { - out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID} - } else { - out.ServerGroup = &infrav1.ServerGroupFilter{} + out.ServerGroup = &infrav1.ServerGroupParam{ID: &in.ServerGroupID} } imageParam := infrav1.ImageParam{} @@ -682,8 +680,8 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *i return err } - if in.ServerGroup != nil { - out.ServerGroupID = in.ServerGroup.ID + if in.ServerGroup != nil && in.ServerGroup.ID != nil { + out.ServerGroupID = *in.ServerGroup.ID } if in.Image.ID != nil { diff --git a/api/v1alpha6/openstackcluster_conversion.go b/api/v1alpha6/openstackcluster_conversion.go index 0cc60afb18..912ccd16eb 100644 --- a/api/v1alpha6/openstackcluster_conversion.go +++ b/api/v1alpha6/openstackcluster_conversion.go @@ -434,7 +434,7 @@ func Convert_v1alpha6_Bastion_To_v1beta1_Bastion(in *Bastion, out *infrav1.Basti } if in.Instance.ServerGroupID != "" { - out.Spec.ServerGroup = &infrav1.ServerGroupFilter{ID: in.Instance.ServerGroupID} + out.Spec.ServerGroup = &infrav1.ServerGroupParam{ID: &in.Instance.ServerGroupID} } else { out.Spec.ServerGroup = nil } @@ -464,8 +464,8 @@ func Convert_v1beta1_Bastion_To_v1alpha6_Bastion(in *infrav1.Bastion, out *Basti return err } - if in.Spec.ServerGroup != nil && in.Spec.ServerGroup.ID != "" { - out.Instance.ServerGroupID = in.Spec.ServerGroup.ID + if in.Spec.ServerGroup != nil && in.Spec.ServerGroup.ID != nil { + out.Instance.ServerGroupID = *in.Spec.ServerGroup.ID } } diff --git a/api/v1alpha6/openstackmachine_conversion.go b/api/v1alpha6/openstackmachine_conversion.go index 2b5864d818..709a8dc1d0 100644 --- a/api/v1alpha6/openstackmachine_conversion.go +++ b/api/v1alpha6/openstackmachine_conversion.go @@ -267,7 +267,7 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *O } if in.ServerGroupID != "" { - out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID} + out.ServerGroup = &infrav1.ServerGroupParam{ID: &in.ServerGroupID} } else { out.ServerGroup = nil } @@ -316,8 +316,8 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *i return err } - if in.ServerGroup != nil { - out.ServerGroupID = in.ServerGroup.ID + if in.ServerGroup != nil && in.ServerGroup.ID != nil { + out.ServerGroupID = *in.ServerGroup.ID } if in.Image.ID != nil { diff --git a/api/v1alpha7/openstackcluster_conversion.go b/api/v1alpha7/openstackcluster_conversion.go index df703c5eb7..6d976806dc 100644 --- a/api/v1alpha7/openstackcluster_conversion.go +++ b/api/v1alpha7/openstackcluster_conversion.go @@ -403,7 +403,7 @@ func Convert_v1alpha7_Bastion_To_v1beta1_Bastion(in *Bastion, out *infrav1.Basti } if in.Instance.ServerGroupID != "" { - out.Spec.ServerGroup = &infrav1.ServerGroupFilter{ID: in.Instance.ServerGroupID} + out.Spec.ServerGroup = &infrav1.ServerGroupParam{ID: &in.Instance.ServerGroupID} } else { out.Spec.ServerGroup = nil } @@ -433,8 +433,8 @@ func Convert_v1beta1_Bastion_To_v1alpha7_Bastion(in *infrav1.Bastion, out *Basti return err } - if in.Spec.ServerGroup != nil && in.Spec.ServerGroup.ID != "" { - out.Instance.ServerGroupID = in.Spec.ServerGroup.ID + if in.Spec.ServerGroup != nil && in.Spec.ServerGroup.ID != nil { + out.Instance.ServerGroupID = *in.Spec.ServerGroup.ID } } diff --git a/api/v1alpha7/openstackmachine_conversion.go b/api/v1alpha7/openstackmachine_conversion.go index 6547fa10e1..ccca67a04c 100644 --- a/api/v1alpha7/openstackmachine_conversion.go +++ b/api/v1alpha7/openstackmachine_conversion.go @@ -178,7 +178,7 @@ func Convert_v1alpha7_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *O } if in.ServerGroupID != "" { - out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID} + out.ServerGroup = &infrav1.ServerGroupParam{ID: &in.ServerGroupID} } else { out.ServerGroup = nil } @@ -224,8 +224,8 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *i return err } - if in.ServerGroup != nil { - out.ServerGroupID = in.ServerGroup.ID + if in.ServerGroup != nil && in.ServerGroup.ID != nil { + out.ServerGroupID = *in.ServerGroup.ID } if in.Image.ID != nil { diff --git a/api/v1beta1/openstackmachine_types.go b/api/v1beta1/openstackmachine_types.go index 3f20a559ff..f1c0550766 100644 --- a/api/v1beta1/openstackmachine_types.go +++ b/api/v1beta1/openstackmachine_types.go @@ -86,7 +86,7 @@ type OpenStackMachineSpec struct { // The server group to assign the machine to. // +optional - ServerGroup *ServerGroupFilter `json:"serverGroup,omitempty"` + ServerGroup *ServerGroupParam `json:"serverGroup,omitempty"` // IdentityRef is a reference to a secret holding OpenStack credentials // to be used when reconciling this machine. If not specified, the diff --git a/api/v1beta1/types.go b/api/v1beta1/types.go index bfdef09c6b..9bf90d826d 100644 --- a/api/v1beta1/types.go +++ b/api/v1beta1/types.go @@ -547,9 +547,30 @@ type AdditionalBlockDevice struct { Storage BlockDeviceStorage `json:"storage"` } +// ServerGroupParam specifies an OpenStack server group. It may be specified by ID or filter, but not both. +// +kubebuilder:validation:MaxProperties:=1 +// +kubebuilder:validation:MinProperties:=1 +type ServerGroupParam struct { + // ID is the ID of the server group to use. + // +kubebuilder:validation:Format:=uuid + ID optional.String `json:"id,omitempty"` + + // Filter specifies a query to select an OpenStack server group. If provided, it cannot be empty. + Filter *ServerGroupFilter `json:"filter,omitempty"` +} + +// ServerGroupFilter specifies a query to select an OpenStack server group. At least one property must be set. +// +kubebuilder:validation:MinProperties:=1 type ServerGroupFilter struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` + // Name is the name of a server group to look for. + Name optional.String `json:"name,omitempty"` +} + +func (f *ServerGroupFilter) IsZero() bool { + if f == nil { + return true + } + return f.Name == nil } // BlockDeviceType defines the type of block device to create. diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 69d71929a1..857c85788b 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -984,8 +984,8 @@ func (in *OpenStackMachineSpec) DeepCopyInto(out *OpenStackMachineSpec) { } if in.ServerGroup != nil { in, out := &in.ServerGroup, &out.ServerGroup - *out = new(ServerGroupFilter) - **out = **in + *out = new(ServerGroupParam) + (*in).DeepCopyInto(*out) } if in.IdentityRef != nil { in, out := &in.IdentityRef, &out.IdentityRef @@ -1563,6 +1563,11 @@ func (in *SecurityGroupStatus) DeepCopy() *SecurityGroupStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServerGroupFilter) DeepCopyInto(out *ServerGroupFilter) { *out = *in + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerGroupFilter. @@ -1575,6 +1580,31 @@ func (in *ServerGroupFilter) DeepCopy() *ServerGroupFilter { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServerGroupParam) DeepCopyInto(out *ServerGroupParam) { + *out = *in + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(string) + **out = **in + } + if in.Filter != nil { + in, out := &in.Filter, &out.Filter + *out = new(ServerGroupFilter) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerGroupParam. +func (in *ServerGroupParam) DeepCopy() *ServerGroupParam { + if in == nil { + return nil + } + out := new(ServerGroupParam) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServerMetadata) DeepCopyInto(out *ServerMetadata) { *out = *in diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml index acdaa6eae7..3310ca1e50 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml @@ -5598,10 +5598,22 @@ spec: type: array serverGroup: description: The server group to assign the machine to. + maxProperties: 1 + minProperties: 1 properties: + filter: + description: Filter specifies a query to select an OpenStack + server group. If provided, it cannot be empty. + minProperties: 1 + properties: + name: + description: Name is the name of a server group to + look for. + type: string + type: object id: - type: string - name: + description: ID is the ID of the server group to use. + format: uuid type: string type: object serverMetadata: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml index f01e35e574..136e031bb5 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml @@ -3035,10 +3035,24 @@ spec: serverGroup: description: The server group to assign the machine to. + maxProperties: 1 + minProperties: 1 properties: + filter: + description: Filter specifies a query to select + an OpenStack server group. If provided, it cannot + be empty. + minProperties: 1 + properties: + name: + description: Name is the name of a server + group to look for. + type: string + type: object id: - type: string - name: + description: ID is the ID of the server group + to use. + format: uuid type: string type: object serverMetadata: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml index 1ea294dcb1..5257d76d04 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml @@ -2364,10 +2364,21 @@ spec: type: array serverGroup: description: The server group to assign the machine to. + maxProperties: 1 + minProperties: 1 properties: + filter: + description: Filter specifies a query to select an OpenStack server + group. If provided, it cannot be empty. + minProperties: 1 + properties: + name: + description: Name is the name of a server group to look for. + type: string + type: object id: - type: string - name: + description: ID is the ID of the server group to use. + format: uuid type: string type: object serverMetadata: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml index 4c1b1abb98..111b256b06 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml @@ -2045,10 +2045,22 @@ spec: type: array serverGroup: description: The server group to assign the machine to. + maxProperties: 1 + minProperties: 1 properties: + filter: + description: Filter specifies a query to select an OpenStack + server group. If provided, it cannot be empty. + minProperties: 1 + properties: + name: + description: Name is the name of a server group to + look for. + type: string + type: object id: - type: string - name: + description: ID is the ID of the server group to use. + format: uuid type: string type: object serverMetadata: diff --git a/controllers/openstackmachine_controller_test.go b/controllers/openstackmachine_controller_test.go index 53c504e05c..f40802aa98 100644 --- a/controllers/openstackmachine_controller_test.go +++ b/controllers/openstackmachine_controller_test.go @@ -92,7 +92,7 @@ func getDefaultOpenStackMachine() *infrav1.OpenStackMachine { }, ConfigDrive: pointer.Bool(true), SecurityGroups: []infrav1.SecurityGroupParam{}, - ServerGroup: &infrav1.ServerGroupFilter{ID: serverGroupUUID}, + ServerGroup: &infrav1.ServerGroupParam{ID: pointer.String(serverGroupUUID)}, }, Status: infrav1.OpenStackMachineStatus{ Resolved: &infrav1.ResolvedMachineSpec{ diff --git a/docs/book/src/api/v1beta1/api.md b/docs/book/src/api/v1beta1/api.md index b97042eec6..10a8f3e104 100644 --- a/docs/book/src/api/v1beta1/api.md +++ b/docs/book/src/api/v1beta1/api.md @@ -715,8 +715,8 @@ RootVolume
serverGroup
serverGroup
serverGroup
(Appears on: +ServerGroupParam) +
++
ServerGroupFilter specifies a query to select an OpenStack server group. At least one property must be set.
+ +Field | +Description | +
---|---|
+name + +string + + |
+
+ Name is the name of a server group to look for. + |
+
+(Appears on: OpenStackMachineSpec)
+
ServerGroupParam specifies an OpenStack server group. It may be specified by ID or filter, but not both.
+ ID is the ID of the server group to use. |
|
-name + filter -string + +ServerGroupFilter + |
+ Filter specifies a query to select an OpenStack server group. If provided, it cannot be empty. |