Add Lease implementation to leaderelection package

Kubernetes-commit: 410175851c092dae63f72f7d12abf19b1b74e200
This commit is contained in:
Matthew Wong
2018-11-20 10:29:44 -05:00
committed by Kubernetes Publisher
parent 75103f9708
commit e10ef5817f
3 changed files with 233 additions and 74 deletions

View File

@@ -21,6 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
coordinationv1 "k8s.io/client-go/kubernetes/typed/coordination/v1"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
)
@@ -28,6 +29,7 @@ const (
LeaderElectionRecordAnnotationKey = "control-plane.alpha.kubernetes.io/leader"
EndpointsResourceLock = "endpoints"
ConfigMapsResourceLock = "configmaps"
LeasesResourceLock = "leases"
)
// LeaderElectionRecord is the record that is stored in the leader election annotation.
@@ -89,7 +91,7 @@ type Interface interface {
}
// Manufacture will create a lock of a given type according to the input parameters
func New(lockType string, ns string, name string, client corev1.CoreV1Interface, rlc ResourceLockConfig) (Interface, error) {
func New(lockType string, ns string, name string, coreClient corev1.CoreV1Interface, coordinationClient coordinationv1.CoordinationV1Interface, rlc ResourceLockConfig) (Interface, error) {
switch lockType {
case EndpointsResourceLock:
return &EndpointsLock{
@@ -97,7 +99,7 @@ func New(lockType string, ns string, name string, client corev1.CoreV1Interface,
Namespace: ns,
Name: name,
},
Client: client,
Client: coreClient,
LockConfig: rlc,
}, nil
case ConfigMapsResourceLock:
@@ -106,7 +108,16 @@ func New(lockType string, ns string, name string, client corev1.CoreV1Interface,
Namespace: ns,
Name: name,
},
Client: client,
Client: coreClient,
LockConfig: rlc,
}, nil
case LeasesResourceLock:
return &LeaseLock{
LeaseMeta: metav1.ObjectMeta{
Namespace: ns,
Name: name,
},
Client: coordinationClient,
LockConfig: rlc,
}, nil
default: