mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
lease controller: add new constructor NewControllerWithLeaseName to support cases when the lease name and holder identity differ
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
This commit is contained in:
parent
f74f819e1a
commit
6925bee6d5
@ -54,6 +54,7 @@ type controller struct {
|
|||||||
client clientset.Interface
|
client clientset.Interface
|
||||||
leaseClient coordclientset.LeaseInterface
|
leaseClient coordclientset.LeaseInterface
|
||||||
holderIdentity string
|
holderIdentity string
|
||||||
|
leaseName string
|
||||||
leaseNamespace string
|
leaseNamespace string
|
||||||
leaseDurationSeconds int32
|
leaseDurationSeconds int32
|
||||||
renewInterval time.Duration
|
renewInterval time.Duration
|
||||||
@ -80,6 +81,28 @@ func NewController(clock clock.Clock, client clientset.Interface, holderIdentity
|
|||||||
client: client,
|
client: client,
|
||||||
leaseClient: leaseClient,
|
leaseClient: leaseClient,
|
||||||
holderIdentity: holderIdentity,
|
holderIdentity: holderIdentity,
|
||||||
|
leaseName: holderIdentity,
|
||||||
|
leaseNamespace: leaseNamespace,
|
||||||
|
leaseDurationSeconds: leaseDurationSeconds,
|
||||||
|
renewInterval: renewInterval,
|
||||||
|
clock: clock,
|
||||||
|
onRepeatedHeartbeatFailure: onRepeatedHeartbeatFailure,
|
||||||
|
newLeasePostProcessFunc: newLeasePostProcessFunc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewControllerWithLeaseName is a copy of NewController but accepts a leaseName parameter.
|
||||||
|
// Use this constructor in cases when the lease name and holder identity should be different.
|
||||||
|
func NewControllerWithLeaseName(clock clock.Clock, client clientset.Interface, holderIdentity string, leaseDurationSeconds int32, onRepeatedHeartbeatFailure func(), renewInterval time.Duration, leaseName, leaseNamespace string, newLeasePostProcessFunc ProcessLeaseFunc) Controller {
|
||||||
|
var leaseClient coordclientset.LeaseInterface
|
||||||
|
if client != nil {
|
||||||
|
leaseClient = client.CoordinationV1().Leases(leaseNamespace)
|
||||||
|
}
|
||||||
|
return &controller{
|
||||||
|
client: client,
|
||||||
|
leaseClient: leaseClient,
|
||||||
|
holderIdentity: holderIdentity,
|
||||||
|
leaseName: leaseName,
|
||||||
leaseNamespace: leaseNamespace,
|
leaseNamespace: leaseNamespace,
|
||||||
leaseDurationSeconds: leaseDurationSeconds,
|
leaseDurationSeconds: leaseDurationSeconds,
|
||||||
renewInterval: renewInterval,
|
renewInterval: renewInterval,
|
||||||
@ -208,7 +231,7 @@ func (c *controller) newLease(base *coordinationv1.Lease) (*coordinationv1.Lease
|
|||||||
if base == nil {
|
if base == nil {
|
||||||
lease = &coordinationv1.Lease{
|
lease = &coordinationv1.Lease{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: c.holderIdentity,
|
Name: c.leaseName,
|
||||||
Namespace: c.leaseNamespace,
|
Namespace: c.leaseNamespace,
|
||||||
},
|
},
|
||||||
Spec: coordinationv1.LeaseSpec{
|
Spec: coordinationv1.LeaseSpec{
|
||||||
|
@ -59,6 +59,7 @@ func TestNewNodeLease(t *testing.T) {
|
|||||||
desc: "nil base without node",
|
desc: "nil base without node",
|
||||||
controller: &controller{
|
controller: &controller{
|
||||||
client: fake.NewSimpleClientset(),
|
client: fake.NewSimpleClientset(),
|
||||||
|
leaseName: node.Name,
|
||||||
holderIdentity: node.Name,
|
holderIdentity: node.Name,
|
||||||
leaseDurationSeconds: 10,
|
leaseDurationSeconds: 10,
|
||||||
clock: fakeClock,
|
clock: fakeClock,
|
||||||
@ -80,6 +81,7 @@ func TestNewNodeLease(t *testing.T) {
|
|||||||
desc: "nil base with node",
|
desc: "nil base with node",
|
||||||
controller: &controller{
|
controller: &controller{
|
||||||
client: fake.NewSimpleClientset(node),
|
client: fake.NewSimpleClientset(node),
|
||||||
|
leaseName: node.Name,
|
||||||
holderIdentity: node.Name,
|
holderIdentity: node.Name,
|
||||||
leaseDurationSeconds: 10,
|
leaseDurationSeconds: 10,
|
||||||
clock: fakeClock,
|
clock: fakeClock,
|
||||||
|
Loading…
Reference in New Issue
Block a user