Skip to content

Library to perform leader election in a cluster of containerized Elixir nodes

License

Notifications You must be signed in to change notification settings

ritalinn/libelection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libelection

Libelection

Build Status Package Version Coverage Inline docs

Library to perform leader election in a cluster of containerized Elixir nodes.

Installation

def deps do
  [{:libelection, "~> 0.2.0"}]
end

Usage

if Election.leader? do
  # Code path executed only by the leader node
else
  # Code path executed by followers
end

How it works

Polls the API of the configured container orchestration platform to determine the oldest node of the cluster.

To configure the polling interval use:

config :libelection, :polling_interval, 2_000 # 2 seconds

To configure the function which lists the node of the cluster use:

config :libelection, :list_nodes, {module, function, args}
# it can also be a function reference
config :libelection, :list_nodes, &SomeModule.some_function/1

Configure the logger

config :libelection, :logger, %{level: :debug} # Default

Election Strategies

Rancher

The create_index identifier is used to pick the leader.

config :libelection,
  strategy: Election.Strategy.Rancher,
  rancher_node_basename: "some-app"

Kubernetes

The resourceVersion identifier is used to pick the leader.

config :libelection,
  strategy: Election.Strategy.Kubernetes,
  kubernetes_selector: "app=some-app",
  kubernetes_node_basename: "some-app"

Documentation

  • exdoc
  • wiki (coming soon)

License

GPLv3

About

Library to perform leader election in a cluster of containerized Elixir nodes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%