feat: migrate leaderelection lock to leases (#8733)

* feat: migrate leaderelection lock to leases

Signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>

* Update RBAC

Co-authored-by: Shafeeque E S <shafeeque.e.s@sap.com>
This commit is contained in:
Jintao Zhang 2022-07-09 20:37:46 +08:00 committed by GitHub
parent e1a16f6e74
commit cf4dca8e43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 6 deletions

View file

@ -93,12 +93,24 @@ func setupLeaderElection(config *leaderElectionConfig) {
Host: hostname,
})
lock := resourcelock.ConfigMapLock{
ConfigMapMeta: metav1.ObjectMeta{Namespace: k8s.IngressPodDetails.Namespace, Name: config.ElectionID},
Client: config.Client.CoreV1(),
LockConfig: resourcelock.ResourceLockConfig{
Identity: k8s.IngressPodDetails.Name,
EventRecorder: recorder,
objectMeta := metav1.ObjectMeta{Namespace: k8s.IngressPodDetails.Namespace, Name: config.ElectionID}
resourceLockConfig := resourcelock.ResourceLockConfig{
Identity: k8s.IngressPodDetails.Name,
EventRecorder: recorder,
}
// TODO: If we upgrade client-go to v0.24 then we can only use LeaseLock.
// MultiLock is used for lock's migration
lock := resourcelock.MultiLock{
Primary: &resourcelock.ConfigMapLock{
ConfigMapMeta: objectMeta,
Client: config.Client.CoreV1(),
LockConfig: resourceLockConfig,
},
Secondary: &resourcelock.LeaseLock{
LeaseMeta: objectMeta,
Client: config.Client.CoordinationV1(),
LockConfig: resourceLockConfig,
},
}