Skip to content

Commit 5c24c4c

Browse files
committed
Port: fix type for SecurityGroupRefs
It should be a list of KubernetesNameRef and not OpenStackName. Fixes #438
1 parent 1b77db8 commit 5c24c4c

8 files changed

Lines changed: 20 additions & 21 deletions

File tree

api/v1alpha1/port_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ type PortResourceSpec struct {
162162
// +optional
163163
AdminStateUp *bool `json:"adminStateUp,omitempty"`
164164

165-
// securityGroupRefs are the names of the security groups associated
165+
// securityGroupRefs are references to the security groups associated
166166
// with this port.
167167
// +kubebuilder:validation:MaxItems:=64
168168
// +listType=set
169169
// +optional
170-
SecurityGroupRefs []OpenStackName `json:"securityGroupRefs,omitempty"` //nolint:kubeapilinter // https://github.com/k-orc/openstack-resource-controller/issues/438
170+
SecurityGroupRefs []KubernetesNameRef `json:"securityGroupRefs,omitempty"`
171171

172172
// vnicType specifies the type of vNIC which this port should be
173173
// attached to. This is used to determine which mechanism driver(s) to

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/models-schema/zz_generated.openapi.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/openstack.k-orc.cloud_ports.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,11 @@ spec:
379379
rule: self == oldSelf
380380
securityGroupRefs:
381381
description: |-
382-
securityGroupRefs are the names of the security groups associated
382+
securityGroupRefs are references to the security groups associated
383383
with this port.
384384
items:
385-
maxLength: 255
385+
maxLength: 253
386386
minLength: 1
387-
pattern: ^[^,]+$
388387
type: string
389388
maxItems: 64
390389
type: array

internal/controllers/port/actuator_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,23 @@ func makeSecGroupWithID(id string) *orcv1alpha1.SecurityGroup {
234234
}
235235

236236
func TestHandleSecurityGroupRefsUpdate(t *testing.T) {
237-
sgWebName := orcv1alpha1.OpenStackName("sg-web")
238-
sgDbName := orcv1alpha1.OpenStackName("sg-db")
237+
sgWebName := orcv1alpha1.KubernetesNameRef("sg-web")
238+
sgDbName := orcv1alpha1.KubernetesNameRef("sg-db")
239239

240240
idWeb := "d564a44b-346c-4f71-92b1-5899b8979374"
241241
idDb := "1d23d83b-2a78-4c12-9e55-0a6e026dd201"
242242
idOther := "7e8a3b8d-6c17-4581-80a5-a4b8b64f9b0c"
243243

244244
testCases := []struct {
245245
name string
246-
newValue []orcv1alpha1.OpenStackName
246+
newValue []orcv1alpha1.KubernetesNameRef
247247
existingValue []string
248248
secGroupMap map[string]*orcv1alpha1.SecurityGroup
249249
expectChange bool
250250
}{
251251
{
252252
name: "Identical",
253-
newValue: []orcv1alpha1.OpenStackName{sgWebName, sgDbName},
253+
newValue: []orcv1alpha1.KubernetesNameRef{sgWebName, sgDbName},
254254
existingValue: []string{idWeb, idDb},
255255
secGroupMap: map[string]*orcv1alpha1.SecurityGroup{
256256
string(sgWebName): makeSecGroupWithID(idWeb),
@@ -260,7 +260,7 @@ func TestHandleSecurityGroupRefsUpdate(t *testing.T) {
260260
},
261261
{
262262
name: "Identical but different order",
263-
newValue: []orcv1alpha1.OpenStackName{sgDbName, sgWebName},
263+
newValue: []orcv1alpha1.KubernetesNameRef{sgDbName, sgWebName},
264264
existingValue: []string{idWeb, idDb},
265265
secGroupMap: map[string]*orcv1alpha1.SecurityGroup{
266266
string(sgWebName): makeSecGroupWithID(idWeb),
@@ -270,7 +270,7 @@ func TestHandleSecurityGroupRefsUpdate(t *testing.T) {
270270
},
271271
{
272272
name: "Add a security group",
273-
newValue: []orcv1alpha1.OpenStackName{sgWebName, sgDbName},
273+
newValue: []orcv1alpha1.KubernetesNameRef{sgWebName, sgDbName},
274274
existingValue: []string{idWeb},
275275
secGroupMap: map[string]*orcv1alpha1.SecurityGroup{
276276
string(sgWebName): makeSecGroupWithID(idWeb),
@@ -280,7 +280,7 @@ func TestHandleSecurityGroupRefsUpdate(t *testing.T) {
280280
},
281281
{
282282
name: "Remove a security group",
283-
newValue: []orcv1alpha1.OpenStackName{sgWebName},
283+
newValue: []orcv1alpha1.KubernetesNameRef{sgWebName},
284284
existingValue: []string{idWeb, idDb},
285285
secGroupMap: map[string]*orcv1alpha1.SecurityGroup{
286286
string(sgWebName): makeSecGroupWithID(idWeb),
@@ -290,7 +290,7 @@ func TestHandleSecurityGroupRefsUpdate(t *testing.T) {
290290
},
291291
{
292292
name: "Replace a security group",
293-
newValue: []orcv1alpha1.OpenStackName{sgWebName, sgDbName},
293+
newValue: []orcv1alpha1.KubernetesNameRef{sgWebName, sgDbName},
294294
existingValue: []string{idWeb, idOther},
295295
secGroupMap: map[string]*orcv1alpha1.SecurityGroup{
296296
string(sgWebName): makeSecGroupWithID(idWeb),
@@ -300,14 +300,14 @@ func TestHandleSecurityGroupRefsUpdate(t *testing.T) {
300300
},
301301
{
302302
name: "Remove all security groups",
303-
newValue: []orcv1alpha1.OpenStackName{},
303+
newValue: []orcv1alpha1.KubernetesNameRef{},
304304
existingValue: []string{idWeb, idDb},
305305
secGroupMap: map[string]*orcv1alpha1.SecurityGroup{},
306306
expectChange: true,
307307
},
308308
{
309309
name: "Add to empty list",
310-
newValue: []orcv1alpha1.OpenStackName{sgWebName},
310+
newValue: []orcv1alpha1.KubernetesNameRef{sgWebName},
311311
existingValue: []string{},
312312
secGroupMap: map[string]*orcv1alpha1.SecurityGroup{
313313
string(sgWebName): makeSecGroupWithID(idWeb),

pkg/clients/applyconfiguration/api/v1alpha1/portresourcespec.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/apivalidations/port_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var _ = Describe("ORC Port API validations", func() {
107107
WithSecurityGroupRefs("sg-foo").
108108
WithPortSecurity(orcv1alpha1.PortSecurityEnabled))
109109
Expect(applyObj(ctx, port, patch)).To(Succeed())
110-
Expect(port.Spec.Resource.SecurityGroupRefs).To(Equal([]orcv1alpha1.OpenStackName{"sg-foo"}))
110+
Expect(port.Spec.Resource.SecurityGroupRefs).To(Equal([]orcv1alpha1.KubernetesNameRef{"sg-foo"}))
111111
Expect(port.Spec.Resource.PortSecurity).To(Equal(orcv1alpha1.PortSecurityEnabled))
112112
})
113113

website/docs/crd-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,7 @@ _Appears in:_
27302730
| `allowedAddressPairs` _[AllowedAddressPair](#allowedaddresspair) array_ | allowedAddressPairs are allowed addresses associated with this port. | | MaxItems: 128 <br />Optional: \{\} <br /> |
27312731
| `addresses` _[Address](#address) array_ | addresses are the IP addresses for the port. | | MaxItems: 128 <br />Optional: \{\} <br /> |
27322732
| `adminStateUp` _boolean_ | adminStateUp is the administrative state of the port,<br />which is up (true) or down (false). The default value is true. | true | Optional: \{\} <br /> |
2733-
| `securityGroupRefs` _[OpenStackName](#openstackname) array_ | securityGroupRefs are the names of the security groups associated<br />with this port. | | MaxItems: 64 <br />MaxLength: 255 <br />MinLength: 1 <br />Pattern: `^[^,]+$` <br />Optional: \{\} <br /> |
2733+
| `securityGroupRefs` _[KubernetesNameRef](#kubernetesnameref) array_ | securityGroupRefs are references to the security groups associated<br />with this port. | | MaxItems: 64 <br />MaxLength: 253 <br />MinLength: 1 <br />Optional: \{\} <br /> |
27342734
| `vnicType` _string_ | vnicType specifies the type of vNIC which this port should be<br />attached to. This is used to determine which mechanism driver(s) to<br />be used to bind the port. The valid values are normal, macvtap,<br />direct, baremetal, direct-physical, virtio-forwarder, smart-nic and<br />remote-managed, although these values will not be validated in this<br />API to ensure compatibility with future neutron changes or custom<br />implementations. What type of vNIC is actually available depends on<br />deployments. If not specified, the Neutron default value is used. | | MaxLength: 64 <br />Optional: \{\} <br /> |
27352735
| `portSecurity` _[PortSecurityState](#portsecuritystate)_ | portSecurity controls port security for this port.<br />When set to Enabled, port security is enabled.<br />When set to Disabled, port security is disabled and SecurityGroupRefs must be empty.<br />When set to Inherit (default), it takes the value from the network level. | Inherit | Enum: [Enabled Disabled Inherit] <br />Optional: \{\} <br /> |
27362736
| `projectRef` _[KubernetesNameRef](#kubernetesnameref)_ | projectRef is a reference to the ORC Project this resource is associated with.<br />Typically, only used by admin. | | MaxLength: 253 <br />MinLength: 1 <br />Optional: \{\} <br /> |

0 commit comments

Comments
 (0)