feat: custom DHCP relay source interface#1348
Conversation
|
🚀 Temp artifacts published: |
006df36 to
06251f1
Compare
|
🚀 Temp artifacts published: |
06251f1 to
6a101c6
Compare
|
🚀 Temp artifacts published: |
6a101c6 to
4e15df5
Compare
|
🚀 Temp artifacts published: |
4e15df5 to
60d874c
Compare
|
🚀 Temp artifacts published: |
Signed-off-by: Emanuele Di Pascale <emanuele@githedgehog.com>
60d874c to
6a98cd9
Compare
|
🚀 Temp artifacts published: |
|
@Frostman this appears to work fine now, in that I see the DHCP packets sent to a server in another VPC. However we should probably decide what exactly the user should be able to configure when using DHCP relay, e.g.:
|
There was a problem hiding this comment.
Pull request overview
Adds support for selecting a DHCP relay “source VRF” (via a referenced VPC) when configuring DHCP relay behavior, plumbing this through the VPC API → agent planning → BCM OpenConfig rendering, and documenting/exposing the new field in CRDs.
Changes:
- Add
relayVPCtoVPCDHCP(API + CRDs + docs) and validate its usage/existence. - Extend dozer DHCP relay spec with an optional
vrfand render/unmarshal it in BCM OpenConfig DHCP relay config. - Update BCM planning to omit the relay source interface for non-control-plane relay, and optionally set relay VRF derived from
relayVPC.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/agent/dozer/dozer.go | Extends internal dozer DHCP relay spec with optional VRF. |
| pkg/agent/dozer/bcm/spec_dhcp.go | Plumbs new VRF field into OpenConfig marshal/unmarshal for DHCP relay. |
| pkg/agent/dozer/bcm/plan.go | Sets relay source interface conditionally and derives relay VRF from relayVPC. |
| api/vpc/v1beta1/vpc_types.go | Adds relayVPC to the API and validates correct usage + referenced VPC existence. |
| config/crd/bases/vpc.githedgehog.com_vpcs.yaml | Exposes relayVPC in the VPC CRD schema. |
| config/crd/bases/agent.githedgehog.com_agents.yaml | Exposes relayVPC in the Agent CRD schema (embedded VPC DHCP config). |
| docs/api.md | Documents the new relayVPC field in VPCDHCP. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if subnetCfg.DHCP.RelayVPC != "" { | ||
| relayVPC := &VPC{} | ||
| err := kube.Get(ctx, ktypes.NamespacedName{Name: subnetCfg.DHCP.RelayVPC, Namespace: vpc.Namespace}, relayVPC) | ||
| if err != nil { | ||
| if kapierrors.IsNotFound(err) { | ||
| return nil, errors.Errorf("subnet %s: dhcp relay VPC %s not found", subnetName, subnetCfg.DHCP.RelayVPC) | ||
| } | ||
|
|
||
| return nil, errors.Wrapf(err, "subnet %s: failed to get dhcp relay VPC %s", subnetName, subnetCfg.DHCP.RelayVPC) // TODO replace with some internal error to not expose to the user | ||
| } |
There was a problem hiding this comment.
New RelayVPC validation branches are added (rejecting relayVPC without relay, and verifying the referenced VPC exists via kube.Get), but there are currently no unit tests covering VPC.Validate. Since this package already uses fake-client validation tests for other resources, consider adding tests to cover the new RelayVPC cases (missing relay, not-found VPC, success path).
| return errors.Wrapf(err, "failed to parse DHCP relay %s for vpc %s", subnet.DHCP.Relay, vpcName) | ||
| } | ||
| if subnet.DHCP.RelayVPC != "" { | ||
| relayVRF = pointer.To(vpcVrfName(subnet.DHCP.RelayVPC)) |
There was a problem hiding this comment.
When RelayVPC is set, the plan derives a relay VRF name but doesn't verify that VRF is actually present in spec.VRFs for this agent. If the relay VPC isn't configured on this switch, this can generate a DHCP relay config that references a non-existent VRF and fail during apply. Consider validating spec.VRFs[vpcVrfName(subnet.DHCP.RelayVPC)] exists (similar to the static external WithinVPC check) or ensuring the relay VPC VRF is planned on-demand.
| relayVRF = pointer.To(vpcVrfName(subnet.DHCP.RelayVPC)) | |
| relayVRFName := vpcVrfName(subnet.DHCP.RelayVPC) | |
| if _, ok := spec.VRFs[relayVRFName]; !ok { | |
| return errors.Errorf("DHCP relay VPC %s is not configured on this switch (missing VRF %s)", subnet.DHCP.RelayVPC, relayVRFName) | |
| } | |
| relayVRF = pointer.To(relayVRFName) |
| return errors.Wrapf(err, "failed to parse DHCP relay %s for vpc %s", subnet.DHCP.Relay, vpcName) | ||
| } | ||
| if subnet.DHCP.RelayVPC != "" { | ||
| relayVRF = pointer.To(vpcVrfName(subnet.DHCP.RelayVPC)) |
There was a problem hiding this comment.
Same issue as above in the L3Flat planning path: RelayVPC-derived VRF is used without checking that the VRF exists in spec.VRFs for this agent, which can yield invalid relay-agent config if the relay VPC isn't otherwise planned on this switch. Add a presence check (or plan the VRF) before setting relayVRF.
| relayVRF = pointer.To(vpcVrfName(subnet.DHCP.RelayVPC)) | |
| vrfName := vpcVrfName(subnet.DHCP.RelayVPC) | |
| if _, ok := spec.VRFs[vrfName]; ok { | |
| relayVRF = pointer.To(vrfName) | |
| } else { | |
| slog.Warn("DHCP relay VRF not found in spec.VRFs; skipping relayVRF assignment", | |
| "vpc", vpcName, | |
| "subnet", subnetName, | |
| "relayVPC", subnet.DHCP.RelayVPC, | |
| "vrf", vrfName, | |
| ) | |
| } |
link/vrf-select is just extra metadata on the request, so it should be fine |
from the broadcom user guide, that shouldn't matter:
So the request will have the SAG address of the VPC, as confirmed by my testing: |
No description provided.