Skip to content

Commit ac3a8e2

Browse files
committed
Port: add binding:host field
1 parent 67fdd10 commit ac3a8e2

File tree

16 files changed

+147
-6
lines changed

16 files changed

+147
-6
lines changed

api/v1alpha1/port_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ type PortResourceSpec struct {
180180
// +kubebuilder:validation:MaxLength=32
181181
// +optional
182182
MACAddress string `json:"macAddress,omitempty"`
183+
184+
// hostID is the ID of host where the port resides.
185+
// +kubebuilder:validation:MaxLength=36
186+
// +optional
187+
HostID string `json:"hostID,omitempty"`
183188
}
184189

185190
type PortResourceStatus struct {
@@ -272,6 +277,11 @@ type PortResourceStatus struct {
272277
// +optional
273278
PortSecurityEnabled *bool `json:"portSecurityEnabled,omitempty"`
274279

280+
// hostID is the ID of host where the port resides.
281+
// +kubebuilder:validation:MaxLength=128
282+
// +optional
283+
HostID string `json:"hostID,omitempty"`
284+
275285
NeutronStatusMetadata `json:",inline"`
276286
}
277287

cmd/models-schema/zz_generated.openapi.go

Lines changed: 14 additions & 0 deletions
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ spec:
298298
maxLength: 255
299299
minLength: 1
300300
type: string
301+
hostID:
302+
description: hostID is the ID of host where the port resides.
303+
type: string
301304
macAddress:
302305
description: macAddress is the MAC address of the port.
303306
maxLength: 32
@@ -561,6 +564,9 @@ spec:
561564
maxItems: 128
562565
type: array
563566
x-kubernetes-list-type: atomic
567+
hostID:
568+
description: hostID is the ID of host where the port resides.
569+
type: string
564570
macAddress:
565571
description: macAddress is the MAC address of the port.
566572
maxLength: 1024

internal/controllers/port/actuator.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ func (actuator portActuator) CreateResource(ctx context.Context, obj *orcv1alpha
254254
portsBindingOpts := portsbinding.CreateOptsExt{
255255
CreateOptsBuilder: createOpts,
256256
VNICType: resource.VNICType,
257+
HostID: resource.HostID,
257258
}
258259

259260
portSecurityOpts := portsecurity.PortCreateOptsExt{
@@ -504,6 +505,16 @@ func handlePortBindingUpdate(updateOpts ports.UpdateOptsBuilder, resource *resou
504505
}
505506
}
506507
}
508+
509+
if resource.HostID != "" {
510+
if resource.HostID != osResource.HostID {
511+
updateOpts = &portsbinding.UpdateOptsExt{
512+
UpdateOptsBuilder: updateOpts,
513+
HostID: &resource.HostID,
514+
}
515+
}
516+
}
517+
507518
return updateOpts
508519
}
509520

internal/controllers/port/status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func (portStatusWriter) ApplyResourceStatus(log logr.Logger, osResource *osResou
7272
WithPortSecurityEnabled(osResource.PortSecurityEnabled).
7373
WithRevisionNumber(int64(osResource.RevisionNumber)).
7474
WithCreatedAt(metav1.NewTime(osResource.CreatedAt)).
75-
WithUpdatedAt(metav1.NewTime(osResource.UpdatedAt))
75+
WithUpdatedAt(metav1.NewTime(osResource.UpdatedAt)).
76+
WithHostID(osResource.HostID)
7677

7778
if osResource.Description != "" {
7879
resourceStatus.WithDescription(osResource.Description)

internal/controllers/port/tests/port-create-full/00-assert.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ status:
1414
portSecurityEnabled: true
1515
propagateUplinkStatus: false
1616
status: DOWN
17-
vnicType: direct
17+
vnicType: macvtap
1818
macAddress: fa:16:3e:23:fd:d7
19+
hostID: devstack
1920
tags:
2021
- tag1
2122
---

internal/controllers/port/tests/port-create-full/00-create-resource.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ spec:
8282
- subnetRef: port-create-full
8383
ip: 192.168.155.122
8484
portSecurity: Enabled
85-
vnicType: direct
85+
vnicType: macvtap
8686
projectRef: port-create-full
8787
macAddress: fa:16:3e:23:fd:d7
88+
hostID: devstack

internal/controllers/port/tests/port-update/00-assert.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ resourceRefs:
66
kind: port
77
name: port-update
88
ref: port
9+
- apiVersion: openstack.k-orc.cloud/v1alpha1
10+
kind: port
11+
name: port-update-admin
12+
ref: portAdmin
913
assertAll:
1014
- celExpr: "port.status.id != ''"
1115
- celExpr: "port.status.resource.createdAt != ''"
1216
- celExpr: "port.status.resource.updatedAt != ''"
1317
- celExpr: "port.status.resource.macAddress != ''"
1418
- celExpr: "!has(port.status.resource.fixedIPs)"
1519
- celExpr: "!has(port.status.resource.description)"
20+
# Following the network API reference, the default value for
21+
# hostID field is an empty string.
22+
- celExpr: "portAdmin.status.resource.hostID == ''"
1623
---
1724
apiVersion: openstack.k-orc.cloud/v1alpha1
1825
kind: Port
@@ -36,3 +43,26 @@ status:
3643
message: OpenStack resource is up to date
3744
status: "False"
3845
reason: Success
46+
---
47+
apiVersion: openstack.k-orc.cloud/v1alpha1
48+
kind: Port
49+
metadata:
50+
name: port-update-admin
51+
status:
52+
resource:
53+
name: port-update-admin
54+
adminStateUp: true
55+
portSecurityEnabled: true
56+
propagateUplinkStatus: false
57+
revisionNumber: 1
58+
status: DOWN
59+
vnicType: normal
60+
conditions:
61+
- type: Available
62+
message: OpenStack resource is available
63+
status: "True"
64+
reason: Success
65+
- type: Progressing
66+
message: OpenStack resource is up to date
67+
status: "False"
68+
reason: Success

internal/controllers/port/tests/port-update/00-minimal-resource.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@ spec:
1212
portSecurity: Disabled
1313
# Need to set the default values to revert them correctly in the 02-revert-resource step.
1414
vnicType: normal
15+
---
16+
# This port is intended to be used only to test fields editable
17+
# by admin users
18+
apiVersion: openstack.k-orc.cloud/v1alpha1
19+
kind: Port
20+
metadata:
21+
name: port-update-admin
22+
spec:
23+
cloudCredentialsRef:
24+
cloudName: openstack-admin
25+
secretName: openstack-clouds
26+
managementPolicy: managed
27+
resource:
28+
networkRef: port-update

internal/controllers/port/tests/port-update/01-assert.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,19 @@ status:
4848
reason: Success
4949
- type: Progressing
5050
status: "False"
51-
reason: Success
51+
reason: Success
52+
---
53+
apiVersion: openstack.k-orc.cloud/v1alpha1
54+
kind: Port
55+
metadata:
56+
name: port-update-admin
57+
status:
58+
resource:
59+
hostID: devstack
60+
conditions:
61+
- type: Available
62+
status: "True"
63+
reason: Success
64+
- type: Progressing
65+
status: "False"
66+
reason: Success

0 commit comments

Comments
 (0)