This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
machinesservicelb.go
65 lines (56 loc) · 1.69 KB
/
machinesservicelb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package wrap
import (
"github.com/caos/orbos/internal/operator/common"
"github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/core/infra"
"github.com/caos/orbos/internal/operator/orbiter/kinds/loadbalancers/dynamic"
"github.com/caos/orbos/internal/operator/orbiter/kinds/providers/core"
)
var _ core.MachinesService = (*CmpSvcLB)(nil)
type CmpSvcLB struct {
core.MachinesService
dynamic dynamic.Current
nodeagents *common.DesiredNodeAgents
notifyMasters func(machine infra.Machine, peers infra.Machines, vips []*dynamic.VIP) string
vrrp bool
vip func(*dynamic.VIP) string
}
func MachinesService(svc core.MachinesService, curr dynamic.Current, vrrp bool, notifyMasters func(machine infra.Machine, peers infra.Machines, vips []*dynamic.VIP) string, vip func(*dynamic.VIP) string) *CmpSvcLB {
return &CmpSvcLB{
MachinesService: svc,
dynamic: curr,
notifyMasters: notifyMasters,
vrrp: vrrp,
vip: vip,
}
}
func (i *CmpSvcLB) InitializeDesiredNodeAgents() (bool, error) {
pools, err := i.ListPools()
if err != nil {
return false, err
}
done := true
for _, pool := range pools {
poolDone, err := i.desire(pool)
if !poolDone {
done = false
}
if err != nil {
return done, err
}
}
return done, nil
}
func (i *CmpSvcLB) Create(poolName string) (infra.Machine, error) {
cmp, err := i.MachinesService.Create(poolName)
if err != nil {
return nil, err
}
_, err = i.desire(poolName)
return machine(cmp, func() error {
_, err := i.desire(poolName)
return err
}), err
}
func (c *CmpSvcLB) desire(selfPool string) (bool, error) {
return c.dynamic.Current.Desire(selfPool, c, c.vrrp, c.notifyMasters, c.vip)
}