From 974d2ae688129e0290f0deb75fca128a92765a41 Mon Sep 17 00:00:00 2001 From: prashanth26 Date: Wed, 19 Dec 2018 16:13:33 +0530 Subject: [PATCH] Final test --- .../tools/leaderelection/leaderelection.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go b/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go index 8bbb32cc8..ba689f350 100644 --- a/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go +++ b/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go @@ -206,14 +206,12 @@ func (le *LeaderElector) renew(ctx context.Context) { gst time.Time ) gst = time.Now() - glog.V(2).Infof("Started") ctx, cancel := context.WithCancel(ctx) defer cancel() wait.Until(func() { timeoutCtx, timeoutCancel := context.WithTimeout(ctx, le.config.RenewDeadline) defer timeoutCancel() - defer glog.V(2).Info("Finished renew") err := wait.PollImmediateUntil(le.config.RetryPeriod, func() (bool, error) { done := make(chan bool, 1) go func() { @@ -257,7 +255,9 @@ func (le *LeaderElector) tryAcquireOrRenew() bool { AcquireTime: now, } + glog.Info("0") // 1. obtain or create the ElectionRecord + glog.Info("1") oldLeaderElectionRecord, err := le.config.Lock.Get() if err != nil { if !errors.IsNotFound(err) { @@ -270,15 +270,15 @@ func (le *LeaderElector) tryAcquireOrRenew() bool { } le.observedRecord = leaderElectionRecord le.observedTime = time.Now() - glog.Info("1") + glog.Info("1-a") return true } + glog.Info("2") // 2. Record obtained, check the Identity & Time if !reflect.DeepEqual(le.observedRecord, *oldLeaderElectionRecord) { le.observedRecord = *oldLeaderElectionRecord le.observedTime = time.Now() - glog.Info("2") } if le.observedTime.Add(le.config.LeaseDuration).After(now.Time) && !le.IsLeader() { @@ -286,26 +286,26 @@ func (le *LeaderElector) tryAcquireOrRenew() bool { glog.Errorf("Lock acquired till: %s, Now: %s", le.observedTime.Add(le.config.LeaseDuration), now.Time) return false } + glog.Info("3") // 3. We're going to try to update. The leaderElectionRecord is set to it's default // here. Let's correct it before updating. if le.IsLeader() { leaderElectionRecord.AcquireTime = oldLeaderElectionRecord.AcquireTime leaderElectionRecord.LeaderTransitions = oldLeaderElectionRecord.LeaderTransitions - glog.Info("3a") } else { leaderElectionRecord.LeaderTransitions = oldLeaderElectionRecord.LeaderTransitions + 1 - glog.Info("3b") } + glog.Info("4") // update the lock itself if err = le.config.Lock.Update(leaderElectionRecord); err != nil { glog.Errorf("Failed to update lock: %v", err) return false } + glog.Info("5") le.observedRecord = leaderElectionRecord le.observedTime = time.Now() - glog.Info("3c") return true }