mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #96705 from andyzhangx/resize-fix
fix: resize Azure disk issue when it's in attached state
This commit is contained in:
commit
7d72ddca6e
@ -297,6 +297,10 @@ func (c *ManagedDiskController) ResizeDisk(diskURI string, oldSize resource.Quan
|
||||
return newSizeQuant, nil
|
||||
}
|
||||
|
||||
if result.DiskProperties.DiskState != compute.Unattached {
|
||||
return oldSize, fmt.Errorf("azureDisk - disk resize is only supported on Unattached disk, current disk state: %s, already attached to %s", result.DiskProperties.DiskState, to.String(result.ManagedBy))
|
||||
}
|
||||
|
||||
diskParameter := compute.DiskUpdate{
|
||||
DiskUpdateProperties: &compute.DiskUpdateProperties{
|
||||
DiskSizeGB: &requestGiB,
|
||||
|
@ -311,7 +311,7 @@ func TestResizeDisk(t *testing.T) {
|
||||
diskName: diskName,
|
||||
oldSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
newSize: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
|
||||
existedDisk: compute.Disk{Name: to.StringPtr("disk1"), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB}},
|
||||
existedDisk: compute.Disk{Name: to.StringPtr("disk1"), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Unattached}},
|
||||
expectedQuantity: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
|
||||
expectedErr: false,
|
||||
},
|
||||
@ -330,7 +330,7 @@ func TestResizeDisk(t *testing.T) {
|
||||
diskName: diskName,
|
||||
oldSize: *resource.NewQuantity(1*(1024*1024*1024), resource.BinarySI),
|
||||
newSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
existedDisk: compute.Disk{Name: to.StringPtr("disk1"), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB}},
|
||||
existedDisk: compute.Disk{Name: to.StringPtr("disk1"), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Unattached}},
|
||||
expectedQuantity: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
expectedErr: false,
|
||||
},
|
||||
@ -339,7 +339,7 @@ func TestResizeDisk(t *testing.T) {
|
||||
diskName: fakeGetDiskFailed,
|
||||
oldSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
newSize: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
|
||||
existedDisk: compute.Disk{Name: to.StringPtr(fakeGetDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB}},
|
||||
existedDisk: compute.Disk{Name: to.StringPtr(fakeGetDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Unattached}},
|
||||
expectedQuantity: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
expectedErr: true,
|
||||
expectedErrMsg: fmt.Errorf("Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: Get Disk failed"),
|
||||
@ -349,11 +349,21 @@ func TestResizeDisk(t *testing.T) {
|
||||
diskName: fakeCreateDiskFailed,
|
||||
oldSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
newSize: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
|
||||
existedDisk: compute.Disk{Name: to.StringPtr(fakeCreateDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB}},
|
||||
existedDisk: compute.Disk{Name: to.StringPtr(fakeCreateDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Unattached}},
|
||||
expectedQuantity: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
expectedErr: true,
|
||||
expectedErrMsg: fmt.Errorf("Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: Create Disk failed"),
|
||||
},
|
||||
{
|
||||
desc: "an error shall be returned if disk is not in Unattached state",
|
||||
diskName: fakeCreateDiskFailed,
|
||||
oldSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
newSize: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
|
||||
existedDisk: compute.Disk{Name: to.StringPtr(fakeCreateDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Attached}},
|
||||
expectedQuantity: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
|
||||
expectedErr: true,
|
||||
expectedErrMsg: fmt.Errorf("azureDisk - disk resize is only supported on Unattached disk, current disk state: Attached, already attached to "),
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range testCases {
|
||||
|
Loading…
Reference in New Issue
Block a user