failover

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PASSIVE   status = -1
	UNDEFINED status = 0
	ACTIVE    status = 1
)
View Source
const Label = "github.com.pace.bricks.activepassive"

Variables

This section is empty.

Functions

func NewPodStateSetter added in v0.5.0

func NewPodStateSetter() (*podStateSetter, error)

Types

type ActivePassive

type ActivePassive struct {
	// OnActive will be called in case the current processes is elected to be the active one
	OnActive func(ctx context.Context)

	// OnPassive will be called in case the current process is the passive one
	OnPassive func(ctx context.Context)

	// OnStop is called after the ActivePassive process stops
	OnStop func()
	// contains filtered or unexported fields
}

ActivePassive implements a failover mechanism that allows to deploy a service multiple times but ony one will accept traffic by using the label selector of kubernetes. In order to determine the active, a lock needs to be hold in redis. Hooks can be passed to handle the case of becoming the active or passive. The readiness probe will report the state (ACTIVE/PASSIVE) of each of the members in the cluster.

func NewActivePassive

func NewActivePassive(clusterName string, timeToFailover time.Duration, client *redis.Client, opts ...ActivePassiveOption) (*ActivePassive, error)

NewActivePassive creates a new active passive cluster identified by the name. The time to fail over determines the frequency of checks performed against redis to keep the active state. NOTE: creating multiple ActivePassive in one process is not working correctly as there is only one readiness probe.

func (*ActivePassive) Handler

func (a *ActivePassive) Handler(w http.ResponseWriter, r *http.Request)

Handler implements the readiness http endpoint

func (*ActivePassive) Run

func (a *ActivePassive) Run(ctx context.Context) error

Run manages distributed lock-based leadership. This method is designed to continually monitor and maintain the leadership status of the calling pod, ensuring only one active instance holds the lock at a time, while transitioning other instances to passive mode. The handler will try to renew its active status by refreshing the lock periodically.

func (*ActivePassive) Stop

func (a *ActivePassive) Stop()

Stop stops acting as a passive or active member.

type ActivePassiveOption added in v0.5.0

type ActivePassiveOption func(*ActivePassive) error

func WithCustomStateSetter added in v0.5.0

func WithCustomStateSetter(fn func(ctx context.Context, state string) error) ActivePassiveOption

func WithNoopStateSetter added in v0.5.0

func WithNoopStateSetter() ActivePassiveOption

func WithPodStateSetter added in v0.5.0

func WithPodStateSetter() ActivePassiveOption

type CustomStateSetter added in v0.5.0

type CustomStateSetter struct {
	// contains filtered or unexported fields
}

func NewCustomStateSetter added in v0.5.0

func NewCustomStateSetter(fn func(ctx context.Context, state string) error) (*CustomStateSetter, error)

func (*CustomStateSetter) SetState added in v0.5.0

func (c *CustomStateSetter) SetState(ctx context.Context, state string) error

type NoopStateSetter added in v0.5.0

type NoopStateSetter struct{}

func (*NoopStateSetter) SetState added in v0.5.0

func (n *NoopStateSetter) SetState(ctx context.Context, state string) error

type StateSetter added in v0.5.0

type StateSetter interface {
	SetState(ctx context.Context, state string) error
}

Jump to

Keyboard shortcuts

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