some work done
This commit is contained in:
parent
a735b9cc5e
commit
09fe1cd163
13 changed files with 174 additions and 45 deletions
|
|
@ -5,17 +5,60 @@ import (
|
|||
"os/exec"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/vipman/pkg/cluster"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/config"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/vip"
|
||||
"git.giftfish.de/ston1th/haproxy-kb/pkg/cluster"
|
||||
"git.giftfish.de/ston1th/haproxy-kb/pkg/config"
|
||||
"git.giftfish.de/ston1th/haproxy-kb/pkg/haproxy"
|
||||
"git.giftfish.de/ston1th/haproxy-kb/pkg/vip"
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
func NewVIPController(cfg *config.Config) (callbacks cluster.Callbacks, err error) {
|
||||
type UpdateAction int
|
||||
|
||||
const (
|
||||
Add UpdateAction = iota
|
||||
Delete
|
||||
)
|
||||
|
||||
type ConfigUpdate struct {
|
||||
Action UpdateAction
|
||||
Config haproxy.LoadBalancer
|
||||
}
|
||||
|
||||
func readConfigUpdates(c chan ConfigUpdate) (cu []ConfigUpdate) {
|
||||
for len(c) > 0 {
|
||||
select {
|
||||
case config := <-c:
|
||||
cu = append(cu, config)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func applyConfigUpdates(cc cluster.CallbackContext, cu []ConfigUpdate) error {
|
||||
for _, c := range cu {
|
||||
switch c.Action {
|
||||
case Add:
|
||||
addIPs(cc, n, []string{c.Config.IP})
|
||||
cc.Set(c.Config.IP, nil)
|
||||
case Delete:
|
||||
cc.Delete(c.Config.IP)
|
||||
deleteIPs(cc, n, []string{c.Config.IP})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func NewLBController(cfg *config.Config) (callbacks cluster.Callbacks, err error) {
|
||||
n, err := vip.NewNetworkWithLabel(cfg.Interface, cfg.Label)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
//TODO
|
||||
ha, err := haproxy.NewHAProxyManager("")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
configUpdate := make(chan ConfigUpdate, 100)
|
||||
|
||||
callbacks = cluster.Callbacks{
|
||||
Leader: func(ctx context.Context, cc cluster.CallbackContext) {
|
||||
t := time.NewTicker(time.Second * 10)
|
||||
|
|
@ -29,7 +72,20 @@ func NewVIPController(cfg *config.Config) (callbacks cluster.Callbacks, err erro
|
|||
}
|
||||
for {
|
||||
cc.Info("leading", "id", cc.ID())
|
||||
cfg, err := cc.Get("config")
|
||||
if err != nil {
|
||||
cc.Error("error getting config key", err)
|
||||
<-t.C
|
||||
continue
|
||||
}
|
||||
addIPs(cc, n, cfg.VirtualIPs)
|
||||
var lbs haproxy.Config
|
||||
err = ha.UpdateConfig(ctx, lbs)
|
||||
if err != nil {
|
||||
cc.Error("error updating haproxy config", err)
|
||||
<-t.C
|
||||
continue
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Stop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue