Skip to content

Commit a056882

Browse files
authored
Merge pull request #127 from alicelyu-px/volumeStateCheck
Add modification state check functionality
2 parents 54c7246 + 8434f3c commit a056882

9 files changed

Lines changed: 92 additions & 2 deletions

File tree

aws/aws.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
awsDevicePrefixWithH = "/dev/hd"
3535
awsDevicePrefixNvme = "/dev/nvme"
3636
contextTimeout = 30 * time.Second
37+
awsErrorModificationNotFound = "InvalidVolumeModification.NotFound"
3738
)
3839

3940
type awsOps struct {
@@ -942,6 +943,42 @@ func (s *awsOps) detachInternal(volumeID, instanceName string, options map[strin
942943
return err
943944
}
944945

946+
func isErrorModificationNotFound(err error) bool {
947+
return strings.HasPrefix(err.Error(), awsErrorModificationNotFound)
948+
}
949+
950+
func (s *awsOps) AreVolumesReadyToExpand(volumeIDs []*string) (bool, error) {
951+
modificationStateRequest := &ec2.DescribeVolumesModificationsInput{
952+
VolumeIds: volumeIDs,
953+
}
954+
describeOutput, err := s.ec2.DescribeVolumesModifications(modificationStateRequest)
955+
if err != nil {
956+
// modification state not found, this indicates no change has occurred before.
957+
if isErrorModificationNotFound(err) {
958+
return true, nil
959+
}
960+
return false, fmt.Errorf("unable to get modification states for aws volumes: %v", err)
961+
}
962+
states := describeOutput.VolumesModifications
963+
964+
var state string
965+
for i := 0; i < len(states); i++ {
966+
if states[i] == nil || states[i].ModificationState == nil {
967+
logrus.Debugf("volume modification state is nil for volume id: %s", *volumeIDs[i])
968+
continue
969+
}
970+
971+
state = *states[i].ModificationState
972+
logrus.Infof("retrived volume modification state: %s for volume id: %s", state, *volumeIDs[i])
973+
if state == ec2.VolumeModificationStateModifying ||
974+
state == ec2.VolumeModificationStateOptimizing {
975+
return false, fmt.Errorf("aws has not fully completed the last modification: " +
976+
"volume %s is in %s state. please retry later", *volumeIDs[i], state)
977+
}
978+
}
979+
return true, nil
980+
}
981+
945982
func (s *awsOps) Expand(
946983
volumeID string,
947984
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) AreVolumesReadyToExpand(volumeIDs []*string) (bool, error) {
584+
return true, &cloudops.ErrNotSupported{
585+
Operation: "azureOps.IsVolumesReadyToExpand",
586+
}
587+
}
588+
583589
func (a *azureOps) Expand(
584590
diskName string,
585591
newSizeInGiB uint64,

backoff/exponential.go

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

439+
func (e *exponentialBackoff) AreVolumesReadyToExpand(volumeIDs []*string) (bool, error) {
440+
return e.cloudOps.AreVolumesReadyToExpand(volumeIDs)
441+
}
442+
439443
func (e *exponentialBackoff) Expand(volumeID string, targetSize uint64, options map[string]string) (uint64, error) {
440444
var (
441445
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 a pool of volumes are in a state that can
133+
// be modified. Should be called before sending an expand request to the cloud provider.
134+
AreVolumesReadyToExpand(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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,12 @@ func (s *gceOps) GetDeviceID(disk interface{}) (string, error) {
664664
}
665665
}
666666

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

mock/cloudops.mock.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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: "oracleOps: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: "unsupportedStorage: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: "vsphereOps:IsVolumesReadyToExpand",
539+
}
540+
}
541+
536542
func (ops *vsphereOps) Expand(
537543
vmdkPath string,
538544
newSizeInGiB uint64,

0 commit comments

Comments
 (0)