Skip to content

Commit 73d6be9

Browse files
authored
Merge pull request kubernetes#92166 from andyzhangx/GetLabelsForVolume-panic
fix: GetLabelsForVolume panic issue for azure disk PV
2 parents 37ec23c + d3a90d1 commit 73d6be9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/azure_managedDiskController.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ func (c *Cloud) GetAzureDiskLabels(diskURI string) (map[string]string, error) {
346346
return nil, err
347347
}
348348

349+
labels := map[string]string{
350+
v1.LabelZoneRegion: c.Location,
351+
}
352+
// no azure credential is set, return nil
353+
if c.DisksClient == nil {
354+
return labels, nil
355+
}
349356
// Get information of the disk.
350357
ctx, cancel := getContextWithCancel()
351358
defer cancel()
@@ -358,7 +365,7 @@ func (c *Cloud) GetAzureDiskLabels(diskURI string) (map[string]string, error) {
358365
// Check whether availability zone is specified.
359366
if disk.Zones == nil || len(*disk.Zones) == 0 {
360367
klog.V(4).Infof("Azure disk %q is not zoned", diskName)
361-
return nil, nil
368+
return labels, nil
362369
}
363370

364371
zones := *disk.Zones
@@ -369,9 +376,6 @@ func (c *Cloud) GetAzureDiskLabels(diskURI string) (map[string]string, error) {
369376

370377
zone := c.makeZone(c.Location, zoneID)
371378
klog.V(4).Infof("Got zone %q for Azure disk %q", zone, diskName)
372-
labels := map[string]string{
373-
v1.LabelZoneRegion: c.Location,
374-
v1.LabelZoneFailureDomain: zone,
375-
}
379+
labels[v1.LabelZoneFailureDomain] = zone
376380
return labels, nil
377381
}

0 commit comments

Comments
 (0)