diff --git a/changelog/fragments/1699010487-leaderelectionconfig.yaml b/changelog/fragments/1699010487-leaderelectionconfig.yaml new file mode 100644 index 00000000000..e965af360df --- /dev/null +++ b/changelog/fragments/1699010487-leaderelectionconfig.yaml @@ -0,0 +1,32 @@ +# Kind can be one of: +# - breaking-change: a change to previously-documented behavior +# - deprecation: functionality that is being removed in a later release +# - bug-fix: fixes a problem in a previous version +# - enhancement: extends functionality but does not break or fix existing behavior +# - feature: new functionality +# - known-issue: problems that we are aware of in a given version +# - security: impacts on the security of a product or a user’s deployment. +# - upgrade: important information for someone upgrading from a prior version +# - other: does not fit into any of the other categories +kind: enhancement + +# Change summary; a 80ish characters long description of the change. +summary: Added Kubernetes leader_election provider configuration parameters + +# Long description; in case the summary is not enough to describe the change +# this field accommodate a description without length limits. +# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. +#description: + +# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. +component: elastic-agent + +# PR URL; optional; the PR number that added the changeset. +# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. +# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. +# Please provide it if you are adding a fragment for a different PR. +#pr: https://github.com/owner/repo/1234 + +# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). +# If not present is automatically filled by the tooling with the issue linked to the PR number. +#issue: https://github.com/owner/repo/1234 diff --git a/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-daemonset-configmap.yaml b/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-daemonset-configmap.yaml index 3b8dd9464a7..9e9517435fc 100644 --- a/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-daemonset-configmap.yaml +++ b/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-daemonset-configmap.yaml @@ -35,7 +35,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -132,6 +132,21 @@ data: # bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token # ssl.certificate_authorities: # - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt + - data_stream: + dataset: kubernetes.state_namespace + type: metrics + metricsets: + - state_namespace + add_metadata: true + hosts: + - 'kube-state-metrics:8080' + period: 10s + # Openshift: + # if to access 'kube-state-metrics' are used third party tools, like kube-rbac-proxy or similar, that perform RBAC authorization + # and/or tls termination, then configuration below should be considered: + # bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + # ssl.certificate_authorities: + # - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt - data_stream: dataset: kubernetes.state_node type: metrics @@ -337,7 +352,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -365,7 +380,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -506,7 +521,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: diff --git a/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-ksm-daemonset-configmap.yaml b/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-ksm-daemonset-configmap.yaml index 4c2d09c9a25..8abe95421cb 100644 --- a/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-ksm-daemonset-configmap.yaml +++ b/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-ksm-daemonset-configmap.yaml @@ -36,7 +36,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -127,7 +127,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -152,7 +152,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -293,7 +293,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: diff --git a/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-ksm-statefulset-configmap.yaml b/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-ksm-statefulset-configmap.yaml index 2a97b864565..cf913c8ea7c 100644 --- a/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-ksm-statefulset-configmap.yaml +++ b/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/base/elastic-agent-standalone-ksm-statefulset-configmap.yaml @@ -80,6 +80,16 @@ data: - 'localhost:8080' period: 10s bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + - data_stream: + type: metrics + dataset: kubernetes.state_namespace + metricsets: + - state_namespace + add_metadata: true + hosts: + - 'localhost:8080' + period: 10s + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token - data_stream: type: metrics dataset: kubernetes.state_node @@ -173,4 +183,4 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 diff --git a/deploy/kubernetes/elastic-agent-kustomize/ksm-autosharding/elastic-agent-standalone/base/elastic-agent-standalone-ksm-daemonset-configmap.yaml b/deploy/kubernetes/elastic-agent-kustomize/ksm-autosharding/elastic-agent-standalone/base/elastic-agent-standalone-ksm-daemonset-configmap.yaml index 4c2d09c9a25..8abe95421cb 100644 --- a/deploy/kubernetes/elastic-agent-kustomize/ksm-autosharding/elastic-agent-standalone/base/elastic-agent-standalone-ksm-daemonset-configmap.yaml +++ b/deploy/kubernetes/elastic-agent-kustomize/ksm-autosharding/elastic-agent-standalone/base/elastic-agent-standalone-ksm-daemonset-configmap.yaml @@ -36,7 +36,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -127,7 +127,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -152,7 +152,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -293,7 +293,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: diff --git a/deploy/kubernetes/elastic-agent-kustomize/ksm-autosharding/elastic-agent-standalone/base/elastic-agent-standalone-ksm-statefulset-configmap.yaml b/deploy/kubernetes/elastic-agent-kustomize/ksm-autosharding/elastic-agent-standalone/base/elastic-agent-standalone-ksm-statefulset-configmap.yaml index 2a97b864565..cf913c8ea7c 100644 --- a/deploy/kubernetes/elastic-agent-kustomize/ksm-autosharding/elastic-agent-standalone/base/elastic-agent-standalone-ksm-statefulset-configmap.yaml +++ b/deploy/kubernetes/elastic-agent-kustomize/ksm-autosharding/elastic-agent-standalone/base/elastic-agent-standalone-ksm-statefulset-configmap.yaml @@ -80,6 +80,16 @@ data: - 'localhost:8080' period: 10s bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + - data_stream: + type: metrics + dataset: kubernetes.state_namespace + metricsets: + - state_namespace + add_metadata: true + hosts: + - 'localhost:8080' + period: 10s + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token - data_stream: type: metrics dataset: kubernetes.state_node @@ -173,4 +183,4 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 diff --git a/deploy/kubernetes/elastic-agent-standalone-kubernetes.yaml b/deploy/kubernetes/elastic-agent-standalone-kubernetes.yaml index 125936a37b3..1aee9d7a74c 100644 --- a/deploy/kubernetes/elastic-agent-standalone-kubernetes.yaml +++ b/deploy/kubernetes/elastic-agent-standalone-kubernetes.yaml @@ -35,7 +35,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -132,6 +132,21 @@ data: # bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token # ssl.certificate_authorities: # - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt + - data_stream: + dataset: kubernetes.state_namespace + type: metrics + metricsets: + - state_namespace + add_metadata: true + hosts: + - 'kube-state-metrics:8080' + period: 10s + # Openshift: + # if to access 'kube-state-metrics' are used third party tools, like kube-rbac-proxy or similar, that perform RBAC authorization + # and/or tls termination, then configuration below should be considered: + # bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + # ssl.certificate_authorities: + # - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt - data_stream: dataset: kubernetes.state_node type: metrics @@ -337,7 +352,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -365,7 +380,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -506,7 +521,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: diff --git a/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-daemonset-configmap.yaml b/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-daemonset-configmap.yaml index 3b8dd9464a7..9e9517435fc 100644 --- a/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-daemonset-configmap.yaml +++ b/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-daemonset-configmap.yaml @@ -35,7 +35,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -132,6 +132,21 @@ data: # bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token # ssl.certificate_authorities: # - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt + - data_stream: + dataset: kubernetes.state_namespace + type: metrics + metricsets: + - state_namespace + add_metadata: true + hosts: + - 'kube-state-metrics:8080' + period: 10s + # Openshift: + # if to access 'kube-state-metrics' are used third party tools, like kube-rbac-proxy or similar, that perform RBAC authorization + # and/or tls termination, then configuration below should be considered: + # bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + # ssl.certificate_authorities: + # - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt - data_stream: dataset: kubernetes.state_node type: metrics @@ -337,7 +352,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -365,7 +380,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: @@ -506,7 +521,7 @@ data: meta: package: name: kubernetes - version: 1.29.2 + version: 1.52.0 data_stream: namespace: default streams: diff --git a/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-ksm-daemonset-configmap.yaml b/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-ksm-daemonset-configmap.yaml index 4c2d09c9a25..8abe95421cb 100644 --- a/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-ksm-daemonset-configmap.yaml +++ b/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-ksm-daemonset-configmap.yaml @@ -36,7 +36,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -127,7 +127,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -152,7 +152,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: @@ -293,7 +293,7 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 data_stream: namespace: default streams: diff --git a/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-ksm-statefulset-configmap.yaml b/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-ksm-statefulset-configmap.yaml index 2a97b864565..cf913c8ea7c 100644 --- a/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-ksm-statefulset-configmap.yaml +++ b/deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-ksm-statefulset-configmap.yaml @@ -80,6 +80,16 @@ data: - 'localhost:8080' period: 10s bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token + - data_stream: + type: metrics + dataset: kubernetes.state_namespace + metricsets: + - state_namespace + add_metadata: true + hosts: + - 'localhost:8080' + period: 10s + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token - data_stream: type: metrics dataset: kubernetes.state_node @@ -173,4 +183,4 @@ data: meta: package: name: kubernetes - version: 1.42.0 + version: 1.52.0 diff --git a/internal/pkg/composable/providers/kubernetesleaderelection/config.go b/internal/pkg/composable/providers/kubernetesleaderelection/config.go index 7ccc2f9a799..7988fcd6fc2 100644 --- a/internal/pkg/composable/providers/kubernetesleaderelection/config.go +++ b/internal/pkg/composable/providers/kubernetesleaderelection/config.go @@ -13,10 +13,18 @@ type Config struct { // Name of the leaderelection lease LeaderLease string `config:"leader_lease"` + //Parameters to configure election process + LeaseDuration int `config:"leader_leaseduration"` + RenewDeadline int `config:"leader_renewdeadline"` + RetryPeriod int `config:"leader_retryperiod"` + KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"` } // InitDefaults initializes the default values for the config. func (c *Config) InitDefaults() { c.LeaderLease = "elastic-agent-cluster-leader" + c.LeaseDuration = 15 + c.RenewDeadline = 10 + c.RetryPeriod = 2 } diff --git a/internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go b/internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go index b1388005ab7..c32b57d78c8 100644 --- a/internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go +++ b/internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go @@ -83,12 +83,13 @@ func (p *contextProvider) Run(ctx context.Context, comm corecomp.ContextProvider }, }, ReleaseOnCancel: true, - LeaseDuration: 15 * time.Second, - RenewDeadline: 10 * time.Second, - RetryPeriod: 2 * time.Second, + LeaseDuration: time.Duration(p.config.LeaseDuration) * time.Second, + RenewDeadline: time.Duration(p.config.RenewDeadline) * time.Second, + RetryPeriod: time.Duration(p.config.RetryPeriod) * time.Second, Callbacks: leaderelection.LeaderCallbacks{ OnStartedLeading: func(ctx context.Context) { p.logger.Debugf("leader election lock GAINED, id %v", id) + p.logger.Debugf("leader configuration timings: LeaseDuration: %v , RenewDeadline: %v, RetryPeriod: %v", p.leaderElection.LeaseDuration, p.leaderElection.RenewDeadline, p.leaderElection.RetryPeriod) p.startLeading(comm) }, OnStoppedLeading: func() {