From af165173268c8aaec3119de80c268e85ee029079 Mon Sep 17 00:00:00 2001 From: prashanth26 Date: Wed, 19 Dec 2018 13:14:32 +0530 Subject: [PATCH] Made changes --- pkg/driver/driver_azure.go | 17 ++++++++++++----- .../tools/leaderelection/leaderelection.go | 15 +++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/pkg/driver/driver_azure.go b/pkg/driver/driver_azure.go index ea73893bf..5de59d750 100644 --- a/pkg/driver/driver_azure.go +++ b/pkg/driver/driver_azure.go @@ -89,7 +89,7 @@ func (d *AzureDriver) Create() (string, string, error) { Name: &nicName, InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ PrivateIPAllocationMethod: network.Dynamic, - Subnet: &subnet, + Subnet: &subnet, }, }, }, @@ -218,13 +218,20 @@ func (d *AzureDriver) Delete() error { listOfResources := make(map[string]string) d.getvms(d.MachineID, listOfResources) if len(listOfResources) != 0 { - _, errChan := vmClient.Delete(resourceGroup, vmName, cancel) + _, errChan := vmClient.PowerOff(resourceGroup, vmName, cancel) + err = onErrorFail(<-errChan, fmt.Sprintf("vmClient.PowerOff failed for '%s'", vmName)) + if err != nil { + return err + } + glog.V(2).Infof("PowerOff VM %s", vmName) + + _, errChan = vmClient.Delete(resourceGroup, vmName, cancel) err = onErrorFail(<-errChan, fmt.Sprintf("vmClient.Delete failed for '%s'", vmName)) if err != nil { return err } } - glog.V(3).Infof("Deleted VM %s", vmName) + glog.V(2).Infof("Deleted VM %s", vmName) listOfResources = make(map[string]string) d.getnics(d.MachineID, listOfResources) @@ -235,7 +242,7 @@ func (d *AzureDriver) Delete() error { return err } } - glog.V(3).Infof("Deleted NIC %s", nicName) + glog.V(2).Infof("Deleted NIC %s", nicName) listOfResources = make(map[string]string) d.getdisks(d.MachineID, listOfResources) @@ -246,7 +253,7 @@ func (d *AzureDriver) Delete() error { return err } } - glog.V(3).Infof("Deleted OS-Disk %s", nicName) + glog.V(2).Infof("Deleted OS-Disk %s", nicName) return err } diff --git a/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go b/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go index 9639fd994..a6a5b768c 100644 --- a/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go +++ b/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go @@ -201,22 +201,33 @@ func (le *LeaderElector) acquire(ctx context.Context) bool { // renew loops calling tryAcquireOrRenew and returns immediately when tryAcquireOrRenew fails or ctx signals done. func (le *LeaderElector) renew(ctx context.Context) { + var ( + lst time.Time + 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() { defer close(done) + lst = time.Now() done <- le.tryAcquireOrRenew() }() select { case <-timeoutCtx.Done(): + glog.V(2).Infof("Finished tryAcquireOrRenew lst: %v, gst: %v, Return: %d", time.Since(lst), time.Since(gst), false) return false, fmt.Errorf("failed to tryAcquireOrRenew %s", timeoutCtx.Err()) case result := <-done: + glog.V(2).Infof("Finished tryAcquireOrRenew lst: %v, gst: %v, Return: %d", time.Since(lst), time.Since(gst), result) return result, nil } }, timeoutCtx.Done()) @@ -237,10 +248,6 @@ func (le *LeaderElector) renew(ctx context.Context) { // else it tries to renew the lease if it has already been acquired. Returns true // on success else returns false. func (le *LeaderElector) tryAcquireOrRenew() bool { - startTime := time.Now() - defer func() { - glog.V(2).Infof("Finished tryAcquireOrRenew (%v)", time.Since(startTime)) - }() now := metav1.Now() leaderElectionRecord := rl.LeaderElectionRecord{