diff --git a/deploy/helm/elastic-agent/examples/fleet-managed/rendered/manifest.yaml b/deploy/helm/elastic-agent/examples/fleet-managed/rendered/manifest.yaml index d6250acbc1..b2ec54b123 100644 --- a/deploy/helm/elastic-agent/examples/fleet-managed/rendered/manifest.yaml +++ b/deploy/helm/elastic-agent/examples/fleet-managed/rendered/manifest.yaml @@ -32,7 +32,7 @@ stringData: node: ${NODE_NAME} scope: node kubernetes_leaderelection: - enabled: false + enabled: true leader_lease: example-pernode --- # Source: elastic-agent/templates/agent/cluster-role.yaml @@ -154,7 +154,7 @@ spec: labels: name: agent-pernode-example annotations: - checksum/config: af3259ba23f68d99ef807759ff88472468ae32fe402c062fa164b19041d533c9 + checksum/config: cd7c5c4f03cc8377d18ee22cf236428090959fc194ee647bd97a39b79f38c807 spec: automountServiceAccountToken: true containers: diff --git a/deploy/helm/elastic-agent/templates/agent/_helpers.tpl b/deploy/helm/elastic-agent/templates/agent/_helpers.tpl index 39f59c7ce0..9832dea7b2 100644 --- a/deploy/helm/elastic-agent/templates/agent/_helpers.tpl +++ b/deploy/helm/elastic-agent/templates/agent/_helpers.tpl @@ -99,7 +99,6 @@ Validate and initialise the defined agent presets {{- end -}} {{- end -}} {{- end -}} -{{/* by default we disable leader election but we also set the name of the leader lease in case it is explicitly enabled */}} {{- if empty ($presetVal).providers -}} {{- $_ := set $presetVal "providers" dict -}} {{- end -}} @@ -108,7 +107,13 @@ Validate and initialise the defined agent presets {{- $_ := set $presetProviders "kubernetes_leaderelection" dict -}} {{- end -}} {{- $presetLeaderLeaseName := (printf "%s-%s" $.Release.Name $presetName) | lower -}} +{{/* by default we disable leader election but we also set the name of the leader lease in case it is explicitly enabled */}} {{- $defaultLeaderElection := dict "enabled" false "leader_lease" $presetLeaderLeaseName -}} +{{- if eq $.Values.agent.fleet.enabled true -}} +{{/* for fleet mode the leader election is enabled by default */}} +{{- $_ := set $defaultLeaderElection "enabled" true -}} +{{- end -}} +{{/* merge the default leader election with the leader election from the preset giving priority to the one from the preset */}} {{- $presetLeaderElection := mergeOverwrite dict $defaultLeaderElection ($presetProviders).kubernetes_leaderelection -}} {{- $_ := set $presetProviders "kubernetes_leaderelection" $presetLeaderElection -}} {{- end -}}