From 4dc4988cc7bf7b3fbb38e58ba6906cfeae93cd0d Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Tue, 16 Jun 2020 06:03:41 +0000 Subject: [PATCH] UPSTREAM: 92166: fix: GetLabelsForVolume panic issue for azure disk PV --- .../azure/azure_managedDiskController.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/vendor/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go b/vendor/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go index 3a48df20b503..06ae4dfb3620 100644 --- a/vendor/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go +++ b/vendor/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go @@ -313,6 +313,14 @@ 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() @@ -325,7 +333,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 @@ -336,9 +344,7 @@ 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 }