Skip to content

Commit b20f185

Browse files
authoredMar 16, 2025··
Merge pull request #2939 from k8s-infra-cherrypick-robot/cherry-pick-2934-to-release-1.30
[release-1.30] fix: avoid get disk call in disk creation
2 parents 477e708 + 43decce commit b20f185

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed
 

‎pkg/azuredisk/azure_managedDiskController.go

+27-26
Original file line numberDiff line numberDiff line change
@@ -272,39 +272,40 @@ func (c *ManagedDiskController) CreateManagedDisk(ctx context.Context, options *
272272
if err != nil {
273273
return "", err
274274
}
275-
if _, err := diskClient.CreateOrUpdate(ctx, rg, options.DiskName, model); err != nil {
276-
return "", err
277-
}
278275

279276
diskID := fmt.Sprintf(managedDiskPath, subsID, rg, options.DiskName)
277+
disk, err := diskClient.CreateOrUpdate(ctx, rg, options.DiskName, model)
278+
if err != nil {
279+
return "", err
280+
}
280281

281-
if options.SkipGetDiskOperation {
282-
klog.Warningf("azureDisk - GetDisk(%s, StorageAccountType:%s) is throttled, unable to confirm provisioningState in poll process", options.DiskName, options.StorageAccountType)
283-
} else {
284-
err = kwait.ExponentialBackoffWithContext(ctx, defaultBackOff, func(_ context.Context) (bool, error) {
285-
provisionState, id, err := c.GetDisk(ctx, subsID, rg, options.DiskName)
286-
if err == nil {
287-
if id != "" {
288-
diskID = id
289-
}
290-
} else {
291-
// We are waiting for provisioningState==Succeeded
292-
// We don't want to hand-off managed disks to k8s while they are
293-
//still being provisioned, this is to avoid some race conditions
294-
return false, err
295-
}
296-
if strings.ToLower(provisionState) == "succeeded" {
297-
return true, nil
282+
err = kwait.ExponentialBackoffWithContext(ctx, defaultBackOff, func(_ context.Context) (bool, error) {
283+
if disk != nil && disk.Properties != nil && disk.Properties.ProvisioningState != nil && strings.EqualFold(*disk.Properties.ProvisioningState, "succeeded") {
284+
if disk.ID != nil && *disk.ID != "" {
285+
diskID = *disk.ID
298286
}
299-
return false, nil
300-
})
287+
return true, nil
288+
}
301289

302-
if err != nil {
303-
klog.Warningf("azureDisk - created new MD Name:%s StorageAccountType:%s Size:%v but was unable to confirm provisioningState in poll process", options.DiskName, options.StorageAccountType, options.SizeGB)
290+
if options.SkipGetDiskOperation {
291+
klog.Warningf("azureDisk - GetDisk(%s, StorageAccountType:%s) is throttled, unable to confirm provisioningState in poll process", options.DiskName, options.StorageAccountType)
292+
return true, nil
304293
}
305-
}
294+
klog.V(4).Infof("azureDisk - waiting for disk(%s) in resourceGroup(%s) to be provisioned", options.DiskName, rg)
295+
if disk, err = diskClient.Get(ctx, rg, options.DiskName); err != nil {
296+
// We are waiting for provisioningState==Succeeded
297+
// We don't want to hand-off managed disks to k8s while they are
298+
//still being provisioned, this is to avoid some race conditions
299+
return false, err
300+
}
301+
return false, nil
302+
})
306303

307-
klog.V(2).Infof("azureDisk - created new MD Name:%s StorageAccountType:%s Size:%v", options.DiskName, options.StorageAccountType, options.SizeGB)
304+
if err != nil {
305+
klog.Warningf("azureDisk - created new MD Name:%s StorageAccountType:%s Size:%v but was unable to confirm provisioningState in poll process", options.DiskName, options.StorageAccountType, options.SizeGB)
306+
} else {
307+
klog.V(2).Infof("azureDisk - created new MD Name:%s StorageAccountType:%s Size:%v", options.DiskName, options.StorageAccountType, options.SizeGB)
308+
}
308309
return diskID, nil
309310
}
310311

0 commit comments

Comments
 (0)
Please sign in to comment.