← Back to Pull requests

Fix nri lifecycle #426

Closed
unknown closed this pull request without merging on Dec 01, 2026 14:07 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 20:37 UTC
Author

What type of PR is this?

/kind bug

What this PR does / why we need it:

A pod must not get a sandbox while the container runtime does not have the DRANET NRI plugin. The runtime then creates the sandbox without the network interfaces, and nothing repairs it later. https://github.com/kubernetes-sigs/dranet/issues/424#issuecomment-7023862177 lists the ways in which this happened. This PR closes the ones that DRANET can close.

  • Start order. DRANET registered the DRA plugin first and connected the NRI plugin later. The kubelet can create the sandbox of a pod as soon as the DRA plugin is registered, and it does not call NodePrepareResources again for a claim that is already prepared. Now Start connects the NRI plugin first and starts the DRA plugin after that.

  • Restart of the container runtime. The NRI connection closes when containerd restarts. DRANET connected again 5 times with no delay and then exited. Now it keeps the same stub and connects again with an exponential backoff (1s to 16s). A successful connection resets the count of failures. DRANET still exits after 5 failures in sequence, because the stub of containerd/nri v0.12.5 cannot connect again after a failed registration.

  • Claims while NRI is not connected. PrepareResourceClaims rejects non-empty calls while the NRI plugin is not connected, so the kubelet does not prepare a new claim in that time.

  • Health checks. /healthz is the logical AND of two checks, and /healthz/dra and /healthz/nri report each one, in the style of the apiserver (?verbose, ?exclude=). The readiness probe now fails while the NRI plugin is not connected. driver.Start is split into driver.New and (*NetworkDriver).Start, so cmd/dranet registers the checks before the driver starts.
  • The state of the NRI connection is one variable, nriConnected. Only the loop that runs the stub writes it: it sets it when Start of the stub returns and clears it when Wait returns. The NRI hooks do not write it, because the close callback of the stub can run while a Synchronize call is still in progress.

    Tests:

  • Unit: the start order, with the real DRA kubelet plugin and a fake NRI stub; the backoff, the reset and the exit of the NRI loop; a restart of the runtime, with the real NRI stub and the NRI runtime adaptation; the check in PrepareResourceClaims; the health endpoints.

  • Integration (tests/integration, kind): TestNRILifecycleAndContainerdRestart stops and restarts containerd. It checks the health endpoints during the outage, that a pod created during the outage gets its interface after the runtime is back, and that DRANET keeps its PID.
  • Which issue(s) this PR is related to:

    Fixes #88
    Related to #424
    Related to #310

    Special notes for your reviewer:

    Known limit, in short. A pod can still start without its claimed interfaces if the runtime does not have the DRANET plugin at the moment that the kubelet creates the sandbox of a pod whose claims are already prepared. That needs a fault on the node at that moment:

  • DRANET is killed (OOM kill, SIGKILL). A graceful stop, for example an update of the DaemonSet, is safe.

  • The container runtime restarts.
  • In both cases something is wrong on the node, and the missing interface is the smaller problem. One cause is not a fault of the node: a panic in a DRANET hook. DRANET does not recover from a panic, so a bug there has the same effect as a kill.

    DRANET does not report such a pod in this PR, so the pod runs without the interfaces and nothing shows it. #427 adds the report: a Warning event on the Pod and a metric.

    The case that stays open. DRANET is down without a graceful shutdown (crash, OOM kill, SIGKILL), and in that time the kubelet creates a sandbox for a pod that has its claims already prepared. DRANET cannot close this case, because it is not running when it happens.

    How it happens:

    1. The kubelet marks a claim as prepared after NodePrepareResources. It does not call NodePrepareResources again for that pod. It only requires that the driver is registered.
    2. A process that is killed does not remove its registration socket, so the kubelet keeps the driver as registered.
    3. The kubelet creates the sandbox. The runtime does not have the DRANET NRI plugin, so the sandbox does not get the claimed interfaces. The containers start, and nothing repairs the pod later.

    It is unlikely, because it needs two things at the same time:

  • DRANET must stop without a graceful shutdown. A graceful stop, for example an update of the DaemonSet, is safe: Stop stops the DRA plugin first, that removes the registration socket, and the kubelet then refuses to create the sandbox (FailedPrepareDynamicResources).

  • While DRANET is down, a pod with a prepared claim must need a sandbox. That is a pod that was between NodePrepareResources and RunPodSandbox when DRANET stopped, or a running pod whose sandbox stops and is created again. A pod that is created later is safe: its NodePrepareResources call fails while DRANET is down.
  • Measured on the kind node of tests/integration:

  • In a normal pod start, the RunPodSandbox hook started 232 ms after the end of NodePrepareResources. A crash must be in this time, or the sandbox of a running pod must stop while DRANET is down.

  • After SIGKILL of DRANET, the registration socket stayed. The sandbox of a running pod was stopped, and the kubelet made a new sandbox after 1.3 s, with lo and eth0 only.

  • After SIGTERM of DRANET, the registration socket was removed. The sandbox of a running pod was stopped, and the kubelet made no new sandbox in 40 s.
  • To close this case needs a check in the runtime at RunPodSandbox (containerd/nri#142) or a DRA call after the sandbox exists.

    Two related limits:

  • The same result is possible when the container runtime restarts at the moment that a pod with a prepared claim has no sandbox. When the runtime is back, the kubelet can create the sandbox before DRANET connects again, and the wait between two connection attempts can be up to 16s. This one is not reproduced.

  • A runtime with NRI older than v0.12.4 does not have the failure policy of #401, so a request that times out is still skipped there (#310).
  • cc @gauravkghildiyal

    Does this PR introduce a user-facing change?

    ``release-note
    DRANET connects its NRI plugin before it registers its DRA plugin, connects again when the container runtime restarts instead of exiting, and rejects new claims while the NRI plugin is not connected.
    /healthz now also fails while the NRI plugin is not connected, and the new /healthz/dra and /healthz/nri endpoints report each check.

    Known limit: a pod can still start without its claimed network interfaces if DRANET is killed or panics, or if the container runtime restarts, at the moment that the kubelet creates the sandbox of the pod. A graceful stop of DRANET, for example an update, is safe.
    ``

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: npinaeva Review duration: 15449m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #426"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%