From d3a90d1dd07a66f0e45ac9867fb71c20bc4ef741 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Tue, 16 Jun 2020 06:03:41 +0000 Subject: [PATCH] fix#92167: GetLabelsForVolume panic issue for azure disk PV fix comments --- .../azure/azure_managedDiskController.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go index de6e5e0a935..2168498c733 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go @@ -346,6 +346,13 @@ func (c *Cloud) GetAzureDiskLabels(diskURI string) (map[string]string, error) { return nil, err } + labels := map[string]string{ + v1.LabelZoneRegion: c.Location, + } + // no azure credential is set, return nil + if c.DisksClient == nil { + return labels, nil + } // Get information of the disk. ctx, cancel := getContextWithCancel() defer cancel() @@ -358,7 +365,7 @@ func (c *Cloud) GetAzureDiskLabels(diskURI string) (map[string]string, error) { // Check whether availability zone is specified. if disk.Zones == nil || len(*disk.Zones) == 0 { klog.V(4).Infof("Azure disk %q is not zoned", diskName) - return nil, nil + return labels, nil } zones := *disk.Zones @@ -369,9 +376,6 @@ func (c *Cloud) GetAzureDiskLabels(diskURI string) (map[string]string, error) { zone := c.makeZone(c.Location, zoneID) klog.V(4).Infof("Got zone %q for Azure disk %q", zone, diskName) - labels := map[string]string{ - v1.LabelZoneRegion: c.Location, - v1.LabelZoneFailureDomain: zone, - } + labels[v1.LabelZoneFailureDomain] = zone return labels, nil }