goelector

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: MIT Imports: 9 Imported by: 0

README

goelector

Lib that extends https://pkg.go.dev/k8s.io/client-go/tools/leaderelection

Example

Example folder provides full build/deploy/test makefile targets

Usage:
  make <target>

Targets:
  compile Go compiles elector for linux os
  docker Docker build and push to your registry, needs REGISTRY env var to be set
  check Check whichs pod is elected leader
  deploy Deploy serviceaccount and deployment to k8s, requires REGISTRY env var to be set
  deploy-sa Deploys service account with access to coordination api, only needed once
  help Show help

Docker

$REGISTRY=gcr.io/<your_project> make docker Builds dockerfile, tags and pushes to registry

$REGISTRY=gcr.io/<your_project> make deploy Deploys to active kubernetes cluster/namespace Using extended service account created by $make deploy-sa

$REGISTRY=gcr.io/<your_project> make check Checks of elector is selected, example output

Running services:
elector-test-68b9db5f95-64cvv
elector-test-68b9db5f95-h8db8
elector-test-68b9db5f95-wvtd9

Elected leader:
elector-test-68b9db5f95-h8db8

Usage

Start

Blocking, using only default functions for callbacks when leader is selected

StartWithCallbacks

Blocking, provides user defined callback functions for Start/Stop/New Leader

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLeader

func IsLeader() bool

IsLeader returns if leading currently is reporting being the leader

func Start

func Start(ctx context.Context, cfg *Config, nodeID string, client *kubernetes.Clientset) error

Start with default callback implementation which is a basic atomic store/load int32

Use when only set/unset leader is needed Caller is responsible for calling cancel on context to release lease

func StartWithCallbacks

func StartWithCallbacks(ctx context.Context, cfg *Config, nodeID string, client *kubernetes.Clientset, startFn *func(context.Context), stopFn *func(), newFn *func(string)) error

StartWithCallbacks with user defined callbacks for set/unset Caller is responsible for calling cancel on context to release lease

func TurnOffKlog

func TurnOffKlog()

TurnOffKlog supresses leaderelector.go's usage of klog

Types

type Config

type Config struct {
	LeaseDuration int    `json:"lease_duration"`
	RenewDeadline int    `json:"renew_deadline"`
	RetryPeriod   int    `json:"retry_period"`
	Lock          string `json:"lock"`
	Namespace     string `json:"namespace"`
}

Config type with input to elector

func GetDefaultConfig

func GetDefaultConfig() *Config

GetDefaultConfig returns defaulted config

type EmptyLogger

type EmptyLogger struct{}

EmptyLogger implements logr.Logging

func (*EmptyLogger) Enabled

func (e *EmptyLogger) Enabled() bool

Enabled always returns false

func (*EmptyLogger) Error

func (e *EmptyLogger) Error(err error, msg string, keysAndValues ...interface{})

Error does nothing

func (*EmptyLogger) Info

func (e *EmptyLogger) Info(msg string, keysAndValues ...interface{})

Info does nothing

func (*EmptyLogger) V

func (e *EmptyLogger) V(level int) logr.Logger

V returns itself

func (*EmptyLogger) WithName

func (e *EmptyLogger) WithName(name string) logr.Logger

WithName returns itself

func (*EmptyLogger) WithValues

func (e *EmptyLogger) WithValues(keysAndValues ...interface{}) logr.Logger

WithValues returns itself

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL