Commit graph

517 commits

Author SHA1 Message Date
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
Brad Davidson
1f2f610b5a Remove flannel external-ip annotations when disabled
Some checks are pending
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2026-01-07 11:58:56 -08:00
Brad Davidson
fc506e56dd lint: unnecessary-format,use-errors-new
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
c1f02b8b19 lint: identical-switch-branches
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
46c7ade9e9 lint: unexported-naming
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
83feb3c31d lint: superfluous-else
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
291086171b lint: redefines-builtin-id
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
26b4f21479 lint: indent-error-flow
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
4d1ad3d595 lint: import-alias-naming
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
d8af4f162a lint: if-return
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
7c7e442be0 lint: empty-lines
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
100cb633a3 lint: duplicated-imports
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
23093122b0 lint: defer,get-return
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
1227f2c435 lint: bool-literal-in-expr
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
55f8d9f731 lint: bare-return
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
5bf4dc7548 lint: comment-spacings
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
d9c4adc4cd lint: dot-imports
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
eee8234720 lint: use-any
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
316464975e lint: redundant-build-tag
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-18 11:20:07 -08:00
Brad Davidson
d582a0da84 Reorganize flannel consts and fields
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-08 12:53:10 -08:00
Brad Davidson
57210b87cc Use patch helper for node labels and annotations
Move flannel annotations into flannel setup, and use patch helpers to manage other node labels and annotations

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-08 12:53:10 -08:00
Brad Davidson
efcf8eb7ac Move embedded flannel and vpn config setup into embedded executor
Flannel and VPN setup shouldn't be done in generic agent config as it is only
used with embeded executor's flannel CNI.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-08 12:53:10 -08:00
Brad Davidson
ec3cc04214 Move CNI execution into executor
Allows properly delegating CNI startup to executor, so that it can be plugged in as platform and distro specific implimentation without relying on cli flag hacks

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-12-08 12:53:10 -08:00
Brad Davidson
1037dcbff4 Add digests and source labels for imported images
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-11-21 09:25:00 -08:00
Roberto Bonafiglia
3530ab5915 Fix tailscale setup in case of an already running configuration
Some checks are pending
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Signed-off-by: Roberto Bonafiglia <roberto.bonafiglia@suse.com>
2025-11-11 12:58:21 +01:00
Brad Davidson
171644cf0c Replace raw ListWatch with NewListWatchFromClient
NewListWatchFromClient replaces a bunch of boilerplate, and is also context-aware

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-10-27 15:06:45 -07:00
Roberto Bonafiglia
09762a57df Update flannel, kube-router and cni plugins
Signed-off-by: Roberto Bonafiglia <roberto.bonafiglia@suse.com>
2025-10-08 09:31:31 +02:00
Brad Davidson
4974fc7c24 Use sync.WaitGroup to avoid exiting before components have shut down
Currently only waits on etcd and kine, as other components
are stateless and do not need to shut down cleanly.

Terminal but non-fatal errors now request shutdown via context
cancellation, instead of just logging a fatal error.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-09-17 09:37:08 -07:00
Brad Davidson
a7d3c8559f Fix IPv6 handling for loadbalancer addresses
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-09-16 11:04:22 -07:00
Brad Davidson
7e253dbf02 Fix netpol fatal error when changing node IP
Wait for updated ready condition before starting netpol controller, to ensure that node IPs have been updated following a restart. The current checks only ensure that the taint is removed, which works for the initial join - but does not handle changing node IPs on restarts.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-09-10 10:27:52 -07:00
Michael Fritch
f248751dbd
make format 2025-09-04 14:41:58 -06:00
Brad Davidson
e47c497a3e Bump containerd to v2.1.4
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-08-26 10:15:38 -07:00
Brad Davidson
356bd5d298 Fix spegel logging and startup sequence
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-08-25 11:02:30 -07:00
Brad Davidson
6ab8b424dd Wire cri-dockerd --log-level=debug up to k3s --debug flag
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-08-22 10:23:30 -07:00
Brad Davidson
3bae735fb5 Fix --docker with --container-runtime-endpoint
The container runtime endpoint value is passed into cri-dockerd as the docker socket address, so we need to check for --docker BEFORE checking for non-nil --container-runtime-endpoint.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-08-01 13:54:46 -07:00
Brad Davidson
fb222e9a68 Fix fallback DNS for IMDS and IPV6-only
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-08-01 11:18:06 -07:00
Brad Davidson
3a428ff02c Update metric help to be more descriptive.
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-07-17 11:24:17 -07:00
Roberto Bonafiglia
573da0d41c Update network components
Signed-off-by: Roberto Bonafiglia <roberto.bonafiglia@suse.com>
2025-06-16 16:04:25 +02:00
Brad Davidson
db5390511e Switch from endpoints to endpointslices
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-06-09 11:28:02 -07:00
Richard Hansen
925726c84d flannel: Use custom type for network mode (IPv4, IPv6, dual-stack)
Move the `ipv4` and `ipv6` constants to their own constant
declaration.  This ensures that the `iota` expression for the `ipv4`
constant evaluates to 0, not some arbitrary value.  (`iota` evaluates
to N for the Nth constant in the constant declaration; see
<https://go.dev/ref/spec#Iota>.)  This is also more idiomatic, which
improves readability.

Also switch from incremental integers to bit flags, and use bitwise
operators for checking.  This is more idiomatic (the integer is
treated like a set of booleans), it avoids some code duplication, and
it is necessary to avoid ambiguity.  Consider the following:

    const (
    	ipv4 = iota
    	ipv6
    )

In the above, `ipv4` would have the value 0 and `ipv6` would have the
value 1.  This would make it impossible to distinguish an IPv6-only
stack from a dual-stack configuration because `ipv6` would equal
`ipv4 + ipv6`.  With bit flags this problem doesn't exist.

And put the integer holding the bit flags in a custom type with
convenience methods to improve readability.

Signed-off-by: Richard Hansen <rhansen@rhansen.org>
2025-05-09 12:51:48 -07:00
Brad Davidson
67291090ca Add support for conditional image tarball imports
Normally K3s will import all tarballs in the image dir on startup, and
re-import any tarballs that change while it is running.

This change allows users to opt into only importing tarballs that have
changed since they were last imported, even across restarts.

This behavior is opted into by touching a `.cache.json` file in the
images dir. This file is used to track the size and mtime of the image
files when they are imported.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-05-07 15:06:14 -07:00
Brad Davidson
b8a705d9c2 Fix handler panic when bootstrapper returned empty peer list
Panic gets rescued by the http server, and was only visible when running in debug mode, but should be handled properly.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-04-18 10:20:15 -07:00
Brad Davidson
3f7e6a30ce Move delegating auth middleware into common package and add MaxInFlight
Adds maximum in-flight request limits to agent join and p2p peer info
request request handlers.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-04-17 14:20:39 -07:00
Brad Davidson
f5b0d7884f Fix windows socket prefix
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-04-09 09:25:43 -07:00
Brad Davidson
ee036f7bc9 Fix issue caused by default authorization-mode apiserver arg
Move arg-parsing helper functions into util, and use them to see if the user has set an authorization-config flag - and do not set authorization-mode if so.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-03-31 17:09:43 -07:00
Brad Davidson
a8bc412422 Move container runtime ready channel into executor
Move the container runtime ready channel into the executor interface, instead of passing it awkwardly between server and agent config structs

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-03-24 12:42:29 -07:00
Brad Davidson
529e748ac7 Move apiserver ready wait into common channel
Splits server startup into prepare/start phases. Server's agent is now
started after server is prepared, but before it is started. This allows
us to properly bootstrap the executor before starting server components,
and use the executor to provide a shared channel to wait on apiserver
readiness.

This allows us to replace four separate callers of WaitForAPIServerReady
with reads from a common ready channel.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-03-24 12:42:29 -07:00
Brad Davidson
c11c06cad4 Add context to agent token validation error
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-03-24 12:42:29 -07:00
Derek Nola
ac38633c71
Migrate to UrfaveCLI v2 (#11831)
* Bump rootlesskit tov 1.1.1, last of the v1 line
* Migrate to urfavecli v2
* Disable StringSlice seperattion

Signed-off-by: Derek Nola <derek.nola@suse.com>
2025-03-12 09:02:45 -07:00
Brad Davidson
781640ecea Fix syncing empty list of apiserver addresses during initial startup
Also add more debug logging to the sync process.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-03-11 14:49:45 -07:00