vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go

    func (le *LeaderElector) acquire(ctx context.Context) bool { ctx, cancel := context.WithCancel(ctx) defer cancel()

    succeeded := false desc := le.config.Lock.Describe()

    klog.Infof(“attempting to acquire leader lease %v…”, desc)

    wait.JitterUntil(func() {

    1. succeeded = le.tryAcquireOrRenew()
    2. le.maybeReportTransition()
    3. if !succeeded {
    4. klog.V(4).Infof("failed to acquire lease %v", desc)
    5. return }
    6. le.config.Lock.RecordEvent("became leader")
    7. le.metrics.leaderOn(le.config.Name)
    8. klog.Infof("successfully acquired lease %v", desc)
    9. cancel()

    }, le.config.RetryPeriod, JitterFactor, true, ctx.Done())

    return succeeded}

    tryAcquireOrRenew