Change:
} } } <ins> func TestCheckDiskExists(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() ctx, cancel := getContextWithCancel() defer cancel() testCloud := GetTestCloud(ctrl) common := &controllerCommon{ location:              testCloud.Location, storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix, resourceGroup:         testCloud.ResourceGroup, subscriptionID:        testCloud.SubscriptionID, cloud:                 testCloud, vmLockMap:             newLockMap(), } // create a new disk before running test newDiskName := "newdisk" newDiskURI := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/%s", testCloud.SubscriptionID, testCloud.ResourceGroup, newDiskName) fDC := newFakeDisksClient() rerr := fDC.CreateOrUpdate(ctx, testCloud.ResourceGroup, newDiskName, compute.Disk{}) assert.Equal(t, rerr == nil, true, "return error: %v", rerr) testCloud.DisksClient = fDC testCases := []struct { diskURI        string expectedResult bool expectedErr    bool }{ { diskURI:        "incorrect disk URI format", expectedResult: false, expectedErr:    true, }, { diskURI:        "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Compute/disks/non-existing-disk", expectedResult: false, expectedErr:    false, }, { diskURI:        newDiskURI, expectedResult: true, expectedErr:    false, }, } for i, test := range testCases { exist, err := common.checkDiskExists(ctx, test.diskURI) assert.Equal(t, test.expectedResult, exist, "TestCase[%d]", i, exist) assert.Equal(t, test.expectedErr, err != nil, "TestCase[%d], return error: %v", i, err) } } func TestFilterNonExistingDisks(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() ctx, cancel := getContextWithCancel() defer cancel() testCloud := GetTestCloud(ctrl) common := &controllerCommon{ location:              testCloud.Location, storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix, resourceGroup:         testCloud.ResourceGroup, subscriptionID:        testCloud.SubscriptionID, cloud:                 testCloud, vmLockMap:             newLockMap(), } // create a new disk before running test diskURIPrefix := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/", testCloud.SubscriptionID, testCloud.ResourceGroup) newDiskName := "newdisk" newDiskURI := diskURIPrefix + newDiskName fDC := newFakeDisksClient() rerr := fDC.CreateOrUpdate(ctx, testCloud.ResourceGroup, newDiskName, compute.Disk{}) assert.Equal(t, rerr == nil, true, "return error: %v", rerr) testCloud.DisksClient = fDC disks := []compute.DataDisk{ { Name: &newDiskName, ManagedDisk: &compute.ManagedDiskParameters{ ID: &newDiskURI, }, }, { Name: pointer.StringPtr("DiskName2"), ManagedDisk: &compute.ManagedDiskParameters{ ID: pointer.StringPtr(diskURIPrefix + "DiskName2"), }, }, { Name: pointer.StringPtr("DiskName3"), ManagedDisk: &compute.ManagedDiskParameters{ ID: pointer.StringPtr(diskURIPrefix + "DiskName3"), }, }, { Name: pointer.StringPtr("DiskName4"), ManagedDisk: &compute.ManagedDiskParameters{ ID: pointer.StringPtr(diskURIPrefix + "DiskName4"), }, }, } filteredDisks := common.filterNonExistingDisks(ctx, disks) assert.Equal(t, 1, len(filteredDisks)) assert.Equal(t, newDiskName, *filteredDisks[0].Name) disks = []compute.DataDisk{} filteredDisks = filterDetachingDisks(disks) assert.Equal(t, 0, len(filteredDisks)) } </ins>

Discussion:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: check disk status before disk azure disk There is little possibility that attach disk would cost 10min, and disk could be attached, deleted in same time, that would cause race condition. What you expected to happen: How to reproduce it (as minimally and precisely as possible): Anything else we need to know?: Environment: Kubernetes version (use ): Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others: /kind bug /assign /priority important-soon /sig cloud-provider /area provider/azure