Skip to content

Commit 6901189

Browse files
committed
port: add propagationUplinkStatus field
1 parent 93a12a8 commit 6901189

17 files changed

Lines changed: 107 additions & 32 deletions

File tree

.github/workflows/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
with:
3737
enable_workaround_docker_io: 'false'
3838
branch: ${{ matrix.openstack_version }}
39-
enabled_services: "openstack-cli-server"
39+
enabled_services: "openstack-cli-server,neutron-uplink-status-propagation"
4040

4141
- name: Deploy a Kind Cluster
4242
uses: helm/kind-action@92086f6be054225fa813e0a4b13787fc9088faab

api/v1alpha1/port_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ type PortResourceSpec struct {
185185
// +kubebuilder:validation:MaxLength=36
186186
// +optional
187187
HostID string `json:"hostID,omitempty"`
188+
189+
// propagateUplinkStatus represents the uplink status propagation of
190+
// the port.
191+
// +optional
192+
PropagateUplinkStatus *bool `json:"propagateUplinkStatus,omitempty"`
188193
}
189194

190195
type PortResourceStatus struct {
@@ -266,7 +271,7 @@ type PortResourceStatus struct {
266271
// propagateUplinkStatus represents the uplink status propagation of
267272
// the port.
268273
// +optional
269-
PropagateUplinkStatus *bool `json:"propagateUplinkStatus,omitempty"`
274+
PropagateUplinkStatus bool `json:"propagateUplinkStatus,omitempty"`
270275

271276
// vnicType is the type of vNIC which this port is attached to.
272277
// +kubebuilder:validation:MaxLength:=64

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 5 deletions
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: 7 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ spec:
347347
x-kubernetes-validations:
348348
- message: projectRef is immutable
349349
rule: self == oldSelf
350+
propagateUplinkStatus:
351+
description: |-
352+
propagateUplinkStatus represents the uplink status propagation of
353+
the port.
354+
type: boolean
350355
securityGroupRefs:
351356
description: |-
352357
securityGroupRefs are the names of the security groups associated

internal/controllers/port/actuator.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,13 @@ func (actuator portActuator) CreateResource(ctx context.Context, obj *orcv1alpha
171171
}
172172

173173
createOpts := ports.CreateOpts{
174-
NetworkID: *network.Status.ID,
175-
Name: getResourceName(obj),
176-
Description: string(ptr.Deref(resource.Description, "")),
177-
ProjectID: projectID,
178-
AdminStateUp: resource.AdminStateUp,
179-
MACAddress: resource.MACAddress,
174+
NetworkID: *network.Status.ID,
175+
Name: getResourceName(obj),
176+
Description: string(ptr.Deref(resource.Description, "")),
177+
ProjectID: projectID,
178+
AdminStateUp: resource.AdminStateUp,
179+
MACAddress: resource.MACAddress,
180+
PropagateUplinkStatus: resource.PropagateUplinkStatus,
180181
}
181182

182183
if len(resource.AllowedAddressPairs) > 0 {
@@ -345,6 +346,7 @@ func (actuator portActuator) updateResource(ctx context.Context, obj orcObjectPT
345346
handleAllowedAddressPairsUpdate(baseUpdateOpts, resource, osResource)
346347
handleSecurityGroupRefsUpdate(baseUpdateOpts, resource, osResource, secGroupMap)
347348
handleAdminStateUpUpdate(baseUpdateOpts, resource, osResource)
349+
handlePropagateUplinkStatusUpdate(baseUpdateOpts, resource, osResource)
348350
updateOpts = baseUpdateOpts
349351
}
350352

@@ -530,6 +532,16 @@ func handleAdminStateUpUpdate(updateOpts *ports.UpdateOpts, resource *resourceSp
530532
}
531533
}
532534

535+
func handlePropagateUplinkStatusUpdate(updateOpts *ports.UpdateOpts, resource *resourceSpecT, osResource *osResourceT) {
536+
// When this field is not defined, let's set this as `false` to
537+
// avoid errors in environments where uplink-propagation-status
538+
// extension isn't enabled.
539+
propagateUplinkStatus := ptr.Deref(resource.PropagateUplinkStatus, false)
540+
if propagateUplinkStatus != osResource.PropagateUplinkStatus {
541+
updateOpts.PropagateUplinkStatus = &propagateUplinkStatus
542+
}
543+
}
544+
533545
type portHelperFactory struct{}
534546

535547
var _ helperFactory = portHelperFactory{}

internal/controllers/port/actuator_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,31 @@ func TestHandleAdminStateUpUpdate(t *testing.T) {
435435
})
436436
}
437437
}
438+
439+
func TestHandlePropagateUplinkStatusUpdate(t *testing.T) {
440+
testCases := []struct {
441+
name string
442+
newValue *bool
443+
existingValue bool
444+
expectChange bool
445+
}{
446+
{name: "Set the same value as the existing one", newValue: ptr.To(true), existingValue: true, expectChange: false},
447+
{name: "Enabled when was disabled", newValue: ptr.To(true), existingValue: false, expectChange: true},
448+
{name: "Disable if it is not defined on spec", newValue: nil, existingValue: true, expectChange: true},
449+
}
450+
451+
for _, tt := range testCases {
452+
t.Run(tt.name, func(t *testing.T) {
453+
resource := &orcv1alpha1.PortResourceSpec{PropagateUplinkStatus: tt.newValue}
454+
osResource := &osclients.PortExt{Port: ports.Port{PropagateUplinkStatus: tt.existingValue}}
455+
updateOpts := &ports.UpdateOpts{}
456+
457+
handlePropagateUplinkStatusUpdate(updateOpts, resource, osResource)
458+
459+
got, _ := needsUpdate(updateOpts)
460+
if got != tt.expectChange {
461+
t.Errorf("expected needsUpdate=%v, got %v", tt.expectChange, got)
462+
}
463+
})
464+
}
465+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ status:
1717
vnicType: macvtap
1818
macAddress: fa:16:3e:23:fd:d7
1919
hostID: devstack
20+
propagateUplinkStatus: true
2021
tags:
2122
- tag1
2223
---

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ spec:
8686
projectRef: port-create-full
8787
macAddress: fa:16:3e:23:fd:d7
8888
hostID: devstack
89+
propagateUplinkStatus: true

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ status:
99
adminStateUp: true
1010
portSecurityEnabled: true
1111
propagateUplinkStatus: false
12-
revisionNumber: 1
12+
revisionNumber: 2
1313
status: DOWN
1414
vnicType: normal
1515
---

0 commit comments

Comments
 (0)