Skip to content

Cannot disable leader election in fleet-agent #4493

@webD97

Description

@webD97

Is there an existing issue for this?

  • I have searched the existing issues

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

  1. Build the fleet-agent binary
  2. Run with "--help"
  3. 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.

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Bug.

Projects

Status

✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions