Skip to content

Commit 2e2333b

Browse files
committed
GT-474 Switch to Lease API
1 parent 344924b commit 2e2333b

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- (Feature) Optional Assertions
77
- (Feature) Deprecate Actions
88
- (Bugfix) Debug mode
9+
- (Improvement) Switch to Lease API
910

1011
## [1.2.32](https://github.com/arangodb/kube-arangodb/tree/1.2.32) (2023-08-07)
1112
- (Feature) Backup lifetime - remove Backup once its lifetime has been reached

chart/kube-arangodb/templates/deployment-operator/role.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ rules:
3535
- apiGroups: ["policy"]
3636
resources: ["poddisruptionbudgets"]
3737
verbs: ["*"]
38+
- apiGroups: ["coordination.k8s.io"]
39+
resources: ["leases"]
40+
verbs: ["*"]
3841
- apiGroups: ["backup.arangodb.com"]
3942
resources: ["arangobackuppolicies", "arangobackups"]
4043
verbs: ["get", "list", "watch"]

pkg/operator/operator_leader.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ func (o *Operator) runLeaderElection(lockName, label string, onStart func(stop <
5757
o.Dependencies.EventRecorder.Event(eventTarget, core.EventTypeNormal, reason, message)
5858
}
5959
}
60-
rl, err := resourcelock.New("endpoints",
61-
namespace,
62-
lockName,
63-
kubecli.CoreV1(),
64-
kubecli.CoordinationV1(),
65-
resourcelock.ResourceLockConfig{
60+
61+
lock := &resourcelock.LeaseLock{
62+
LeaseMeta: meta.ObjectMeta{
63+
Name: lockName,
64+
Namespace: namespace,
65+
},
66+
Client: kubecli.CoordinationV1(),
67+
LockConfig: resourcelock.ResourceLockConfig{
6668
Identity: o.Config.ID,
6769
EventRecorder: o.Dependencies.EventRecorder,
68-
})
69-
if err != nil {
70-
log.Err(err).Fatal("Failed to create resource lock")
70+
},
7171
}
7272

7373
ctx := context.Background()
7474
leaderelection.RunOrDie(ctx, leaderelection.LeaderElectionConfig{
75-
Lock: rl,
75+
Lock: lock,
7676
LeaseDuration: 15 * time.Second,
7777
RenewDeadline: 10 * time.Second,
7878
RetryPeriod: 2 * time.Second,

0 commit comments

Comments
 (0)