Skip to content

feat(metis): fallback CNI to direct local IPAM when daemon is unavailable - #1283

Open
arvindbr8 wants to merge 7 commits into
kubernetes:masterfrom
arvindbr8:feature/cni-direct-fallback-retry
Open

feat(metis): fallback CNI to direct local IPAM when daemon is unavailable#1283
arvindbr8 wants to merge 7 commits into
kubernetes:masterfrom
arvindbr8:feature/cni-direct-fallback-retry

Conversation

@arvindbr8

@arvindbr8 arvindbr8 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR implements socket connection retry logic and direct local IPAM fallback in the Metis CNI plugin when the background daemon process is unavailable or starting up.

  • Socket Availability Check & Connection Retries:
    • Adds socket file availability verification (os.Stat) prior to gRPC client initialization in getGrpcClient to prevent lazy gRPC connection false-positives.
    • Adds 3 connection retries with 100ms backoff in prepare() to gracefully handle transient daemon restarts or startup timing.
  • Direct Local IPAM Fallback:
    • If the daemon socket remains unavailable after retries, the CNI plugin falls back to opening the SQLite store directly at dbPath (/var/lib/cni/metis/metis.sqlite) and instantiating IPAMEngine in-process via directClientAdapter.
    • Operates without initializing network/UDS listeners, gRPC servers, or background sync tasks.
    • Built-in default behavior without extra configuration knobs.

Operational & Safety Details

  • SQLite Write-Ahead Logging (WAL), _busy_timeout=5000ms, and _txlock=immediate ensure transaction isolation and lock safety when CNI and Daemon concurrently access SQLite.
  • If local IP capacity is exhausted while operating in direct mode, IPAMEngine cleanly returns store.ErrNoAvailableIPs (since no daemon/monitor is present to trigger dynamic scale-up).

Test Plan

  • Unit Tests:
    • go test ./... in metis/ (ok k8s.io/metis/pkg/cni, ok k8s.io/metis/pkg/daemon, ok k8s.io/metis/pkg/store).
  • Integration Tests:
    • Executed metis/test/daemon_cni_race_test.go covering deterministic startup sequences:
      • TestCNI_SequenceA_CNIBeforeDaemon: CNI runs before daemon exists -> direct fallback -> daemon starts -> daemon handles subsequent requests cleanly.
      • TestCNI_SequenceB_SocketAppearsDuringRetry: Daemon socket creation delayed by 150ms -> CNI retries socket -> connects via gRPC on attempt 2.
      • TestCNI_SequenceC_DaemonAlreadyRunning: CNI connects immediately to running daemon.
  • Verification:
    • make verify-up-to-date passed with 0 dirty changes.

@kubernetes-prow kubernetes-prow Bot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jul 30, 2026
@kubernetes-prow

Copy link
Copy Markdown

This issue is currently awaiting triage.

If the repository mantainers determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 30, 2026
@arvindbr8

Copy link
Copy Markdown
Contributor Author

/assign @YifeiZhuang

@kubernetes-prow

Copy link
Copy Markdown

Hi @arvindbr8. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 30, 2026
@kubernetes-prow kubernetes-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 30, 2026
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: arvindbr8
Once this PR has been reviewed and has the lgtm label, please ask for approval from yifeizhuang. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@YifeiZhuang

Copy link
Copy Markdown
Contributor

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 3, 2026
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants