From e54ce8730c586288d52daf90b281e8c3250de8d3 Mon Sep 17 00:00:00 2001 From: Arashad Ahamad <42564459+arahamad@users.noreply.github.com> Date: Tue, 15 Sep 2020 13:01:24 +0530 Subject: [PATCH] stopping retry while volume and node not found (#207) * stopping retry while volume and node not found * changed method name to generic name * Remaned method name --- samples/attach_detach.go | 22 ++++++++++++++++--- samples/main.go | 4 +++- .../vpc/provider/attach_volume.go | 2 +- .../vpc/provider/detach_volume.go | 2 +- .../vpc/provider/get_volume_attachment.go | 4 ++-- volume-providers/vpc/provider/util.go | 7 ++++-- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/samples/attach_detach.go b/samples/attach_detach.go index 9262b8cb..c5ac820e 100644 --- a/samples/attach_detach.go +++ b/samples/attach_detach.go @@ -72,7 +72,24 @@ 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: ") @@ -80,14 +97,13 @@ func (vam *VolumeAttachmentManager) setupVolumeAttachmentRequest() { 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, }, } - } diff --git a/samples/main.go b/samples/main.go index 9cf06e61..c8656e81 100644 --- a/samples/main.go +++ b/samples/main.go @@ -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 @@ -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 { diff --git a/volume-providers/vpc/provider/attach_volume.go b/volume-providers/vpc/provider/attach_volume.go index 86e069ad..816497ff 100644 --- a/volume-providers/vpc/provider/attach_volume.go +++ b/volume-providers/vpc/provider/attach_volume.go @@ -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 diff --git a/volume-providers/vpc/provider/detach_volume.go b/volume-providers/vpc/provider/detach_volume.go index 1ba9a48b..2a67d8a4 100644 --- a/volume-providers/vpc/provider/detach_volume.go +++ b/volume-providers/vpc/provider/detach_volume.go @@ -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 diff --git a/volume-providers/vpc/provider/get_volume_attachment.go b/volume-providers/vpc/provider/get_volume_attachment.go index ec0e0a06..7669a854 100644 --- a/volume-providers/vpc/provider/get_volume_attachment.go +++ b/volume-providers/vpc/provider/get_volume_attachment.go @@ -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 }) @@ -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 }) diff --git a/volume-providers/vpc/provider/util.go b/volume-providers/vpc/provider/util.go index 5ddedaec..af374576 100644 --- a/volume-providers/vpc/provider/util.go +++ b/volume-providers/vpc/provider/util.go @@ -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 ... @@ -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)