From 3e2fa12215f95f40aabd9ef5910b2ef8744c4465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Mon, 1 Jun 2020 15:28:54 +0200 Subject: [PATCH 1/9] feat: add configurable retryInterval and timeout --- api/baremetal/v1alpha1/server_utils.go | 47 ++++++++++----- api/instance/v1/image_utils.go | 20 ++++--- api/instance/v1/server_utils.go | 26 ++++---- api/instance/v1/server_utils_test.go | 2 +- api/instance/v1/snapshot_utils.go | 20 ++++--- api/instance/v1/volume_utils.go | 20 ++++--- api/k8s/v1/k8s_helpers.go | 81 ++++++++++++++----------- api/k8s/v1beta3/k8s_helpers.go | 27 +++++++-- api/k8s/v1beta4/k8s_helpers.go | 82 +++++++++++++++----------- api/lb/v1/lb_utils.go | 25 ++++++-- api/rdb/v1/rdb_utils.go | 25 ++++++-- 11 files changed, 239 insertions(+), 136 deletions(-) diff --git a/api/baremetal/v1alpha1/server_utils.go b/api/baremetal/v1alpha1/server_utils.go index 07acbb2ef..6df64bfd6 100644 --- a/api/baremetal/v1alpha1/server_utils.go +++ b/api/baremetal/v1alpha1/server_utils.go @@ -8,26 +8,31 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" ) -var ( - // RetryInterval is needed when running recorded tests (e.g. on scaleway-cli) - // it allows to execute the WaitFor funcs immediately - RetryInterval = defaultRetryInterval -) - const ( defaultRetryInterval = 15 * time.Second + defaultTimeout = 2 * time.Hour ) // WaitForServerRequest is used by WaitForServer method. type WaitForServerRequest struct { - ServerID string - Zone scw.Zone - Timeout time.Duration + ServerID string + Zone scw.Zone + Timeout time.Duration + RetryInterval time.Duration } // WaitForServer wait for the server to be in a "terminal state" before returning. // This function can be used to wait for a server to be created. func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = defaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[ServerStatus]struct{}{ ServerStatusReady: {}, ServerStatusStopped: {}, @@ -49,8 +54,8 @@ func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { _, isTerminal := terminalStatus[res.Status] return res, isTerminal, err }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for server failed") @@ -61,15 +66,25 @@ func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { // WaitForServerInstallRequest is used by WaitForServerInstall method. type WaitForServerInstallRequest struct { - ServerID string - Zone scw.Zone - Timeout time.Duration + ServerID string + Zone scw.Zone + Timeout time.Duration + RetryInterval time.Duration } // WaitForServerInstall wait for the server install to be in a // "terminal state" before returning. // This function can be used to wait for a server to be installed. func (s *API) WaitForServerInstall(req *WaitForServerInstallRequest) (*Server, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = defaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + installTerminalStatus := map[ServerInstallStatus]struct{}{ ServerInstallStatusCompleted: {}, ServerInstallStatusError: {}, @@ -93,8 +108,8 @@ func (s *API) WaitForServerInstall(req *WaitForServerInstallRequest) (*Server, e _, isTerminal := installTerminalStatus[res.Install.Status] return res, isTerminal, err }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for server installation failed") diff --git a/api/instance/v1/image_utils.go b/api/instance/v1/image_utils.go index 681d220c4..d73bb8b0e 100644 --- a/api/instance/v1/image_utils.go +++ b/api/instance/v1/image_utils.go @@ -10,15 +10,21 @@ import ( // WaitForImageRequest is used by WaitForImage method. type WaitForImageRequest struct { - ImageID string - Zone scw.Zone - Timeout time.Duration + ImageID string + Zone scw.Zone + Timeout time.Duration + RetryInterval time.Duration } // WaitForImage wait for the image to be in a "terminal state" before returning. func (s *API) WaitForImage(req *WaitForImageRequest) (*Image, error) { - if req.Timeout == 0 { - req.Timeout = defaultTimeout + timeout := req.Timeout + if timeout == 0 { + timeout = defaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval } terminalStatus := map[ImageState]struct{}{ @@ -40,8 +46,8 @@ func (s *API) WaitForImage(req *WaitForImageRequest) (*Image, error) { return res.Image, isTerminal, err }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for image failed") diff --git a/api/instance/v1/server_utils.go b/api/instance/v1/server_utils.go index 66c352939..5427f07b2 100644 --- a/api/instance/v1/server_utils.go +++ b/api/instance/v1/server_utils.go @@ -19,10 +19,6 @@ const ( defaultRetryInterval = 5 * time.Second ) -var ( - RetryInterval = defaultRetryInterval -) - // CreateServer creates a server. func (s *API) CreateServer(req *CreateServerRequest, opts ...scw.RequestOption) (*CreateServerResponse, error) { // If image is not a UUID we try to fetch it from marketplace. @@ -52,14 +48,23 @@ func (s *API) UpdateServer(req *UpdateServerRequest, opts ...scw.RequestOption) // WaitForServerRequest is used by WaitForServer method. type WaitForServerRequest struct { - ServerID string - Zone scw.Zone - Timeout time.Duration + ServerID string + Zone scw.Zone + Timeout time.Duration + RetryInterval time.Duration } // WaitForServer wait for the server to be in a "terminal state" before returning. // This function can be used to wait for a server to be started for example. func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = defaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } terminalStatus := map[ServerState]struct{}{ ServerStateStopped: {}, ServerStateStoppedInPlace: {}, @@ -81,8 +86,8 @@ func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { return res.Server, isTerminal, err }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for server failed") @@ -97,7 +102,8 @@ type ServerActionAndWaitRequest struct { Action ServerAction // Timeout: maximum time to wait before (default: 5 minutes) - Timeout time.Duration + Timeout time.Duration + RetryInterval time.Duration } // ServerActionAndWait start an action and wait for the server to be in the correct "terminal state" diff --git a/api/instance/v1/server_utils_test.go b/api/instance/v1/server_utils_test.go index 39ba9c7df..f9eac6dde 100644 --- a/api/instance/v1/server_utils_test.go +++ b/api/instance/v1/server_utils_test.go @@ -16,7 +16,7 @@ import ( func init() { // set interval strategy to 0 when replaying cassettes if httprecorder.IsUpdatingCassette() { - RetryInterval = 0 + } } diff --git a/api/instance/v1/snapshot_utils.go b/api/instance/v1/snapshot_utils.go index fb5068d90..a058f1cd3 100644 --- a/api/instance/v1/snapshot_utils.go +++ b/api/instance/v1/snapshot_utils.go @@ -10,15 +10,21 @@ import ( // WaitForImageRequest is used by WaitForImage method. type WaitForSnapshotRequest struct { - SnapshotID string - Zone scw.Zone - Timeout time.Duration + SnapshotID string + Zone scw.Zone + Timeout time.Duration + RetryInterval time.Duration } // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning. func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest) (*Snapshot, error) { - if req.Timeout == 0 { - req.Timeout = defaultTimeout + timeout := req.Timeout + if timeout == 0 { + timeout = defaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval } terminalStatus := map[SnapshotState]struct{}{ @@ -40,8 +46,8 @@ func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest) (*Snapshot, error) { return res.Snapshot, isTerminal, err }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for snapshot failed") diff --git a/api/instance/v1/volume_utils.go b/api/instance/v1/volume_utils.go index 0690ff209..92b41d48d 100644 --- a/api/instance/v1/volume_utils.go +++ b/api/instance/v1/volume_utils.go @@ -10,15 +10,21 @@ import ( // WaitForImageRequest is used by WaitForImage method. type WaitForVolumeRequest struct { - VolumeID string - Zone scw.Zone - Timeout time.Duration + VolumeID string + Zone scw.Zone + Timeout time.Duration + RetryInterval time.Duration } // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning. func (s *API) WaitForVolume(req *WaitForVolumeRequest) (*Volume, error) { - if req.Timeout == 0 { - req.Timeout = defaultTimeout + timeout := req.Timeout + if timeout == 0 { + timeout = defaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval } terminalStatus := map[VolumeState]struct{}{ @@ -40,8 +46,8 @@ func (s *API) WaitForVolume(req *WaitForVolumeRequest) (*Volume, error) { return res.Volume, isTerminal, err }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for volume failed") diff --git a/api/k8s/v1/k8s_helpers.go b/api/k8s/v1/k8s_helpers.go index 6ed362ca6..fb094817d 100644 --- a/api/k8s/v1/k8s_helpers.go +++ b/api/k8s/v1/k8s_helpers.go @@ -8,32 +8,31 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" ) -var ( - // RetryInterval is needed when running recorded tests (e.g. on scaleway-cli) - // it allows to execute the WaitFor funcs immediately - RetryInterval = defaultRetryInterval -) - const ( - waitForClusterDefaultTimeout = time.Minute * 15 - waitForPoolDefaultTimeout = time.Minute * 15 - waitForNodeDefaultTimeout = time.Minute * 15 - defaultRetryInterval = time.Second * 5 + waitForClusterDefaultTimeout = 15 * time.Minute + waitForPoolDefaultTimeout = 15 * time.Minute + waitForNodeDefaultTimeout = 15 * time.Minute + defaultRetryInterval = 5 * time.Second ) // WaitForClusterRequest is used by WaitForCluster method. type WaitForClusterRequest struct { - ClusterID string - Region scw.Region - Status ClusterStatus - Timeout *time.Duration + ClusterID string + Region scw.Region + Status ClusterStatus + Timeout time.Duration + RetryInterval time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { - timeout := waitForClusterDefaultTimeout - if req.Timeout != nil { - timeout = *req.Timeout + timeout := req.Timeout + if timeout == 0 { + timeout = waitForClusterDefaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval } terminalStatus := map[ClusterStatus]struct{}{ ClusterStatusReady: {}, @@ -56,7 +55,7 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { return cluster, isTerminal, nil }, Timeout: timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for cluster failed") @@ -67,23 +66,28 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { // WaitForPoolRequest is used by WaitForPool method. type WaitForPoolRequest struct { - PoolID string - Region scw.Region - Timeout *time.Duration + PoolID string + Region scw.Region + Timeout time.Duration + RetryInterval time.Duration } // WaitForPool waits for a pool to be ready func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = waitForPoolDefaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[PoolStatus]struct{}{ PoolStatusReady: {}, PoolStatusWarning: {}, } - timeout := waitForPoolDefaultTimeout - if req.Timeout != nil { - timeout = *req.Timeout - } - pool, err := async.WaitSync(&async.WaitSyncConfig{ Get: func() (interface{}, bool, error) { res, err := s.GetPool(&GetPoolRequest{ @@ -99,7 +103,7 @@ func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { return res, isTerminal, nil }, Timeout: timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for pool failed") @@ -110,23 +114,28 @@ func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { // WaitForNodeRequest is used by WaitForNode method. type WaitForNodeRequest struct { - NodeID string - Region scw.Region - Timeout *time.Duration + NodeID string + Region scw.Region + Timeout time.Duration + RetryInterval time.Duration } // WaitForNode waits for a Node to be ready func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = waitForNodeDefaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[NodeStatus]struct{}{ NodeStatusCreationError: {}, NodeStatusReady: {}, } - timeout := waitForNodeDefaultTimeout - if req.Timeout != nil { - timeout = *req.Timeout - } - node, err := async.WaitSync(&async.WaitSyncConfig{ Get: func() (interface{}, bool, error) { res, err := s.GetNode(&GetNodeRequest{ @@ -142,7 +151,7 @@ func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { return res, isTerminal, nil }, Timeout: timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for node failed") diff --git a/api/k8s/v1beta3/k8s_helpers.go b/api/k8s/v1beta3/k8s_helpers.go index 66ae31d87..311aba007 100644 --- a/api/k8s/v1beta3/k8s_helpers.go +++ b/api/k8s/v1beta3/k8s_helpers.go @@ -8,16 +8,31 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" ) +const ( + waitForClusterDefaultTimeout = 15 * time.Minute + defaultRetryInterval = 5 * time.Second +) + // WaitForClusterRequest is used by WaitForCluster method. type WaitForClusterRequest struct { - ClusterID string - Region scw.Region - Status ClusterStatus - Timeout time.Duration + ClusterID string + Region scw.Region + Status ClusterStatus + Timeout time.Duration + RetryInterval time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = waitForClusterDefaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[ClusterStatus]struct{}{ ClusterStatusReady: {}, ClusterStatusError: {}, @@ -39,8 +54,8 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { _, isTerminal := terminalStatus[cluster.Status] return cluster, isTerminal, nil }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(5 * time.Second), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for cluster failed") diff --git a/api/k8s/v1beta4/k8s_helpers.go b/api/k8s/v1beta4/k8s_helpers.go index 73a7e0a9b..36533acc0 100644 --- a/api/k8s/v1beta4/k8s_helpers.go +++ b/api/k8s/v1beta4/k8s_helpers.go @@ -8,33 +8,33 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" ) -var ( - // RetryInterval is needed when running recorded tests (e.g. on scaleway-cli) - // it allows to execute the WaitFor funcs immediately - RetryInterval = defaultRetryInterval -) - const ( - waitForClusterDefaultTimeout = time.Minute * 15 - waitForPoolDefaultTimeout = time.Minute * 15 - waitForNodeDefaultTimeout = time.Minute * 15 - defaultRetryInterval = time.Second * 5 + waitForClusterDefaultTimeout = 15 * time.Minute + waitForPoolDefaultTimeout = 15 * time.Minute + waitForNodeDefaultTimeout = 15 * time.Minute + defaultRetryInterval = 5 * time.Second ) // WaitForClusterRequest is used by WaitForCluster method. type WaitForClusterRequest struct { - ClusterID string - Region scw.Region - Status ClusterStatus - Timeout *time.Duration + ClusterID string + Region scw.Region + Status ClusterStatus + Timeout time.Duration + RetryInterval time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { - timeout := waitForClusterDefaultTimeout - if req.Timeout != nil { - timeout = *req.Timeout + timeout := req.Timeout + if timeout == 0 { + timeout = waitForClusterDefaultTimeout } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[ClusterStatus]struct{}{ ClusterStatusReady: {}, ClusterStatusError: {}, @@ -57,7 +57,7 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { return cluster, isTerminal, nil }, Timeout: timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for cluster failed") @@ -67,23 +67,28 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { // WaitForPoolRequest is used by WaitForPool method. type WaitForPoolRequest struct { - PoolID string - Region scw.Region - Timeout *time.Duration + PoolID string + Region scw.Region + Timeout time.Duration + RetryInterval time.Duration } // WaitForPool waits for a pool to be ready func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = waitForPoolDefaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[PoolStatus]struct{}{ PoolStatusReady: {}, PoolStatusWarning: {}, } - timeout := waitForPoolDefaultTimeout - if req.Timeout != nil { - timeout = *req.Timeout - } - pool, err := async.WaitSync(&async.WaitSyncConfig{ Get: func() (interface{}, bool, error) { res, err := s.GetPool(&GetPoolRequest{ @@ -99,7 +104,7 @@ func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { return res, isTerminal, nil }, Timeout: timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) return pool.(*Pool), err @@ -107,23 +112,28 @@ func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { // WaitForNodeRequest is used by WaitForNode method. type WaitForNodeRequest struct { - NodeID string - Region scw.Region - Timeout *time.Duration + NodeID string + Region scw.Region + Timeout time.Duration + RetryInterval time.Duration } // WaitForNode waits for a Node to be ready func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = waitForNodeDefaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[NodeStatus]struct{}{ NodeStatusCreationError: {}, NodeStatusReady: {}, } - timeout := waitForNodeDefaultTimeout - if req.Timeout != nil { - timeout = *req.Timeout - } - node, err := async.WaitSync(&async.WaitSyncConfig{ Get: func() (interface{}, bool, error) { res, err := s.GetNode(&GetNodeRequest{ @@ -139,7 +149,7 @@ func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { return res, isTerminal, nil }, Timeout: timeout, - IntervalStrategy: async.LinearIntervalStrategy(RetryInterval), + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) return node.(*Node), err diff --git a/api/lb/v1/lb_utils.go b/api/lb/v1/lb_utils.go index 6e5d60a72..c8893da23 100644 --- a/api/lb/v1/lb_utils.go +++ b/api/lb/v1/lb_utils.go @@ -8,16 +8,31 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" ) +const ( + defaultRetryInterval = 2 * time.Second + defaultTimeout = 10 * time.Minute +) + // WaitForLbRequest is used by WaitForLb method. type WaitForLbRequest struct { - LbID string - Region scw.Region - Timeout time.Duration + LbID string + Region scw.Region + Timeout time.Duration + RetryInterval time.Duration } // WaitForLb waits for the lb to be in a "terminal state" before returning. // This function can be used to wait for a lb to be ready for example. func (s *API) WaitForLb(req *WaitForLbRequest) (*Lb, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = defaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[LbStatus]struct{}{ LbStatusReady: {}, LbStatusStopped: {}, @@ -39,8 +54,8 @@ func (s *API) WaitForLb(req *WaitForLbRequest) (*Lb, error) { return res, isTerminal, nil }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(5 * time.Second), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for lb failed") diff --git a/api/rdb/v1/rdb_utils.go b/api/rdb/v1/rdb_utils.go index ce97648ef..0a98d8c08 100644 --- a/api/rdb/v1/rdb_utils.go +++ b/api/rdb/v1/rdb_utils.go @@ -8,16 +8,31 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" ) +const ( + defaultRetryInterval = 15 * time.Second + defaultTimeout = 15 * time.Minute +) + // WaitForInstanceRequest is used by WaitForInstance method. type WaitForInstanceRequest struct { - InstanceID string - Region scw.Region - Timeout time.Duration + InstanceID string + Region scw.Region + Timeout time.Duration + RetryInterval time.Duration } // WaitForInstance waits for the instance to be in a "terminal state" before returning. // This function can be used to wait for an instance to be ready for example. func (s *API) WaitForInstance(req *WaitForInstanceRequest) (*Instance, error) { + timeout := req.Timeout + if timeout == 0 { + timeout = defaultTimeout + } + retryInterval := req.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + terminalStatus := map[InstanceStatus]struct{}{ InstanceStatusReady: {}, InstanceStatusDiskFull: {}, @@ -38,8 +53,8 @@ func (s *API) WaitForInstance(req *WaitForInstanceRequest) (*Instance, error) { return res, isTerminal, nil }, - Timeout: req.Timeout, - IntervalStrategy: async.LinearIntervalStrategy(5 * time.Second), + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { return nil, errors.Wrap(err, "waiting for instance failed") From 761ee436b4a96f2c7ca43cfebc984b1a14f2f74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 2 Jun 2020 11:57:44 +0200 Subject: [PATCH 2/9] Fix --- api/lb/v1/lb_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/lb/v1/lb_utils.go b/api/lb/v1/lb_utils.go index c8893da23..cda436c0a 100644 --- a/api/lb/v1/lb_utils.go +++ b/api/lb/v1/lb_utils.go @@ -10,7 +10,7 @@ import ( const ( defaultRetryInterval = 2 * time.Second - defaultTimeout = 10 * time.Minute + defaultTimeout = 5 * time.Minute ) // WaitForLbRequest is used by WaitForLb method. From cd4b4c45a453ffb2f59fe573c30bbef9f22178d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 2 Jun 2020 13:26:40 +0200 Subject: [PATCH 3/9] Fix --- api/baremetal/v1/server_utils.go | 8 ++++---- api/baremetal/v1alpha1/server_utils.go | 8 ++++---- api/instance/v1/image_utils.go | 4 ++-- api/instance/v1/server_utils.go | 13 +++++++------ api/instance/v1/snapshot_utils.go | 4 ++-- api/instance/v1/volume_utils.go | 4 ++-- api/k8s/v1/k8s_helpers.go | 12 ++++++------ api/k8s/v1beta3/k8s_helpers.go | 4 ++-- api/k8s/v1beta4/k8s_helpers.go | 12 ++++++------ api/lb/v1/lb_utils.go | 4 ++-- api/rdb/v1/rdb_utils.go | 4 ++-- api/registry/v1/image_utils.go | 4 ++-- api/registry/v1/registry_utils.go | 4 ++-- api/registry/v1/tag_utils.go | 4 ++-- 14 files changed, 45 insertions(+), 44 deletions(-) diff --git a/api/baremetal/v1/server_utils.go b/api/baremetal/v1/server_utils.go index 6df64bfd6..b1bbd9def 100644 --- a/api/baremetal/v1/server_utils.go +++ b/api/baremetal/v1/server_utils.go @@ -17,14 +17,14 @@ const ( type WaitForServerRequest struct { ServerID string Zone scw.Zone - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForServer wait for the server to be in a "terminal state" before returning. // This function can be used to wait for a server to be created. func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } @@ -68,7 +68,7 @@ func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { type WaitForServerInstallRequest struct { ServerID string Zone scw.Zone - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } @@ -76,7 +76,7 @@ type WaitForServerInstallRequest struct { // "terminal state" before returning. // This function can be used to wait for a server to be installed. func (s *API) WaitForServerInstall(req *WaitForServerInstallRequest) (*Server, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/baremetal/v1alpha1/server_utils.go b/api/baremetal/v1alpha1/server_utils.go index 6df64bfd6..b1bbd9def 100644 --- a/api/baremetal/v1alpha1/server_utils.go +++ b/api/baremetal/v1alpha1/server_utils.go @@ -17,14 +17,14 @@ const ( type WaitForServerRequest struct { ServerID string Zone scw.Zone - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForServer wait for the server to be in a "terminal state" before returning. // This function can be used to wait for a server to be created. func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } @@ -68,7 +68,7 @@ func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { type WaitForServerInstallRequest struct { ServerID string Zone scw.Zone - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } @@ -76,7 +76,7 @@ type WaitForServerInstallRequest struct { // "terminal state" before returning. // This function can be used to wait for a server to be installed. func (s *API) WaitForServerInstall(req *WaitForServerInstallRequest) (*Server, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/instance/v1/image_utils.go b/api/instance/v1/image_utils.go index d73bb8b0e..c8d15dac2 100644 --- a/api/instance/v1/image_utils.go +++ b/api/instance/v1/image_utils.go @@ -12,13 +12,13 @@ import ( type WaitForImageRequest struct { ImageID string Zone scw.Zone - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForImage wait for the image to be in a "terminal state" before returning. func (s *API) WaitForImage(req *WaitForImageRequest) (*Image, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/instance/v1/server_utils.go b/api/instance/v1/server_utils.go index 5427f07b2..250fce3a1 100644 --- a/api/instance/v1/server_utils.go +++ b/api/instance/v1/server_utils.go @@ -50,14 +50,14 @@ func (s *API) UpdateServer(req *UpdateServerRequest, opts ...scw.RequestOption) type WaitForServerRequest struct { ServerID string Zone scw.Zone - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForServer wait for the server to be in a "terminal state" before returning. // This function can be used to wait for a server to be started for example. func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } @@ -102,15 +102,16 @@ type ServerActionAndWaitRequest struct { Action ServerAction // Timeout: maximum time to wait before (default: 5 minutes) - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // ServerActionAndWait start an action and wait for the server to be in the correct "terminal state" // expected by this action. func (s *API) ServerActionAndWait(req *ServerActionAndWaitRequest) error { - if req.Timeout == 0 { - req.Timeout = defaultTimeout + timeout := *req.Timeout + if timeout == 0 { + timeout = defaultTimeout } _, err := s.ServerAction(&ServerActionRequest{ @@ -125,7 +126,7 @@ func (s *API) ServerActionAndWait(req *ServerActionAndWaitRequest) error { finalServer, err := s.WaitForServer(&WaitForServerRequest{ Zone: req.Zone, ServerID: req.ServerID, - Timeout: req.Timeout, + Timeout: &timeout, }) if err != nil { return err diff --git a/api/instance/v1/snapshot_utils.go b/api/instance/v1/snapshot_utils.go index a058f1cd3..847ac4468 100644 --- a/api/instance/v1/snapshot_utils.go +++ b/api/instance/v1/snapshot_utils.go @@ -12,13 +12,13 @@ import ( type WaitForSnapshotRequest struct { SnapshotID string Zone scw.Zone - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning. func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest) (*Snapshot, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/instance/v1/volume_utils.go b/api/instance/v1/volume_utils.go index 92b41d48d..e9b3ed661 100644 --- a/api/instance/v1/volume_utils.go +++ b/api/instance/v1/volume_utils.go @@ -12,13 +12,13 @@ import ( type WaitForVolumeRequest struct { VolumeID string Zone scw.Zone - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning. func (s *API) WaitForVolume(req *WaitForVolumeRequest) (*Volume, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/k8s/v1/k8s_helpers.go b/api/k8s/v1/k8s_helpers.go index fb094817d..8cc3a9719 100644 --- a/api/k8s/v1/k8s_helpers.go +++ b/api/k8s/v1/k8s_helpers.go @@ -20,13 +20,13 @@ type WaitForClusterRequest struct { ClusterID string Region scw.Region Status ClusterStatus - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = waitForClusterDefaultTimeout } @@ -68,13 +68,13 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { type WaitForPoolRequest struct { PoolID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForPool waits for a pool to be ready func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = waitForPoolDefaultTimeout } @@ -116,13 +116,13 @@ func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { type WaitForNodeRequest struct { NodeID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForNode waits for a Node to be ready func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = waitForNodeDefaultTimeout } diff --git a/api/k8s/v1beta3/k8s_helpers.go b/api/k8s/v1beta3/k8s_helpers.go index 311aba007..5172b4c74 100644 --- a/api/k8s/v1beta3/k8s_helpers.go +++ b/api/k8s/v1beta3/k8s_helpers.go @@ -18,13 +18,13 @@ type WaitForClusterRequest struct { ClusterID string Region scw.Region Status ClusterStatus - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = waitForClusterDefaultTimeout } diff --git a/api/k8s/v1beta4/k8s_helpers.go b/api/k8s/v1beta4/k8s_helpers.go index 36533acc0..fcc1284ba 100644 --- a/api/k8s/v1beta4/k8s_helpers.go +++ b/api/k8s/v1beta4/k8s_helpers.go @@ -20,13 +20,13 @@ type WaitForClusterRequest struct { ClusterID string Region scw.Region Status ClusterStatus - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = waitForClusterDefaultTimeout } @@ -69,13 +69,13 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { type WaitForPoolRequest struct { PoolID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForPool waits for a pool to be ready func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = waitForPoolDefaultTimeout } @@ -114,13 +114,13 @@ func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { type WaitForNodeRequest struct { NodeID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForNode waits for a Node to be ready func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = waitForNodeDefaultTimeout } diff --git a/api/lb/v1/lb_utils.go b/api/lb/v1/lb_utils.go index cda436c0a..b4e755d36 100644 --- a/api/lb/v1/lb_utils.go +++ b/api/lb/v1/lb_utils.go @@ -17,14 +17,14 @@ const ( type WaitForLbRequest struct { LbID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForLb waits for the lb to be in a "terminal state" before returning. // This function can be used to wait for a lb to be ready for example. func (s *API) WaitForLb(req *WaitForLbRequest) (*Lb, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/rdb/v1/rdb_utils.go b/api/rdb/v1/rdb_utils.go index 0a98d8c08..0cc11f034 100644 --- a/api/rdb/v1/rdb_utils.go +++ b/api/rdb/v1/rdb_utils.go @@ -17,14 +17,14 @@ const ( type WaitForInstanceRequest struct { InstanceID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForInstance waits for the instance to be in a "terminal state" before returning. // This function can be used to wait for an instance to be ready for example. func (s *API) WaitForInstance(req *WaitForInstanceRequest) (*Instance, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/registry/v1/image_utils.go b/api/registry/v1/image_utils.go index 0ea40002d..fbcb53d67 100644 --- a/api/registry/v1/image_utils.go +++ b/api/registry/v1/image_utils.go @@ -12,14 +12,14 @@ import ( type WaitForImageRequest struct { ImageID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForImage wait for the image to be in a "terminal state" before returning. // This function can be used to wait for an image to be ready for example. func (s *API) WaitForImage(req *WaitForImageRequest) (*Image, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/registry/v1/registry_utils.go b/api/registry/v1/registry_utils.go index b03ecbc22..95ae53378 100644 --- a/api/registry/v1/registry_utils.go +++ b/api/registry/v1/registry_utils.go @@ -17,14 +17,14 @@ const ( type WaitForNamespaceRequest struct { NamespaceID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForNamespace wait for the namespace to be in a "terminal state" before returning. // This function can be used to wait for a namespace to be ready for example. func (s *API) WaitForNamespace(req *WaitForNamespaceRequest) (*Namespace, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } diff --git a/api/registry/v1/tag_utils.go b/api/registry/v1/tag_utils.go index 9f834a558..4a0ff8de3 100644 --- a/api/registry/v1/tag_utils.go +++ b/api/registry/v1/tag_utils.go @@ -12,14 +12,14 @@ import ( type WaitForTagRequest struct { TagID string Region scw.Region - Timeout time.Duration + Timeout *time.Duration RetryInterval time.Duration } // WaitForTag wait for the tag to be in a "terminal state" before returning. // This function can be used to wait for a tag to be ready for example. func (s *API) WaitForTag(req *WaitForTagRequest) (*Tag, error) { - timeout := req.Timeout + timeout := *req.Timeout if timeout == 0 { timeout = defaultTimeout } From d99103cfff50a18ef22287c45dc06694910bde8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 2 Jun 2020 13:34:33 +0200 Subject: [PATCH 4/9] Fix --- api/baremetal/v1/server_utils.go | 12 ++++++------ api/baremetal/v1alpha1/server_utils.go | 12 ++++++------ api/instance/v1/server_utils.go | 12 ++++++------ api/instance/v1/snapshot_utils.go | 6 +++--- api/instance/v1/volume_utils.go | 6 +++--- api/k8s/v1/k8s_helpers.go | 6 +++--- api/k8s/v1beta3/k8s_helpers.go | 6 +++--- api/k8s/v1beta4/k8s_helpers.go | 18 +++++++++--------- api/lb/v1/lb_utils.go | 6 +++--- api/rdb/v1/rdb_utils.go | 6 +++--- api/registry/v1/image_utils.go | 6 +++--- api/registry/v1/registry_utils.go | 6 +++--- api/registry/v1/tag_utils.go | 6 +++--- 13 files changed, 54 insertions(+), 54 deletions(-) diff --git a/api/baremetal/v1/server_utils.go b/api/baremetal/v1/server_utils.go index b1bbd9def..812a22627 100644 --- a/api/baremetal/v1/server_utils.go +++ b/api/baremetal/v1/server_utils.go @@ -24,9 +24,9 @@ type WaitForServerRequest struct { // WaitForServer wait for the server to be in a "terminal state" before returning. // This function can be used to wait for a server to be created. func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { @@ -76,9 +76,9 @@ type WaitForServerInstallRequest struct { // "terminal state" before returning. // This function can be used to wait for a server to be installed. func (s *API) WaitForServerInstall(req *WaitForServerInstallRequest) (*Server, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/baremetal/v1alpha1/server_utils.go b/api/baremetal/v1alpha1/server_utils.go index b1bbd9def..812a22627 100644 --- a/api/baremetal/v1alpha1/server_utils.go +++ b/api/baremetal/v1alpha1/server_utils.go @@ -24,9 +24,9 @@ type WaitForServerRequest struct { // WaitForServer wait for the server to be in a "terminal state" before returning. // This function can be used to wait for a server to be created. func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { @@ -76,9 +76,9 @@ type WaitForServerInstallRequest struct { // "terminal state" before returning. // This function can be used to wait for a server to be installed. func (s *API) WaitForServerInstall(req *WaitForServerInstallRequest) (*Server, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/instance/v1/server_utils.go b/api/instance/v1/server_utils.go index 250fce3a1..344b2b620 100644 --- a/api/instance/v1/server_utils.go +++ b/api/instance/v1/server_utils.go @@ -57,9 +57,9 @@ type WaitForServerRequest struct { // WaitForServer wait for the server to be in a "terminal state" before returning. // This function can be used to wait for a server to be started for example. func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { @@ -109,9 +109,9 @@ type ServerActionAndWaitRequest struct { // ServerActionAndWait start an action and wait for the server to be in the correct "terminal state" // expected by this action. func (s *API) ServerActionAndWait(req *ServerActionAndWaitRequest) error { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } _, err := s.ServerAction(&ServerActionRequest{ diff --git a/api/instance/v1/snapshot_utils.go b/api/instance/v1/snapshot_utils.go index 847ac4468..8a3273755 100644 --- a/api/instance/v1/snapshot_utils.go +++ b/api/instance/v1/snapshot_utils.go @@ -18,9 +18,9 @@ type WaitForSnapshotRequest struct { // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning. func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest) (*Snapshot, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/instance/v1/volume_utils.go b/api/instance/v1/volume_utils.go index e9b3ed661..f15f0e7d1 100644 --- a/api/instance/v1/volume_utils.go +++ b/api/instance/v1/volume_utils.go @@ -18,9 +18,9 @@ type WaitForVolumeRequest struct { // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning. func (s *API) WaitForVolume(req *WaitForVolumeRequest) (*Volume, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/k8s/v1/k8s_helpers.go b/api/k8s/v1/k8s_helpers.go index 8cc3a9719..8773d7400 100644 --- a/api/k8s/v1/k8s_helpers.go +++ b/api/k8s/v1/k8s_helpers.go @@ -122,9 +122,9 @@ type WaitForNodeRequest struct { // WaitForNode waits for a Node to be ready func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = waitForNodeDefaultTimeout + timeout := waitForNodeDefaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/k8s/v1beta3/k8s_helpers.go b/api/k8s/v1beta3/k8s_helpers.go index 5172b4c74..a8adfe7dd 100644 --- a/api/k8s/v1beta3/k8s_helpers.go +++ b/api/k8s/v1beta3/k8s_helpers.go @@ -24,9 +24,9 @@ type WaitForClusterRequest struct { // WaitForCluster waits for the cluster to be in a "terminal state" before returning. func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = waitForClusterDefaultTimeout + timeout := waitForClusterDefaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/k8s/v1beta4/k8s_helpers.go b/api/k8s/v1beta4/k8s_helpers.go index fcc1284ba..3b2e02cd9 100644 --- a/api/k8s/v1beta4/k8s_helpers.go +++ b/api/k8s/v1beta4/k8s_helpers.go @@ -26,9 +26,9 @@ type WaitForClusterRequest struct { // WaitForCluster waits for the cluster to be in a "terminal state" before returning. func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = waitForClusterDefaultTimeout + timeout := waitForClusterDefaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { @@ -75,9 +75,9 @@ type WaitForPoolRequest struct { // WaitForPool waits for a pool to be ready func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = waitForPoolDefaultTimeout + timeout := waitForPoolDefaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { @@ -120,9 +120,9 @@ type WaitForNodeRequest struct { // WaitForNode waits for a Node to be ready func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = waitForNodeDefaultTimeout + timeout := waitForNodeDefaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/lb/v1/lb_utils.go b/api/lb/v1/lb_utils.go index b4e755d36..7a902811a 100644 --- a/api/lb/v1/lb_utils.go +++ b/api/lb/v1/lb_utils.go @@ -24,9 +24,9 @@ type WaitForLbRequest struct { // WaitForLb waits for the lb to be in a "terminal state" before returning. // This function can be used to wait for a lb to be ready for example. func (s *API) WaitForLb(req *WaitForLbRequest) (*Lb, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/rdb/v1/rdb_utils.go b/api/rdb/v1/rdb_utils.go index 0cc11f034..f32b8cf53 100644 --- a/api/rdb/v1/rdb_utils.go +++ b/api/rdb/v1/rdb_utils.go @@ -24,9 +24,9 @@ type WaitForInstanceRequest struct { // WaitForInstance waits for the instance to be in a "terminal state" before returning. // This function can be used to wait for an instance to be ready for example. func (s *API) WaitForInstance(req *WaitForInstanceRequest) (*Instance, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/registry/v1/image_utils.go b/api/registry/v1/image_utils.go index fbcb53d67..b1b4a6cda 100644 --- a/api/registry/v1/image_utils.go +++ b/api/registry/v1/image_utils.go @@ -19,9 +19,9 @@ type WaitForImageRequest struct { // WaitForImage wait for the image to be in a "terminal state" before returning. // This function can be used to wait for an image to be ready for example. func (s *API) WaitForImage(req *WaitForImageRequest) (*Image, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/registry/v1/registry_utils.go b/api/registry/v1/registry_utils.go index 95ae53378..80e06d6a9 100644 --- a/api/registry/v1/registry_utils.go +++ b/api/registry/v1/registry_utils.go @@ -24,9 +24,9 @@ type WaitForNamespaceRequest struct { // WaitForNamespace wait for the namespace to be in a "terminal state" before returning. // This function can be used to wait for a namespace to be ready for example. func (s *API) WaitForNamespace(req *WaitForNamespaceRequest) (*Namespace, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { diff --git a/api/registry/v1/tag_utils.go b/api/registry/v1/tag_utils.go index 4a0ff8de3..06a423331 100644 --- a/api/registry/v1/tag_utils.go +++ b/api/registry/v1/tag_utils.go @@ -19,9 +19,9 @@ type WaitForTagRequest struct { // WaitForTag wait for the tag to be in a "terminal state" before returning. // This function can be used to wait for a tag to be ready for example. func (s *API) WaitForTag(req *WaitForTagRequest) (*Tag, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := req.RetryInterval if retryInterval == 0 { From ca26ef2f94e5c61a5d8da947d186fa53ffc136f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 2 Jun 2020 14:07:51 +0200 Subject: [PATCH 5/9] FIx --- api/baremetal/v1/server_utils.go | 16 ++++++++-------- api/baremetal/v1alpha1/server_utils.go | 16 ++++++++-------- api/instance/v1/server_utils.go | 22 ++++++++++++++-------- api/instance/v1/snapshot_utils.go | 8 ++++---- api/instance/v1/volume_utils.go | 8 ++++---- api/k8s/v1/k8s_helpers.go | 25 +++++++++++++------------ api/k8s/v1beta3/k8s_helpers.go | 8 ++++---- api/k8s/v1beta4/k8s_helpers.go | 24 ++++++++++++------------ api/lb/v1/lb_utils.go | 8 ++++---- api/rdb/v1/rdb_utils.go | 8 ++++---- api/registry/v1/image_utils.go | 8 ++++---- api/registry/v1/registry_utils.go | 8 ++++---- api/registry/v1/tag_utils.go | 8 ++++---- 13 files changed, 87 insertions(+), 80 deletions(-) diff --git a/api/baremetal/v1/server_utils.go b/api/baremetal/v1/server_utils.go index 812a22627..7b6672705 100644 --- a/api/baremetal/v1/server_utils.go +++ b/api/baremetal/v1/server_utils.go @@ -18,7 +18,7 @@ type WaitForServerRequest struct { ServerID string Zone scw.Zone Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForServer wait for the server to be in a "terminal state" before returning. @@ -28,9 +28,9 @@ func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[ServerStatus]struct{}{ @@ -69,7 +69,7 @@ type WaitForServerInstallRequest struct { ServerID string Zone scw.Zone Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForServerInstall wait for the server install to be in a @@ -80,9 +80,9 @@ func (s *API) WaitForServerInstall(req *WaitForServerInstallRequest) (*Server, e if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } installTerminalStatus := map[ServerInstallStatus]struct{}{ diff --git a/api/baremetal/v1alpha1/server_utils.go b/api/baremetal/v1alpha1/server_utils.go index 812a22627..7b6672705 100644 --- a/api/baremetal/v1alpha1/server_utils.go +++ b/api/baremetal/v1alpha1/server_utils.go @@ -18,7 +18,7 @@ type WaitForServerRequest struct { ServerID string Zone scw.Zone Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForServer wait for the server to be in a "terminal state" before returning. @@ -28,9 +28,9 @@ func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[ServerStatus]struct{}{ @@ -69,7 +69,7 @@ type WaitForServerInstallRequest struct { ServerID string Zone scw.Zone Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForServerInstall wait for the server install to be in a @@ -80,9 +80,9 @@ func (s *API) WaitForServerInstall(req *WaitForServerInstallRequest) (*Server, e if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } installTerminalStatus := map[ServerInstallStatus]struct{}{ diff --git a/api/instance/v1/server_utils.go b/api/instance/v1/server_utils.go index 344b2b620..88f958351 100644 --- a/api/instance/v1/server_utils.go +++ b/api/instance/v1/server_utils.go @@ -51,7 +51,7 @@ type WaitForServerRequest struct { ServerID string Zone scw.Zone Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForServer wait for the server to be in a "terminal state" before returning. @@ -61,10 +61,11 @@ func (s *API) WaitForServer(req *WaitForServerRequest) (*Server, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } + terminalStatus := map[ServerState]struct{}{ ServerStateStopped: {}, ServerStateStoppedInPlace: {}, @@ -103,7 +104,7 @@ type ServerActionAndWaitRequest struct { // Timeout: maximum time to wait before (default: 5 minutes) Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // ServerActionAndWait start an action and wait for the server to be in the correct "terminal state" @@ -113,6 +114,10 @@ func (s *API) ServerActionAndWait(req *ServerActionAndWaitRequest) error { if req.Timeout != nil { timeout = *req.Timeout } + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval + } _, err := s.ServerAction(&ServerActionRequest{ Zone: req.Zone, @@ -124,9 +129,10 @@ func (s *API) ServerActionAndWait(req *ServerActionAndWaitRequest) error { } finalServer, err := s.WaitForServer(&WaitForServerRequest{ - Zone: req.Zone, - ServerID: req.ServerID, - Timeout: &timeout, + Zone: req.Zone, + ServerID: req.ServerID, + Timeout: &timeout, + RetryInterval: &retryInterval, }) if err != nil { return err diff --git a/api/instance/v1/snapshot_utils.go b/api/instance/v1/snapshot_utils.go index 8a3273755..683b0056a 100644 --- a/api/instance/v1/snapshot_utils.go +++ b/api/instance/v1/snapshot_utils.go @@ -13,7 +13,7 @@ type WaitForSnapshotRequest struct { SnapshotID string Zone scw.Zone Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning. @@ -22,9 +22,9 @@ func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest) (*Snapshot, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[SnapshotState]struct{}{ diff --git a/api/instance/v1/volume_utils.go b/api/instance/v1/volume_utils.go index f15f0e7d1..1f9b7ad60 100644 --- a/api/instance/v1/volume_utils.go +++ b/api/instance/v1/volume_utils.go @@ -13,7 +13,7 @@ type WaitForVolumeRequest struct { VolumeID string Zone scw.Zone Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning. @@ -22,9 +22,9 @@ func (s *API) WaitForVolume(req *WaitForVolumeRequest) (*Volume, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[VolumeState]struct{}{ diff --git a/api/k8s/v1/k8s_helpers.go b/api/k8s/v1/k8s_helpers.go index 8773d7400..6f61d5939 100644 --- a/api/k8s/v1/k8s_helpers.go +++ b/api/k8s/v1/k8s_helpers.go @@ -21,7 +21,7 @@ type WaitForClusterRequest struct { Region scw.Region Status ClusterStatus Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. @@ -30,10 +30,11 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { if timeout == 0 { timeout = waitForClusterDefaultTimeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } + terminalStatus := map[ClusterStatus]struct{}{ ClusterStatusReady: {}, ClusterStatusLocked: {}, @@ -69,7 +70,7 @@ type WaitForPoolRequest struct { PoolID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForPool waits for a pool to be ready @@ -78,9 +79,9 @@ func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { if timeout == 0 { timeout = waitForPoolDefaultTimeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[PoolStatus]struct{}{ @@ -117,7 +118,7 @@ type WaitForNodeRequest struct { NodeID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForNode waits for a Node to be ready @@ -126,9 +127,9 @@ func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[NodeStatus]struct{}{ diff --git a/api/k8s/v1beta3/k8s_helpers.go b/api/k8s/v1beta3/k8s_helpers.go index a8adfe7dd..a8ce755f1 100644 --- a/api/k8s/v1beta3/k8s_helpers.go +++ b/api/k8s/v1beta3/k8s_helpers.go @@ -19,7 +19,7 @@ type WaitForClusterRequest struct { Region scw.Region Status ClusterStatus Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. @@ -28,9 +28,9 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[ClusterStatus]struct{}{ diff --git a/api/k8s/v1beta4/k8s_helpers.go b/api/k8s/v1beta4/k8s_helpers.go index 3b2e02cd9..0a24fc814 100644 --- a/api/k8s/v1beta4/k8s_helpers.go +++ b/api/k8s/v1beta4/k8s_helpers.go @@ -21,7 +21,7 @@ type WaitForClusterRequest struct { Region scw.Region Status ClusterStatus Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForCluster waits for the cluster to be in a "terminal state" before returning. @@ -30,9 +30,9 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[ClusterStatus]struct{}{ @@ -70,7 +70,7 @@ type WaitForPoolRequest struct { PoolID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForPool waits for a pool to be ready @@ -79,9 +79,9 @@ func (s *API) WaitForPool(req *WaitForPoolRequest) (*Pool, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[PoolStatus]struct{}{ @@ -115,7 +115,7 @@ type WaitForNodeRequest struct { NodeID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForNode waits for a Node to be ready @@ -124,9 +124,9 @@ func (s *API) WaitForNode(req *WaitForNodeRequest) (*Node, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[NodeStatus]struct{}{ diff --git a/api/lb/v1/lb_utils.go b/api/lb/v1/lb_utils.go index 7a902811a..f7a43f571 100644 --- a/api/lb/v1/lb_utils.go +++ b/api/lb/v1/lb_utils.go @@ -18,7 +18,7 @@ type WaitForLbRequest struct { LbID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForLb waits for the lb to be in a "terminal state" before returning. @@ -28,9 +28,9 @@ func (s *API) WaitForLb(req *WaitForLbRequest) (*Lb, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[LbStatus]struct{}{ diff --git a/api/rdb/v1/rdb_utils.go b/api/rdb/v1/rdb_utils.go index f32b8cf53..70f52cec0 100644 --- a/api/rdb/v1/rdb_utils.go +++ b/api/rdb/v1/rdb_utils.go @@ -18,7 +18,7 @@ type WaitForInstanceRequest struct { InstanceID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForInstance waits for the instance to be in a "terminal state" before returning. @@ -28,9 +28,9 @@ func (s *API) WaitForInstance(req *WaitForInstanceRequest) (*Instance, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[InstanceStatus]struct{}{ diff --git a/api/registry/v1/image_utils.go b/api/registry/v1/image_utils.go index b1b4a6cda..2eba338e1 100644 --- a/api/registry/v1/image_utils.go +++ b/api/registry/v1/image_utils.go @@ -13,7 +13,7 @@ type WaitForImageRequest struct { ImageID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForImage wait for the image to be in a "terminal state" before returning. @@ -23,9 +23,9 @@ func (s *API) WaitForImage(req *WaitForImageRequest) (*Image, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[ImageStatus]struct{}{ diff --git a/api/registry/v1/registry_utils.go b/api/registry/v1/registry_utils.go index 80e06d6a9..b29f48784 100644 --- a/api/registry/v1/registry_utils.go +++ b/api/registry/v1/registry_utils.go @@ -18,7 +18,7 @@ type WaitForNamespaceRequest struct { NamespaceID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForNamespace wait for the namespace to be in a "terminal state" before returning. @@ -28,9 +28,9 @@ func (s *API) WaitForNamespace(req *WaitForNamespaceRequest) (*Namespace, error) if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[NamespaceStatus]struct{}{ diff --git a/api/registry/v1/tag_utils.go b/api/registry/v1/tag_utils.go index 06a423331..c0c4f3cf5 100644 --- a/api/registry/v1/tag_utils.go +++ b/api/registry/v1/tag_utils.go @@ -13,7 +13,7 @@ type WaitForTagRequest struct { TagID string Region scw.Region Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForTag wait for the tag to be in a "terminal state" before returning. @@ -23,9 +23,9 @@ func (s *API) WaitForTag(req *WaitForTagRequest) (*Tag, error) { if req.Timeout != nil { timeout = *req.Timeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[TagStatus]struct{}{ From b7e20060df64ad507d723ff97d663a35aa529e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 2 Jun 2020 14:08:54 +0200 Subject: [PATCH 6/9] Fix --- api/instance/v1/image_utils.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/instance/v1/image_utils.go b/api/instance/v1/image_utils.go index c8d15dac2..bf99e0685 100644 --- a/api/instance/v1/image_utils.go +++ b/api/instance/v1/image_utils.go @@ -13,7 +13,7 @@ type WaitForImageRequest struct { ImageID string Zone scw.Zone Timeout *time.Duration - RetryInterval time.Duration + RetryInterval *time.Duration } // WaitForImage wait for the image to be in a "terminal state" before returning. @@ -22,9 +22,9 @@ func (s *API) WaitForImage(req *WaitForImageRequest) (*Image, error) { if timeout == 0 { timeout = defaultTimeout } - retryInterval := req.RetryInterval - if retryInterval == 0 { - retryInterval = defaultRetryInterval + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval } terminalStatus := map[ImageState]struct{}{ From eac77a5e70f79a7c86c43b0fc996495425f7641d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 2 Jun 2020 16:02:38 +0200 Subject: [PATCH 7/9] Fix --- example_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example_test.go b/example_test.go index 5f2c99276..77a3f5ee8 100644 --- a/example_test.go +++ b/example_test.go @@ -109,10 +109,11 @@ func Example_createServer() { } // Start the server and wait until it's ready. + timeout := 5 * time.Minute err = instanceAPI.ServerActionAndWait(&instance.ServerActionAndWaitRequest{ ServerID: createRes.Server.ID, Action: instance.ServerActionPoweron, - Timeout: 5 * time.Minute, + Timeout: &timeout, }) if err != nil { panic(err) @@ -139,13 +140,14 @@ func Example_rebootAllServers() { } // For each server if they are running we reboot them using ServerActionAndWait + timeout := 5 * time.Minute for _, server := range response.Servers { if server.State == instance.ServerStateRunning { fmt.Println("Rebooting server with ID", server.ID) err = instanceAPI.ServerActionAndWait(&instance.ServerActionAndWaitRequest{ ServerID: server.ID, Action: instance.ServerActionReboot, - Timeout: 5 * time.Minute, + Timeout: &timeout, }) if err != nil { panic(err) From 363148920f1698b9f22f2ca135d63796376824b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 2 Jun 2020 16:15:52 +0200 Subject: [PATCH 8/9] Fix --- api/instance/v1/image_utils.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/instance/v1/image_utils.go b/api/instance/v1/image_utils.go index bf99e0685..e9d4a90f7 100644 --- a/api/instance/v1/image_utils.go +++ b/api/instance/v1/image_utils.go @@ -18,9 +18,9 @@ type WaitForImageRequest struct { // WaitForImage wait for the image to be in a "terminal state" before returning. func (s *API) WaitForImage(req *WaitForImageRequest) (*Image, error) { - timeout := *req.Timeout - if timeout == 0 { - timeout = defaultTimeout + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout } retryInterval := defaultRetryInterval if req.RetryInterval != nil { From cd819c7396a9b82c2c9b9410118d8a700215f5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Wed, 3 Jun 2020 11:27:33 +0200 Subject: [PATCH 9/9] Fix --- api/instance/v1/server_utils_test.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/api/instance/v1/server_utils_test.go b/api/instance/v1/server_utils_test.go index f9eac6dde..ceffcf202 100644 --- a/api/instance/v1/server_utils_test.go +++ b/api/instance/v1/server_utils_test.go @@ -13,13 +13,6 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" ) -func init() { - // set interval strategy to 0 when replaying cassettes - if httprecorder.IsUpdatingCassette() { - - } -} - func TestAPI_GetServerType(t *testing.T) { client, r, err := httprecorder.CreateRecordedScwClient("get-server-type") testhelpers.AssertNoError(t, err)