added etcd support

This commit is contained in:
ston1th 2020-11-15 18:39:16 +01:00
commit 85a8ba23bd
21 changed files with 767 additions and 247 deletions

View file

@ -4,33 +4,53 @@ import (
"errors"
"git.giftfish.de/ston1th/vipman/pkg/cluster"
"github.com/go-logr/logr"
"github.com/hashicorp/raft"
)
type Cluster struct {
kv *KV
r *raft.Raft
logr.Logger
cluster.KV
r *raft.Raft
kvm *kv
stepdown chan struct{}
stop chan struct{}
done chan struct{}
Callbacks cluster.Callbacks
callbacks cluster.Callbacks
id string
}
func NewCluster(callbacks cluster.Callbacks) (cluster.Cluster, error) {
if callbacks.Leader == nil {
return nil, errors.New("Leader is nil")
}
if callbacks.Follower == nil {
return nil, errors.New("Follower is nil")
func NewCluster(log logr.Logger) cluster.Cluster {
kvm := &kv{
m: make(map[string][]byte),
}
return &Cluster{
kv: &KV{
m: make(map[string][]byte),
},
stepdown: make(chan struct{}, 1),
stop: make(chan struct{}, 1),
done: make(chan struct{}, 1),
Callbacks: callbacks,
}, nil
Logger: log,
KV: kvm,
kvm: kvm,
stepdown: make(chan struct{}, 1),
stop: make(chan struct{}, 1),
done: make(chan struct{}, 1),
}
}
func (c *Cluster) ID() string {
return c.id
}
func (c *Cluster) SetCallbacks(callbacks cluster.Callbacks) error {
c.callbacks = callbacks
return c.checkConfig()
}
func (c *Cluster) checkConfig() error {
if c.callbacks.Leader == nil {
return errors.New("Leader callback is nil")
}
if c.callbacks.Follower == nil {
return errors.New("Follower callback is nil")
}
return nil
}