Skip to content

Commit b2a1552

Browse files
committed
add volume check
1 parent c33708f commit b2a1552

8 files changed

Lines changed: 77 additions & 2 deletions

File tree

aws/aws.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,42 @@ func (s *awsOps) detachInternal(volumeID, instanceName string, options map[strin
942942
return err
943943
}
944944

945+
func (s *awsOps) getVolumeModificationState(volumeID string) (string, error) {
946+
modificationStateRequest := &ec2.DescribeVolumesModificationsInput{
947+
VolumeIds: []*string{&volumeID},
948+
}
949+
describeOutput, err := s.ec2.DescribeVolumesModifications(modificationStateRequest)
950+
if err != nil {
951+
return "", err
952+
}
953+
volumeModifications := describeOutput.VolumesModifications
954+
if len(volumeModifications) == 0 {
955+
return "", nil
956+
}
957+
958+
volumeModification := volumeModifications[len(volumeModifications)-1]
959+
state := *volumeModification.ModificationState
960+
return state, nil
961+
}
962+
963+
func (s *awsOps) IsVolumesReadyToExpand(volumeIDs []string) (bool, error) {
964+
for i := 0; i < len(volumeIDs); i++ {
965+
state, err := s.getVolumeModificationState(volumeIDs[i])
966+
if err != nil {
967+
return false, fmt.Errorf("unable to get modification state: #{err}. ")
968+
}
969+
// Empty string indicates there was no volume change
970+
if state == "" {
971+
return true, nil
972+
}
973+
if state == ec2.VolumeModificationStateModifying ||
974+
state == ec2.VolumeModificationStateOptimizing {
975+
return false, fmt.Errorf("the last modification has not fully completed. ")
976+
}
977+
}
978+
return true, nil
979+
}
980+
945981
func (s *awsOps) Expand(
946982
volumeID string,
947983
newSizeInGiB uint64,

azure/azure.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,12 @@ func (a *azureOps) DeleteFrom(diskName, _ string) error {
580580
return a.Delete(diskName, nil)
581581
}
582582

583+
func (a *azureOps) IsVolumesReadyToExpand(volumeIDs []string) (bool, error) {
584+
return true, &cloudops.ErrNotSupported{
585+
Operation: "IsVolumesReadyToExpand",
586+
}
587+
}
588+
583589
func (a *azureOps) Expand(
584590
diskName string,
585591
newSizeInGiB uint64,

backoff/exponential.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ func (e *exponentialBackoff) DevicePath(volumeID string) (string, error) {
436436
return devicePath, origErr
437437
}
438438

439+
func (e *exponentialBackoff) IsVolumesReadyToExpand(volumeIDs []string) (bool, error) {
440+
return true, &cloudops.ErrNotSupported{
441+
Operation: "IsVolumesReadyToExpand",
442+
}
443+
}
444+
439445
func (e *exponentialBackoff) Expand(volumeID string, targetSize uint64, options map[string]string) (uint64, error) {
440446
var (
441447
actualSize uint64

cloudops.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ type Storage interface {
129129
// Attach volumeID, accepts attachoOptions as opaque data
130130
// Return attach path.
131131
Attach(volumeID string, options map[string]string) (string, error)
132+
// IsVolumeReadyToExpand pre-checks if the volume is in a state that can be modified. Should be called
133+
// before issue an expand request to the cloud provider
134+
IsVolumesReadyToExpand(volumeIDs []string) (bool, error)
132135
// Expand expands the provided device from the existing size to the new size
133136
// It returns the new size of the device. It is a blocking API where it will
134137
// only return once the requested size is validated with the cloud provider or

gce/gce.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,11 @@ func (s *gceOps) GetDeviceID(disk interface{}) (string, error) {
664664
}
665665
}
666666

667+
func (s *gceOps) IsVolumesReadyToExpand(volumeIDs []string) (bool, error) {
668+
return true, &cloudops.ErrNotSupported{
669+
Operation: "IsVolumesReadyToExpand",
670+
}
671+
}
667672
func (s *gceOps) Expand(
668673
volumeID string,
669674
newSizeInGiB uint64,

oracle/oracle.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (o *oracleOps) GetInstance(displayName string) (interface{}, error) {
293293
if len(listInstanceResp.Items) == 0 {
294294
return nil, fmt.Errorf("no oracle instance found with display name: %s", displayName)
295295
}
296-
// Currently, torpedo uses this API to fetch details of the instance created
296+
// Currently, torpedo uses this API to fetch details of the instance created
297297
// by OKE. OKE ensures that all the worker nodes created, have unique display
298298
// names. In future, if we require to use this API to get details of vanilla
299299
// compute instances, then we can modify below array indexing.
@@ -829,6 +829,12 @@ func nodePoolContainsNode(s []containerengine.Node, e string) bool {
829829
return false
830830
}
831831

832+
func (o *oracleOps) IsVolumesReadyToExpand(volumeIDs []string) (bool, error) {
833+
return true, &cloudops.ErrNotSupported{
834+
Operation: "IsVolumesReadyToExpand",
835+
}
836+
}
837+
832838
func (o *oracleOps) Expand(volumeID string, newSizeInGiB uint64, options map[string]string) (uint64, error) {
833839
logrus.Debug("Expand volume to size ", newSizeInGiB, " GiB")
834840

unsupported/unsupported.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ func (u *unsupportedStorage) Attach(volumeID string, options map[string]string)
9999
Operation: "Attach",
100100
}
101101
}
102+
103+
func (u *unsupportedStorage) IsVolumesReadyToExpand(volumeIDs []string) (bool, error) {
104+
return true, &cloudops.ErrNotSupported{
105+
Operation: "IsVolumesReadyToExpand",
106+
}
107+
}
108+
102109
func (u *unsupportedStorage) Expand(volumeID string, newSizeInGiB uint64, options map[string]string) (uint64, error) {
103110
return 0, &cloudops.ErrNotSupported{
104111
Operation: "Expand",

vsphere/vsphere.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func (ops *vsphereOps) DeviceMappings() (map[string]string, error) {
476476
if ok {
477477
diskUUID, err := vmObj.Datacenter.GetVirtualDiskPage83Data(ctx, backing.FileName)
478478
if err != nil {
479-
vmName,_ := vmObj.ObjectName(ctx)
479+
vmName, _ := vmObj.ObjectName(ctx)
480480
return nil, fmt.Errorf("failed to get device path for disk: %s on vm: %s err: %s", backing.FileName, vmName, err)
481481
}
482482

@@ -533,6 +533,12 @@ func (ops *vsphereOps) Enumerate(volumeIds []*string,
533533
}
534534
}
535535

536+
func (ops *vsphereOps) IsVolumesReadyToExpand(volumeIDs []string) (bool, error) {
537+
return true, &cloudops.ErrNotSupported{
538+
Operation: "IsVolumesReadyToExpand",
539+
}
540+
}
541+
536542
func (ops *vsphereOps) Expand(
537543
vmdkPath string,
538544
newSizeInGiB uint64,

0 commit comments

Comments
 (0)