Merge pull request #92166 from andyzhangx/GetLabelsForVolume-panic

fix: GetLabelsForVolume panic issue for azure disk PV
This commit is contained in:
Kubernetes Prow Robot 2020-06-18 06:02:32 -07:00 committed by GitHub
commit 73d6be90d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
}