Is there an existing issue for this?
Current Behavior
I am currently experimenting with bootstrapping fleet-agent without a CNI installed. Running the agent in hostNetwork mode with appropriate tolerations allows it to start but leader election fails because it cannot reach the apiserver without a CNI (error retrieving resource lock fleet-system/fleet-agent: Get "https://<redacted>:443/apis/coordination.k8s.io/v1/namespaces/fleet-system/leases/fleet-agent": dial tcp <redacted>:443: i/o timeout - where <redacted> is the cluster-internal apiserver IP).
No CLI argument or env variable is exposed to disable leader election, despite #3891 suggesting this:
Usage:
fleet-agent [flags]
Flags:
--agent-scope string An identifier used to scope the agent bundleID names, typically the same as namespace
--checkin-interval string How often to post cluster status
--debug Turn on debug logging
--debug-level int If debugging is enabled, set klog -v=X
-h, --help help for fleet-agent
--kubeconfig string Paths to a kubeconfig. Only required if out-of-cluster.
--namespace string system namespace is the namespace, the agent runs in, e.g. cattle-fleet-system
-v, --version version for fleet-agent
--zap-devel Development Mode defaults(encoder=consoleEncoder,logLevel=Debug,stackTraceLevel=Warn). Production Mode defaults(encoder=jsonEncoder,logLevel=Info,stackTraceLevel=Error) (default true)
--zap-encoder encoder Zap log encoding (one of 'json' or 'console')
--zap-log-level level Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error', 'panic'or any integer value > 0 which corresponds to custom debug levels of increasing verbosity
--zap-stacktrace-level level Zap Level at and above which stacktraces are captured (one of 'info', 'error', 'panic').
--zap-time-encoding time-encoding Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano'). Defaults to 'epoch'.
Expected Behavior
There is a CLI argument and an env variable to disable leader election.
Steps To Reproduce
- Build the fleet-agent binary
- Run with "--help"
- Observe that no such option exists
Environment
- Architecture: amd64
- Fleet Version: latest commit on main
- Cluster:
- Provider: k3s (on agent cluster)
- Options: no customizations
- Kubernetes Version: 1.34.1
Logs
Error: unknown flag: --leader-elect
Usage:
fleet-agent [flags]
Flags:
--agent-scope string An identifier used to scope the agent bundleID names, typically the same as namespace
--checkin-interval string How often to post cluster status
--debug Turn on debug logging
--debug-level int If debugging is enabled, set klog -v=X
-h, --help help for fleet-agent
--kubeconfig string Paths to a kubeconfig. Only required if out-of-cluster.
--namespace string system namespace is the namespace, the agent runs in, e.g. cattle-fleet-system
-v, --version version for fleet-agent
--zap-devel Development Mode defaults(encoder=consoleEncoder,logLevel=Debug,stackTraceLevel=Warn). Production Mode defaults(encoder=jsonEncoder,logLevel=Info,stackTraceLevel=Error) (default true)
--zap-encoder encoder Zap log encoding (one of 'json' or 'console')
--zap-log-level level Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error', 'panic'or any integer value > 0 which corresponds to custom debug levels of increasing verbosity
--zap-stacktrace-level level Zap Level at and above which stacktraces are captured (one of 'info', 'error', 'panic').
--zap-time-encoding time-encoding Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano'). Defaults to 'epoch'.
time="2026-01-06T09:12:15Z" level=fatal msg="unknown flag: --leader-elect"
Anything else?
Adding an env variable like env:"ENABLE_LEADER_ELECTION" in
|
EnableLeaderElection bool `name:"leader-elect" default:"true" usage:"Enable leader election for the agent. Enabling this will ensure there is only one active agent."` |
exposes the CLI argument and adds the option to configure this via this variable.
I will gladly prepare a PR for this.
Is there an existing issue for this?
Current Behavior
I am currently experimenting with bootstrapping fleet-agent without a CNI installed. Running the agent in hostNetwork mode with appropriate tolerations allows it to start but leader election fails because it cannot reach the apiserver without a CNI (
error retrieving resource lock fleet-system/fleet-agent: Get "https://<redacted>:443/apis/coordination.k8s.io/v1/namespaces/fleet-system/leases/fleet-agent": dial tcp <redacted>:443: i/o timeout- where<redacted>is the cluster-internal apiserver IP).No CLI argument or env variable is exposed to disable leader election, despite #3891 suggesting this:
Expected Behavior
There is a CLI argument and an env variable to disable leader election.
Steps To Reproduce
Environment
Logs
Anything else?
Adding an env variable like
env:"ENABLE_LEADER_ELECTION"infleet/internal/cmd/agent/root.go
Line 37 in 42b4424
I will gladly prepare a PR for this.