Skip to content

Add per-interface DHCP relay configuration - #543

Open
nikatza wants to merge 2 commits into
mainfrom
origin/nxos-perinterface-dhcprelay
Open

Add per-interface DHCP relay configuration#543
nikatza wants to merge 2 commits into
mainfrom
origin/nxos-perinterface-dhcprelay

Conversation

@nikatza

@nikatza nikatza commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Resources

apiVersion: networking.metal.ironcore.dev/v1alpha1
kind: DHCPRelay
metadata:
  labels:
    app.kubernetes.io/name: network-operator
    app.kubernetes.io/managed-by: kustomize
    networking.metal.ironcore.dev/device-name: leaf1
  name: dhcprelay100
spec:
  deviceRef:
    name: leaf1
  interfaceRef:
    name: svi100
  servers:
    - "10.0.0.10"
---
apiVersion: networking.metal.ironcore.dev/v1alpha1
kind: DHCPRelay
metadata:
  labels:
    app.kubernetes.io/name: network-operator
    app.kubernetes.io/managed-by: kustomize
    networking.metal.ironcore.dev/device-name: leaf1
  name: dhcprelay200
spec:
  deviceRef:
    name: leaf1
  interfaceRef:
    name: svi200
  vrfRef:
    name: dhcp-vrf
  servers:
    - "10.0.0.10"
    - "10.0.1.10"

K8s:

❯ k get dhcprelays                                                                                                                                                                   13:11
NAME           DEVICE   VRF        SERVERS                     READY   AGE
dhcprelay100   leaf1               ["10.0.0.10"]               True    29s
dhcprelay200   leaf1    dhcp-vrf   ["10.0.0.10","10.0.1.10"]   True    28s

NXOS config:

interface Vlan100
  no shutdown
  no ip redirects
  ip address 192.168.100.1/24
  ip dhcp relay address 10.0.0.10

interface Vlan200
  no shutdown
  no ip redirects
  ip address 192.168.101.1/24
  ip dhcp relay address 10.0.0.10 use-vrf DHCP-VRF-GREEN
  ip dhcp relay address 10.0.1.10 use-vrf DHCP-VRF-GREEN

NXOS sh ip dhcp relay

Helper addresses are configured on the following interfaces:
 Interface        Relay Address     VRF Name
 -------------    -------------     --------
 Vlan100           10.0.0.10
 Vlan200           10.0.0.10        DHCP-VRF-GREEN
 Vlan200           10.0.1.10        DHCP-VRF-GREEN

@nikatza
nikatza force-pushed the origin/nxos-perinterface-dhcprelay branch 3 times, most recently from 7c9a1ec to e84779b Compare September 2, 2026 20:21
@hardikdr hardikdr added the area/switch-automation Automation processes for network switch management and operations. label Sep 3, 2026
@hardikdr hardikdr added this to Roadmap Sep 3, 2026
@nikatza nikatza changed the title Fix DHCPRelay API and gnmi integration tests Update DHCPRelay API Sep 3, 2026
@nikatza
nikatza force-pushed the origin/nxos-perinterface-dhcprelay branch 5 times, most recently from bc5a79e to fe821a8 Compare September 3, 2026 14:32
@nikatza nikatza changed the title Update DHCPRelay API Add per-interface DHCP relay configuration Sep 3, 2026
@nikatza
nikatza force-pushed the origin/nxos-perinterface-dhcprelay branch 2 times, most recently from 7781873 to 2dab9bf Compare September 3, 2026 14:40
@nikatza
nikatza marked this pull request as ready for review September 3, 2026 14:51
Comment thread api/core/v1alpha1/dhcprelay_types.go Outdated
@nikatza
nikatza marked this pull request as draft September 4, 2026 07:27
@nikatza
nikatza force-pushed the origin/nxos-perinterface-dhcprelay branch 5 times, most recently from d4fd217 to c9f1305 Compare September 5, 2026 10:44
Introduce per-interface configuration for the DHCPRelay relay
(previously all interfaces were configured equally with one object).
With this change the DHCPRelay is keyed with a Device and an Interface
reference. This brings more flexibility to high-level resources.

As per code project agreement the previous API is mantained and marked
as deprecated: added validation hooks to return a warning if used. CEL
rules prevent mixed used of deprecated and new format.

The migration path for existing DHCPRelay objects that use the
deprecated InterfaceRefs field requires deleting those objects and
creating new ones using the new fields. Objects using the deprecated
field InterfaceRefs likely replace the entire DHCPRelay tree and thus
would remove configuration for all interfaces, even for those that are
not referenced.

Replace the interfaces list with a singular interfaceRef. DHCP server
and VRF settings now live on the DHCPRelay resource, allowing each
resource to configure a single interface. Update the controller and
NX-OS provider to reconcile and delete relay configuration per
interface, allowing multiple DHCPRelay resources on a device while
rejecting duplicates for the same interface. Remove the status
update, update samples/CRDs, and cover both the preferred and
deprecated APIs in controller and gNMI tests.

Signed-off-by: Pujol <enric.pujol@sap.com>
Track fixture resources in creation order and tear them down in reverse,
waiting for each deletion to complete before continuing. This preserves
dependency ordering and avoids concurrent cleanup races during envtest.

An example for this situation is the DHCPRelay, which references
Interfaces and VRFs. If these resources are deleted the finalizer fails
as it can't derive the name of the interface/vrf on the device (e.g.,
eth1/1). On NXOS this would imply having to leave the entire dhcp tree
on the post-delete section of the fixture.

Signed-off-by: Pujol <enric.pujol@sap.com>
@nikatza
nikatza force-pushed the origin/nxos-perinterface-dhcprelay branch from c9f1305 to 93b0dd9 Compare September 5, 2026 10:53
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Merging this branch changes the coverage (2 decrease, 1 increase)

Impacted Packages Coverage Δ 🤖
github.com/ironcore-dev/network-operator/api/core/v1alpha1 2.52% (ø)
github.com/ironcore-dev/network-operator/cmd 0.00% (ø)
github.com/ironcore-dev/network-operator/internal/controller/core 61.52% (+0.27%) 👍
github.com/ironcore-dev/network-operator/internal/provider 0.00% (ø)
github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos 9.43% (-0.03%) 👎
github.com/ironcore-dev/network-operator/internal/webhook/core/v1alpha1 95.53% (-0.20%) 👎
github.com/ironcore-dev/network-operator/test/gnmi 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/ironcore-dev/network-operator/api/core/v1alpha1/dhcprelay_types.go 12.50% (ø) 8 1 7
github.com/ironcore-dev/network-operator/api/core/v1alpha1/zz_generated.deepcopy.go 0.00% (ø) 2693 0 2693
github.com/ironcore-dev/network-operator/cmd/main.go 0.00% (ø) 317 (+3) 0 317 (+3)
github.com/ironcore-dev/network-operator/internal/controller/core/dhcprelay_controller.go 70.80% (+4.91%) 274 (+16) 194 (+24) 80 (-8) 👍
github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos/dhcprelay.go 0.00% (ø) 4 (+1) 0 4 (+1)
github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos/provider.go 0.35% (-0.00%) 2296 (+10) 8 2288 (+10) 👎
github.com/ironcore-dev/network-operator/internal/provider/provider.go 0.00% (ø) 42 0 42
github.com/ironcore-dev/network-operator/internal/webhook/core/v1alpha1/dhcprelay_webhook.go 91.67% (+91.67%) 12 (+12) 11 (+11) 1 (+1) 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/ironcore-dev/network-operator/internal/controller/core/dhcprelay_controller_deprecated_test.go
  • github.com/ironcore-dev/network-operator/internal/controller/core/dhcprelay_controller_test.go
  • github.com/ironcore-dev/network-operator/internal/controller/core/suite_test.go
  • github.com/ironcore-dev/network-operator/internal/webhook/core/v1alpha1/dhcprelay_webhook_test.go
  • github.com/ironcore-dev/network-operator/internal/webhook/core/v1alpha1/webhook_suite_test.go
  • github.com/ironcore-dev/network-operator/test/gnmi/gnmi_suite_test.go
  • github.com/ironcore-dev/network-operator/test/gnmi/gnmi_test.go

@nikatza
nikatza marked this pull request as ready for review September 5, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/switch-automation Automation processes for network switch management and operations. size/XXL

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants