plugins/vrf: make DEL idempotent when the device is already gone - #1282
Open
bgly wants to merge 1 commit into
Open
plugins/vrf: make DEL idempotent when the device is already gone#1282bgly wants to merge 1 commit into
bgly wants to merge 1 commit into
Conversation
During concurrent pod-netns teardown the VRF can be removed between findVRF and LinkDel, so LinkDel(vrf) returns ENODEV. cmdDel propagated that error and (under Multus/libcni) aborted the conflist DEL before the chained macvlan DEL ran, orphaning the interface and leaking its netns. resetMaster had the same problem when the enslaved interface was already gone, and additionally masked the underlying error by not wrapping it. Per the CNI SPEC, DEL is best-effort and must not fail when a resource has already been removed. Treat "link not found" as success on both LinkDel and resetMaster, matching by errno (ENODEV/ENOENT) as well as the typed LinkNotFoundError -- LinkDel returns a bare errno, so a type-only check misses it. Also switch the existing findVRF guard to the shared helper and wrap resetMaster errors with %w. Signed-off-by: Bryant Ly <bly@coreweave.com>
Author
|
@squeed Can you possibly review or someone? This is live in production that we reproduced / fixing with a shim. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the
vrfmeta plugin'scmdDelidempotent, as the CNI SPEC requires DELto be best-effort ("plugins should generally complete a DEL action without error
even if some resources are missing").
Problem
During concurrent netns teardown the VRF can be removed between
findVRFandLinkDel, sonetlink.LinkDel(vrf)returns a bareENODEVandcmdDelpropagated it.
resetMasterhad the same problem when the enslaved interfacewas already gone (and dropped the underlying error by not wrapping it).
When
vrfis used in a conflist (e.g.macvlan+vrf, as Multus generates),a plugin error aborts the remaining reverse-order DELs in the runtime (libcni
DelNetworkList), so the chainedmacvlanDEL never runs. The orphanedinterface pins its netns via its
dev_netreference and the namespace leaks; atscale this exhausts the kernel namespace limit and new pods fail with
failed to create network namespace: resource temporarily unavailable.cmdDelalready handles thefindVRF-not-found case andNSPathNotExistErr,but not
LinkDel/resetMaster. NoteLinkDelreturns a bare errno(
syscall.ENODEV), notnetlink.LinkNotFoundError, so the type-assertionguard used for
findVRFdoes not catch it.Changes
cmdDel: treatLinkDel(vrf)not-found as success; route the existingfindVRFguard through a shared helper.resetMaster: treatLinkByNamenot-found as success; wrap real errors with%w.linkNotFound()helper matchingnetlink.LinkNotFoundErroranderrors.Is(ENODEV/ENOENT).out-of-band.
Behaviour change
Only on the DEL error path: an already-removed VRF/interface now yields success
instead of an error. The happy path is unchanged. This mirrors the existing
NSPathNotExistErrhandling.Testing
go build/go vet/ test-binary compile clean; added a unit test coveringresetMaster/findVRFidempotency. TheLinkDel-ENODEVpath is inherently arace (VRF removed mid-
cmdDel); it was validated out-of-tree by driving amacvlan+vrfconflist through libcni with the race window forceddeterministically: 8/8 leaked without this change, 0/8 with it.