Skip to content

Commit cc8c8bd

Browse files
nikatzaweneghawi
authored andcommitted
[NXOS] Add DHCPRelay provider implementation
Enable or disable the DHCP feature based on AdminState. When enabled, configure DHCP relay on each referenced interface with the specified server addresses. The provider uses the VRF context from VrfRef (or the NXOS default "!unspecified" if no VRF is specified) when configuring server addresses. The implementation uses the Update operation to ensure stale DHCP relay entries are removed when the configuration changes. This also affects entries referencing interfaces not managed by the operator. The entire tree is removed on deletion, affecting non-managed interfaces., It leaves the DHCP feature in its current state. GetDHCPRelayStatus queries the device for all interfaces with DHCP relay configured and returns their names.
1 parent f8e6673 commit cc8c8bd

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

internal/controller/core/aaa_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
"sigs.k8s.io/controller-runtime/pkg/predicate"
2727

2828
"github.com/ironcore-dev/network-operator/api/core/v1alpha1"
29-
"github.com/ironcore-dev/network-operator/internal/annotations"
3029
"github.com/ironcore-dev/network-operator/internal/clientutil"
3130
"github.com/ironcore-dev/network-operator/internal/conditions"
3231
"github.com/ironcore-dev/network-operator/internal/deviceutil"
32+
"github.com/ironcore-dev/network-operator/internal/paused"
3333
"github.com/ironcore-dev/network-operator/internal/provider"
3434
"github.com/ironcore-dev/network-operator/internal/resourcelock"
3535
)
@@ -102,9 +102,8 @@ func (r *AAAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl
102102
return ctrl.Result{}, err
103103
}
104104

105-
if annotations.IsPaused(device, obj) {
106-
log.Info("Reconciliation is paused for this object")
107-
return ctrl.Result{}, nil
105+
if isPaused, requeue, err := paused.EnsureCondition(ctx, r.Client, device, obj); isPaused || requeue || err != nil {
106+
return ctrl.Result{}, err
108107
}
109108

110109
if err := r.Locker.AcquireLock(ctx, device.Name, "aaa-controller"); err != nil {

internal/provider/cisco/nxos/provider.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var (
6060
_ provider.LLDPProvider = (*Provider)(nil)
6161
_ provider.DHCPRelayProvider = (*Provider)(nil)
6262
_ provider.AAAProvider = (*Provider)(nil)
63+
_ provider.DHCPRelayProvider = (*Provider)(nil)
6364
)
6465

6566
type Provider struct {
@@ -3119,6 +3120,65 @@ func (p *Provider) DeleteAAA(ctx context.Context, req *provider.DeleteAAARequest
31193120
return p.Update(ctx, conf...)
31203121
}
31213122

3123+
// EnsureDHCPRelay configures DHCP relay on the specified interfaces.
3124+
// Replaces the entire DHCP relay configuration on the device with the provided configuration in the request.
3125+
func (p *Provider) EnsureDHCPRelay(ctx context.Context, req *provider.DHCPRelayRequest) error {
3126+
f := new(Feature)
3127+
f.Name = "dhcp"
3128+
f.AdminSt = AdminStEnabled
3129+
3130+
// undocumented default value for the VRF property in DME (can be verified via NX-API)
3131+
vrfName := "!unspecified"
3132+
if req.VRF != nil {
3133+
vrfName = req.VRF.Spec.Name
3134+
}
3135+
3136+
conf := new(DHCPRelayConfig)
3137+
for _, intf := range req.Interfaces {
3138+
ifName, err := ShortName(intf.Spec.Name)
3139+
if err != nil {
3140+
return fmt.Errorf("dhcp relay: failed to get short name for interface %q: %w", intf.Spec.Name, err)
3141+
}
3142+
3143+
relay := &DHCPRelay{ID: ifName}
3144+
for _, addr := range req.DHCPRelay.Spec.Servers {
3145+
a, err := netip.ParseAddr(addr)
3146+
if err != nil {
3147+
return fmt.Errorf("dhcp relay: invalid server address %q: %w", addr, err)
3148+
}
3149+
relay.AddrItems.AddrList.Set(&DHCPRelayServer{Address: a, Vrf: vrfName})
3150+
}
3151+
conf.RelayIfList.Set(relay)
3152+
}
3153+
3154+
return p.Update(ctx, f, conf)
3155+
}
3156+
3157+
// DeleteDHCPRelay removes all DHCP relay configurations from the device.
3158+
func (p *Provider) DeleteDHCPRelay(ctx context.Context, req *provider.DHCPRelayRequest) error {
3159+
config := new(DHCPRelayConfig)
3160+
return p.client.Delete(ctx, config)
3161+
}
3162+
3163+
// GetDHCPRelayStatus retrieves the current DHCP relay status.
3164+
func (p *Provider) GetDHCPRelayStatus(ctx context.Context, req *provider.DHCPRelayRequest) (provider.DHCPRelayStatus, error) {
3165+
s := provider.DHCPRelayStatus{}
3166+
config := new(DHCPRelayConfig)
3167+
if err := p.client.GetConfig(ctx, config); err != nil {
3168+
if errors.Is(err, gnmiext.ErrNil) {
3169+
return s, nil
3170+
}
3171+
return s, fmt.Errorf("dhcp relay: failed to get status: %w", err)
3172+
}
3173+
3174+
s.ConfiguredInterfaces = make([]string, 0, config.RelayIfList.Len())
3175+
for _, relay := range config.RelayIfList {
3176+
s.ConfiguredInterfaces = append(s.ConfiguredInterfaces, relay.ID)
3177+
}
3178+
3179+
return s, nil
3180+
}
3181+
31223182
func init() {
31233183
provider.Register("cisco-nxos-gnmi", NewProvider)
31243184
}

0 commit comments

Comments
 (0)