k3s/pkg/agent
luojiyin f42523c55f Fix atomic write in WriteSubnetFile
- Use os.CreateTemp to avoid race conditions with fixed temp filename
   - Add f.Sync() before close to ensure data durability
   - Check all fmt.Fprintf errors instead of ignoring them
   - Preserve original file permissions when overwriting
   - Handle dir== edge case from filepath.Split
   - Check os.MkdirAll error
   - Proper cleanup on all error paths

Signed-off-by: luojiyin <luojiyin@hotmail.com>

Add documentation comments to WriteSubnetFile

   Clarify the design choices for atomic file writing:
   - Explain why CreateTemp is used (defense-in-depth, avoids pre-existing file issues)
   - Document the single-instance assumption
   - Note the permission preservation logic

Signed-off-by: luojiyin <luojiyin@hotmail.com>

Update WriteSubnetFile comment to clarify CreateTemp rationale

   Remove misleading reference to concurrent writes (K3s is single-instance).
   Focus on the actual benefits: avoiding stale temp files from crashes,
   handling unexpected permissions/ownership, and O_EXCL guarantees.

Signed-off-by: luojiyin <luojiyin@hotmail.com>

Refactor cleanup to use merr.NewErrors for better error aggregation

   Address review feedback from @brandond to improve error handling:
   - Change cleanup function to accept error parameter
   - Use merr.NewErrors to aggregate original error with Close/Remove errors
   - Simplify error handling with consistent return cleanup(err) pattern

Signed-off-by: luojiyin <luojiyin@hotmail.com>

Fix Close error handling to preserve original error

   Add cleanupNoClose helper to avoid double Close and preserve the
   original Close error when file close fails.

Signed-off-by: luojiyin <luojiyin@hotmail.com>
2026-01-08 11:37:41 -08:00
..
config lint: indent-error-flow 2025-12-18 11:20:07 -08:00
containerd lint: superfluous-else 2025-12-18 11:20:07 -08:00
cri lint: redundant-build-tag 2025-12-18 11:20:07 -08:00
cridockerd lint: redundant-build-tag 2025-12-18 11:20:07 -08:00
flannel Fix atomic write in WriteSubnetFile 2026-01-08 11:37:41 -08:00
https Fix handler panic when bootstrapper returned empty peer list 2025-04-18 10:20:15 -07:00
loadbalancer lint: unnecessary-format,use-errors-new 2025-12-18 11:20:07 -08:00
netpol lint: duplicated-imports 2025-12-18 11:20:07 -08:00
proxy lint: duplicated-imports 2025-12-18 11:20:07 -08:00
syssetup Load kernel modules for nft in agent setup (#11524) 2025-01-07 03:01:02 +02:00
templates lint: use-any 2025-12-18 11:20:07 -08:00
tunnel Replace raw ListWatch with NewListWatchFromClient 2025-10-27 15:06:45 -07:00
util Avoid use of github.com/pkg/errors functions that capture stack 2025-03-05 00:41:38 -08:00
run.go lint: unnecessary-format,use-errors-new 2025-12-18 11:20:07 -08:00
run_linux.go lint: redundant-build-tag 2025-12-18 11:20:07 -08:00
run_test.go Update to v1.31.0 2024-08-22 14:23:34 -07:00
run_windows.go lint: redundant-build-tag 2025-12-18 11:20:07 -08:00