-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypes.go
60 lines (47 loc) · 1.34 KB
/
types.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
package leaderelection
import (
"context"
"sync"
"sync/atomic"
"time"
"k8s.io/client-go/kubernetes"
coordinationV1 "k8s.io/client-go/kubernetes/typed/coordination/v1"
coreV1 "k8s.io/client-go/kubernetes/typed/core/v1"
leaderelection "k8s.io/client-go/tools/leaderelection"
)
type NewLeaderPayload struct {
CurrentlyLeading bool
OldLeader string
NewLeader string
}
type LeaderEngineSubscriber interface {
Name() string
NewLeader(payload *NewLeaderPayload) error
}
type K8sLeaderEngine struct {
isRunning atomic.Bool
stopped chan struct{}
parentCtx context.Context
ctx context.Context
ctxCancel context.CancelFunc
holderIdentity string
leaseDuration time.Duration
leaseName string
leaseNamespace string
renewDeadline time.Duration
retryPeriod time.Duration
apiClient kubernetes.Interface
coreClient coreV1.CoreV1Interface
coordinationClient coordinationV1.CoordinationV1Interface
leaderElector *leaderelection.LeaderElector
leaderIdentityMutex sync.Mutex
currentLeaderIdentity string
subscribersMu sync.Mutex
subscribers map[string]LeaderEngineSubscriber
logger Logger
errorLogger Logger
}
type K8sLeaderEngineOption func(*K8sLeaderEngine)
type Logger interface {
Log(string, ...interface{})
}