Skip to content

Commit

Permalink
stopping retry while volume and node not found (#207)
Browse files Browse the repository at this point in the history
* stopping retry while volume and node not found

* changed method name to generic name

* Remaned method name
  • Loading branch information
arahamad-zz authored Sep 15, 2020
1 parent 712b9e4 commit e54ce87
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
22 changes: 19 additions & 3 deletions samples/attach_detach.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,38 @@ func (vam *VolumeAttachmentManager) DetachVolume() {
fmt.Println("Volume attachment", response, err)
}

// VolumeAttachment ...
func (vam *VolumeAttachmentManager) VolumeAttachment() {
fmt.Println("You selected to get volume atatchment detail")
vam.setupVolumeAttachmentRequest()
response, err := vam.Session.GetVolumeAttachment(volumeAttachmentReq)
if err != nil {
updateRequestID(err, vam.RequestID)
vam.Logger.Error("Failed to get volume attachment", zap.Error(err))
return
}

fmt.Println("Volume attachment details", response, err)
}

func (vam *VolumeAttachmentManager) setupVolumeAttachmentRequest() {
var volumeID string
var instanceID string
var clusterID string
fmt.Printf("Enter the volume id: ")
_, _ = fmt.Scanf("%s", &volumeID)
fmt.Printf("Enter the instance id: ")
_, _ = fmt.Scanf("%s", &instanceID)
fmt.Printf("Enter the cluster id: ")
_, _ = fmt.Scanf("%s", &clusterID)
volumeAttachmentReq = provider.VolumeAttachmentRequest{
VolumeID: *volumeID,
VolumeID: volumeID,
InstanceID: instanceID,
VPCVolumeAttachment: &provider.VolumeAttachment{
DeleteVolumeOnInstanceDelete: false,
},
IKSVolumeAttachment: &provider.IKSVolumeAttachment{
ClusterID: clusterID,
ClusterID: &clusterID,
},
}

}
4 changes: 3 additions & 1 deletion samples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func main() {
valid := true
for valid {

fmt.Println("\n\nSelect your choice\n 1- Get volume details \n 2- Create snapshot \n 3- list snapshot \n 4- Create volume \n 5- Snapshot details \n 6- Snapshot Order \n 7- Create volume from snapshot\n 8- Delete volume \n 9- Delete Snapshot \n 10- List all Snapshot \n 12- Authorize volume \n 13- Create VPC Volume \n 14- Create VPC Snapshot \n 15- Attach VPC volume \n 16- Detach VPC volume \n 17- Get volume by name \n 18- List volumes \n Your choice?:")
fmt.Println("\n\nSelect your choice\n 1- Get volume details \n 2- Create snapshot \n 3- list snapshot \n 4- Create volume \n 5- Snapshot details \n 6- Snapshot Order \n 7- Create volume from snapshot\n 8- Delete volume \n 9- Delete Snapshot \n 10- List all Snapshot \n 12- Authorize volume \n 13- Create VPC Volume \n 14- Create VPC Snapshot \n 15- Attach VPC volume \n 16- Detach VPC volume \n 17- Get volume by name \n 18- List volumes \n 19- Get volume Attachment \nYour choice?:")

var choiceN int
var volumeID string
Expand Down Expand Up @@ -492,6 +492,8 @@ func main() {
}
fmt.Printf("\n\n")
} else if choiceN == 19 {
volumeAttachmentManager.VolumeAttachment()
} else if choiceN == 20 {
volumeManager.UpdateVolume()
os.Exit(0)
} else {
Expand Down
2 changes: 1 addition & 1 deletion volume-providers/vpc/provider/attach_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (vpcs *VPCSession) AttachVolume(volumeAttachmentRequest provider.VolumeAtta
volumeAttachResult, err = vpcs.APIClientVolAttachMgr.AttachVolume(&volumeAttachment, vpcs.Logger)
// Keep retry, until we get the proper volumeAttachResult object
if err != nil {
return err, skipRetryForAttach(err, vpcs.Config.IsIKS)
return err, skipRetryForObviousErrors(err, vpcs.Config.IsIKS)
}
varp = volumeAttachResult.ToVolumeAttachmentResponse(vpcs.Config.VPCBlockProviderType)
return err, true // stop retry as no error
Expand Down
2 changes: 1 addition & 1 deletion volume-providers/vpc/provider/detach_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (vpcs *VPCSession) DetachVolume(volumeAttachmentTemplate provider.VolumeAtt
volumeAttachment.ID = currentVolAttachment.VPCVolumeAttachment.ID
vpcs.Logger.Info("Detaching volume from VPC provider...")
response, err = vpcs.APIClientVolAttachMgr.DetachVolume(&volumeAttachment, vpcs.Logger)
return err, err == nil // Retry in case of all errors
return err, skipRetryForObviousErrors(err, vpcs.Config.IsIKS)
}
vpcs.Logger.Info("No volume attachment found for", zap.Reflect("currentVolAttachment", currentVolAttachment), zap.Error(err))
// consider volume detach success if its already in Detaching or VolumeAttachment is not found
Expand Down
4 changes: 2 additions & 2 deletions volume-providers/vpc/provider/get_volume_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (vpcs *VPCSession) getVolumeAttachmentByID(volumeAttachmentRequest models.V
volumeAttachmentResult, err = vpcs.APIClientVolAttachMgr.GetVolumeAttachment(&volumeAttachmentRequest, vpcs.Logger)
// Keep retry, until we get the proper volumeAttachmentRequest object
if err != nil {
return err, skipRetryForAttach(err, vpcs.Config.IsIKS)
return err, skipRetryForObviousErrors(err, vpcs.Config.IsIKS)
}
return err, true // stop retry as no error
})
Expand All @@ -83,7 +83,7 @@ func (vpcs *VPCSession) getVolumeAttachmentByVolumeID(volumeAttachmentRequest mo
volumeAttachmentList, err = vpcs.APIClientVolAttachMgr.ListVolumeAttachments(&volumeAttachmentRequest, vpcs.Logger)
// Keep retry, until we get the proper volumeAttachmentRequest object
if err != nil {
return err, skipRetryForAttach(err, vpcs.Config.IsIKS)
return err, skipRetryForObviousErrors(err, vpcs.Config.IsIKS)
}
return err, true // stop retry as no error
})
Expand Down
7 changes: 5 additions & 2 deletions volume-providers/vpc/provider/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ var skipErrorCodes = map[string]bool{
"ST0014": true, // Required parameter missing or invalid
"ST0015": true, // Required parameter missing
"ST0016": true, // Tagging failed .. Do not repeat
"P4106": true, // Instnace not found
"P4107": true, // Volume not found
"P4109": true, // Volume attachment not found
}

// retry ...
Expand Down Expand Up @@ -112,8 +115,8 @@ func SkipRetryForIKS(err error) bool {
return false
}

// skipRetryForAttach skip retry as per listed error codes
func skipRetryForAttach(err error, isIKS bool) bool {
// skipRetryForObviousErrors skip retry as per listed error codes
func skipRetryForObviousErrors(err error, isIKS bool) bool {
// Only for storage-api ms related calls error
if isIKS {
return SkipRetryForIKS(err)
Expand Down

0 comments on commit e54ce87

Please sign in to comment.