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:
|
verbs:
|
||||||
- list
|
- list
|
||||||
- watch
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- coordination.k8s.io
|
||||||
|
resources:
|
||||||
|
- leases
|
||||||
|
verbs:
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
{{- if and .Values.controller.scope.enabled .Values.controller.scope.namespace }}
|
{{- if and .Values.controller.scope.enabled .Values.controller.scope.namespace }}
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ""
|
- ""
|
||||||
|
|
|
@ -73,6 +73,21 @@ rules:
|
||||||
- configmaps
|
- configmaps
|
||||||
verbs:
|
verbs:
|
||||||
- create
|
- create
|
||||||
|
- apiGroups:
|
||||||
|
- coordination.k8s.io
|
||||||
|
resources:
|
||||||
|
- leases
|
||||||
|
resourceNames:
|
||||||
|
- {{ .Values.controller.electionID }}
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- update
|
||||||
|
- apiGroups:
|
||||||
|
- coordination.k8s.io
|
||||||
|
resources:
|
||||||
|
- leases
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ""
|
- ""
|
||||||
resources:
|
resources:
|
||||||
|
|
|
@ -93,12 +93,24 @@ func setupLeaderElection(config *leaderElectionConfig) {
|
||||||
Host: hostname,
|
Host: hostname,
|
||||||
})
|
})
|
||||||
|
|
||||||
lock := resourcelock.ConfigMapLock{
|
objectMeta := metav1.ObjectMeta{Namespace: k8s.IngressPodDetails.Namespace, Name: config.ElectionID}
|
||||||
ConfigMapMeta: metav1.ObjectMeta{Namespace: k8s.IngressPodDetails.Namespace, Name: config.ElectionID},
|
resourceLockConfig := resourcelock.ResourceLockConfig{
|
||||||
Client: config.Client.CoreV1(),
|
|
||||||
LockConfig: resourcelock.ResourceLockConfig{
|
|
||||||
Identity: k8s.IngressPodDetails.Name,
|
Identity: k8s.IngressPodDetails.Name,
|
||||||
EventRecorder: recorder,
|
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