address illegal SR-IOV VF MTU configuration#213
Conversation
Signed-off-by: Masaharu Kanda <kanlkan.naklnak@gmail.com>
✅ Deploy Preview for dranet canceled.
|
There was a problem hiding this comment.
Pull request overview
This PR adds validation to prevent configuring an SR-IOV Virtual Function (VF) MTU larger than its parent Physical Function (PF) MTU, avoiding invalid network setups that can leave pods stuck during resource preparation.
Changes:
- Add sysfs helper(s) to resolve a VF’s parent PF interface name.
- Add unit tests for PF-name resolution via a temporary sysfs-like directory tree.
- Enforce VF MTU ≤ PF MTU during
NodePrepareResources/ claim preparation (rejecting invalid claims).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/inventory/sysfs.go | Adds PF interface lookup helper for a given VF using sysfs. |
| pkg/inventory/sysfs_test.go | Adds tests covering PF lookup success and failure scenarios. |
| pkg/driver/dra_hooks.go | Adds claim-time MTU validation for SR-IOV VFs against parent PF MTU. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // For SR-IOV VFs, check that the requested MTU does not exceed the parent PF's MTU. | ||
| // If it does, log an error and fail the Pod creation to avoid silent misconfiguration. | ||
| if deviceCfg.NetworkInterfaceConfigInPod.Interface.MTU != nil { | ||
| if pfName, err := inventory.GetPFInterfaceName(ifName); err == nil { | ||
| if pfLink, err := nlHandle.LinkByName(pfName); err == nil { | ||
| pfMTU := pfLink.Attrs().MTU | ||
| requestedMTU := int(*deviceCfg.NetworkInterfaceConfigInPod.Interface.MTU) | ||
| if requestedMTU > pfMTU { | ||
| klog.Errorf("requested MTU %d for SR-IOV VF %s exceeds parent PF %s MTU %d", | ||
| requestedMTU, ifName, pfName, pfMTU) | ||
| errorList = append(errorList, fmt.Errorf("requested MTU %d for SR-IOV VF %s exceeds parent PF %s MTU %d", | ||
| requestedMTU, ifName, pfName, pfMTU)) | ||
| continue | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I fix the behavior when an error happened for each branch of this validation. b4c5e84
| // For SR-IOV VFs, check that the requested MTU does not exceed the parent PF's MTU. | ||
| // If it does, log an error and fail the Pod creation to avoid silent misconfiguration. | ||
| if deviceCfg.NetworkInterfaceConfigInPod.Interface.MTU != nil { | ||
| if pfName, err := inventory.GetPFInterfaceName(ifName); err == nil { | ||
| if pfLink, err := nlHandle.LinkByName(pfName); err == nil { |
There was a problem hiding this comment.
I added an unit test for this validation. b4c5e84
Signed-off-by: Masaharu Kanda <kanlkan.naklnak@gmail.com>
|
The e2e IPv4 test failed, but it does not seem to be related to my changes. |
|
Try retest? (Edit: Doesn't work, tests don't use prow) /retest |
|
@gauravkghildiyal |
gauravkghildiyal
left a comment
There was a problem hiding this comment.
Thanks @kanlkan. Minor suggestions.
| if deviceCfg.NetworkInterfaceConfigInPod.Interface.MTU != nil { | ||
| pfName, err := inventory.GetPFInterfaceName(ifName) | ||
| if err != nil { | ||
| // Not an SR-IOV VF, or the parent PF cannot be determined. This is |
There was a problem hiding this comment.
Can we only perform the check if this is an actual VF? We have an isSriovVf function to check that.
There was a problem hiding this comment.
Thank you for your feedback. I've added that check. 5f8645a
| if err == nil { | ||
| t.Fatalf("validateVFMTU() expected error, got nil") | ||
| } | ||
| want := fmt.Sprintf("requested MTU %d for SR-IOV VF eth1 exceeds parent PF eth0 MTU %d", tc.requestedMTU, tc.pfMTU) |
There was a problem hiding this comment.
nit: valudateVFMTU is a simple function with only one single kind of error. Let's not try to unnecessarily validate the return string. We can simplify the logic to check if err != tc.WantErr
There was a problem hiding this comment.
Thank you for your feedback. I simplyfied the test. 5f8645a
|
Please also add a release note |
Signed-off-by: Masaharu Kanda <kanlkan.naklnak@gmail.com>
|
@kanlkan Please remember a release note as well :) (Unhold once done) /lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: gauravkghildiyal, kanlkan, tamilmani1989 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@gauravkghildiyal |
|
/unhold |
What type of PR is this?
/kind feature
What this PR does / why we need it:
MTU can be configured via opaque.parameters.interface.mtu.
However, for SR-IOV VFs, it is currently possible to set an MTU larger than the parent PF’s MTU due to the lack of validation.
Which issue(s) this PR is related to:
Fixes #178
Special notes for your reviewer:
The example output below shows the case where validation fails. An error is logged, and the Pod remains in the ContainerCreating state.
Does this PR introduce a user-facing change?