fix#92167: GetLabelsForVolume panic issue for azure disk PV

fix comments
This commit is contained in:
andyzhangx 2020-06-16 06:03:41 +00:00
parent 1c11ff7a26
commit d3a90d1dd0

View File

@ -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
}