initial commit
This commit is contained in:
commit
c0616030c6
14 changed files with 1468 additions and 0 deletions
45
pkg/cluster/cluster.go
Normal file
45
pkg/cluster/cluster.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Cluster - The Cluster object manages the state of the cluster for a particular node
|
||||
type Cluster struct {
|
||||
stateMachine FSM
|
||||
stop chan struct{}
|
||||
done chan struct{}
|
||||
Callbacks LeaderCallbacks
|
||||
}
|
||||
|
||||
type LeaderCallbacks struct {
|
||||
// OnStartedLeading is called when a LeaderElector client starts leading
|
||||
OnStartedLeading func(context.Context)
|
||||
// OnStoppedLeading is called when a LeaderElector client stops leading
|
||||
OnStoppedLeading func()
|
||||
// OnNewLeader is called when the client observes a leader that is
|
||||
// not the previously observed leader. This includes the first observed
|
||||
// leader when the client starts.
|
||||
OnNewLeader func(string)
|
||||
}
|
||||
|
||||
// InitCluster - Will attempt to initialise all of the required settings for the cluster
|
||||
func InitCluster(callbacks LeaderCallbacks) (*Cluster, error) {
|
||||
if callbacks.OnStartedLeading == nil {
|
||||
return nil, errors.New("OnStartedLeading is nil")
|
||||
}
|
||||
if callbacks.OnStoppedLeading == nil {
|
||||
return nil, errors.New("OnStoppedLeading is nil")
|
||||
}
|
||||
if callbacks.OnNewLeader == nil {
|
||||
return nil, errors.New("OnNewLeader is nil")
|
||||
}
|
||||
c := &Cluster{
|
||||
stop: make(chan struct{}, 1),
|
||||
done: make(chan struct{}, 1),
|
||||
Callbacks: callbacks,
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue