feat: Allow leases to have custom labels set when a new holder has the lease

Kubernetes-commit: 109ae1bacadfa5c8655adb4594762c77b135f446
This commit is contained in:
Derek Frank
2025-05-06 10:43:05 -07:00
committed by Kubernetes Publisher
parent 647bbbe859
commit 34f791d2b1
3 changed files with 394 additions and 4 deletions

View File

@@ -99,8 +99,8 @@ type Interface interface {
Describe() string
}
// Manufacture will create a lock of a given type according to the input parameters
func New(lockType string, ns string, name string, coreClient corev1.CoreV1Interface, coordinationClient coordinationv1.CoordinationV1Interface, rlc ResourceLockConfig) (Interface, error) {
// new will create a lock of a given type according to the input parameters
func new(lockType string, ns string, name string, coreClient corev1.CoreV1Interface, coordinationClient coordinationv1.CoordinationV1Interface, rlc ResourceLockConfig, labels map[string]string) (Interface, error) {
leaseLock := &LeaseLock{
LeaseMeta: metav1.ObjectMeta{
Namespace: ns,
@@ -108,6 +108,7 @@ func New(lockType string, ns string, name string, coreClient corev1.CoreV1Interf
},
Client: coordinationClient,
LockConfig: rlc,
Labels: labels,
}
switch lockType {
case endpointsResourceLock:
@@ -125,6 +126,17 @@ func New(lockType string, ns string, name string, coreClient corev1.CoreV1Interf
}
}
// New will create a lock of a given type according to the input parameters
func New(lockType string, ns string, name string, coreClient corev1.CoreV1Interface, coordinationClient coordinationv1.CoordinationV1Interface, rlc ResourceLockConfig) (Interface, error) {
return new(lockType, ns, name, coreClient, coordinationClient, rlc, nil)
}
// NewWithLabels will create a lock of a given type according to the input parameters
// When the holder of the lock changes, that holder will apply their labels
func NewWithLabels(lockType string, ns string, name string, coreClient corev1.CoreV1Interface, coordinationClient coordinationv1.CoordinationV1Interface, rlc ResourceLockConfig, labels map[string]string) (Interface, error) {
return new(lockType, ns, name, coreClient, coordinationClient, rlc, labels)
}
// NewFromKubeconfig will create a lock of a given type according to the input parameters.
// Timeout set for a client used to contact to Kubernetes should be lower than
// RenewDeadline to keep a single hung request from forcing a leader loss.