k8sleaderelector

package module
v0.121.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

Leader Elector Extension

Status
Stability development
Distributions []
Issues Open issues Closed issues
Code Owners @dmitryax, @rakesh-garimella

This extension enables OpenTelemetry components to run in HA mode across a Kubernetes cluster. The component that owns the lease becomes the leader and becomes the active instance.

How It Works

The extension uses k8s.io/client-go/tools/leaderelection to perform leader election. The component that owns the lease becomes the leader and runs the function defined in onStartedLeading. If the leader loses the lease, it runs the function defined in onStoppedLeading, stops its operation, and waits to acquire the lease again.

Configuration

receivers:
  my_awesome_receiver:
    leader_elector: k8s_leader_elector
extensions:
  k8s_leader_elector:
    auth_type: kubeConfig
    lease_name: foo
    lease_namespace: default

service:
  extensions: [k8s_leader_elector]
  pipelines:
    metrics:
      receivers: [my_awesome_receiver]
Leader Election Configuration
configuration description default value
auth_type Authorization type to be used (serviceAccount, kubeConfig). none (required)
lease_name The name of the lease object. none (required)
lease_namespace The namespace of the lease object. none (required)
lease_duration The duration of the lease. 15s
renew_deadline The deadline for renewing the lease. It must be less than the lease duration. 10s
retry_period The period for retrying the leader election. 2s
Suggested RBAC
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: my-lease
  namespace: default
rules:
- apiGroups:
  - coordination.k8s.io
  resources:
  - leases
  verbs:
  - get
  - list
  - watch
  - create
  - update
  - patch
  - delete

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFactory

func NewFactory() extension.Factory

NewFactory creates a new factory for your extension.

Types

type Config

type Config struct {
	k8sconfig.APIConfig `mapstructure:",squash"`
	LeaseName           string        `mapstructure:"lease_name"`
	LeaseNamespace      string        `mapstructure:"lease_namespace"`
	LeaseDuration       time.Duration `mapstructure:"lease_duration"`
	RenewDuration       time.Duration `mapstructure:"renew_deadline"`
	RetryPeriod         time.Duration `mapstructure:"retry_period"`
	// contains filtered or unexported fields
}

Config is the configuration for the leader elector extension.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate checks if the extension configuration is valid

type LeaderElection

type LeaderElection interface {
	extension.Extension
	SetCallBackFuncs(StartCallback, StopCallback)
}

LeaderElection Interface allows the invoker to set the callback functions that would be invoked when the leader wins or loss the election.

type StartCallback

type StartCallback = func(context.Context)

type StopCallback

type StopCallback = func()

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳