Skip to content

ipvs: propagate errors during netlink initialization, and remove logrus dependency - #52

Open
thaJeztah wants to merge 2 commits into
moby:mainfrom
thaJeztah:cleanup_init
Open

thaJeztah wants to merge 2 commits into
moby:mainfrom
thaJeztah:cleanup_init

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

ipvs: only close namespace handles when opened

Only defer closing the network namespace handle when GetFromPath
succeeds. Avoid calling Close on the invalid handle returned by
netns.None when using the current network namespace.

ipvs: propagate errors during netlink initialization

Replace the global IPVS family ID and sync.Once with sync.OnceValues
to cache both the family ID and initialization error.

Try discovering the IPVS generic-netlink family before attempting
modprobe. Linux 5.17 and newer support automatic module loading,
but older kernels may still require explicit module loading.

Keep modprobe as a best-effort fallback and retry discovery afterward.
Only report module-loading errors if discovery also fails, preserving
both errors to help diagnose initialization failures.

Return initialization errors instead of logging them, removing the
dependency on logrus.

Only defer closing the network namespace handle when GetFromPath
succeeds. Avoid calling Close on the invalid handle returned by
netns.None when using the current network namespace.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Replace the global IPVS family ID and sync.Once with sync.OnceValues
to cache both the family ID and initialization error.

Try discovering the IPVS generic-netlink family before attempting
modprobe. Linux 5.17 and newer support automatic module loading,
but older kernels may still require explicit module loading.

Keep modprobe as a best-effort fallback and retry discovery afterward.
Only report module-loading errors if discovery also fails, preserving
both errors to help diagnose initialization failures.

Return initialization errors instead of logging them, removing the
dependency on logrus.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztah marked this pull request as ready for review October 15, 2026 20:53
@thaJeztah
thaJeztah requested a balanced review from Copilot October 15, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Failed module-loading diagnostics are discarded, and initialization failure paths lack regression coverage.

2 open findings
What changed in this PR

Updates IPVS netlink initialization to return errors to callers and removes its logging dependency.

Changes:

  • Caches family discovery results and errors, with best-effort module-loading fallback.
  • Closes namespace handles only when explicitly opened.
  • Removes logrus and unused dependency checksums.
File Description
netlink_linux.go Reworks family discovery, caching, and module-loading fallback.
ipvs_linux.go Returns initialization errors and guards namespace cleanup.
go.sum Removes unused dependency checksums.
go.mod Removes logrus dependency.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread netlink_linux.go
}
// ipvsFamily lazily discovers and caches the IPVS generic-netlink family ID
// and any initialization error.
var ipvsFamily = sync.OnceValues(func() (int, error) {
Comment thread netlink_linux.go
Comment on lines +81 to +86
_, _ = exec.Command("modprobe", "-va", "ip_vs").CombinedOutput()

family, err = getIPVSFamily()
if err != nil {
return 0, fmt.Errorf("get IPVS generic-netlink family: %w", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants