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:
parent
e1a16f6e74
commit
cf4dca8e43
3 changed files with 40 additions and 6 deletions
|
@ -29,6 +29,13 @@ rules:
|
|||
verbs:
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- coordination.k8s.io
|
||||
resources:
|
||||
- leases
|
||||
verbs:
|
||||
- list
|
||||
- watch
|
||||
{{- if and .Values.controller.scope.enabled .Values.controller.scope.namespace }}
|
||||
- apiGroups:
|
||||
- ""
|
||||
|
|
|
@ -73,6 +73,21 @@ rules:
|
|||
- configmaps
|
||||
verbs:
|
||||
- create
|
||||
- apiGroups:
|
||||
- coordination.k8s.io
|
||||
resources:
|
||||
- leases
|
||||
resourceNames:
|
||||
- {{ .Values.controller.electionID }}
|
||||
verbs:
|
||||
- get
|
||||
- update
|
||||
- apiGroups:
|
||||
- coordination.k8s.io
|
||||
resources:
|
||||
- leases
|
||||
verbs:
|
||||
- create
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue