Skip to content

Commit 58be212

Browse files
committed
Add MaxErrorRetry to k8s config [ci fast]
Co-authored-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com> Signed-off-by: naineshmp <pnainesh18@gmail.com> Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
1 parent d27384d commit 58be212

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

docs/config.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ storageSubPath The path in the persistent volume to be mounted (default: ro
424424
computeResourceType Define whether use Kubernetes ``Pod`` or ``Job`` resource type to carry out Nextflow tasks (default: ``Pod``).
425425
fetchNodeName If you trace the hostname, activate this option (default: ``false``, requires version ``22.05.0-edge`` or later).
426426
volumeClaims (deprecated)
427+
maxErrorRetry Defines the Kubernetes API max request retries (default is set to 4)
427428
httpReadTimeout Defines the Kubernetes client request HTTP connection read timeout e.g. ``'60s'`` (requires version ``22.10.0`` or later).
428429
httpConnectTimeout Defines the Kubernetes client request HTTP connection timeout e.g. ``'60s'`` (requires version ``22.10.0`` or later).
429430
=================== ================

modules/nextflow/src/main/groovy/nextflow/k8s/K8sConfig.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ class K8sConfig implements Map<String,Object> {
226226
if( target.httpReadTimeout )
227227
result.httpReadTimeout = target.httpReadTimeout as Duration
228228

229+
if( target.maxErrorRetry )
230+
result.maxErrorRetry = target.maxErrorRetry as Integer
231+
229232
return result
230233
}
231234

modules/nextflow/src/main/groovy/nextflow/k8s/client/ClientConfig.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class ClientConfig {
5656

5757
KeyManager[] keyManagers
5858

59+
Integer maxErrorRetry = 4
60+
5961
/**
6062
* Timeout when reading from Input stream when a connection is established to a resource.
6163
* If the timeout expires before there is data available for read, a {@link java.net.SocketTimeoutException} is raised
@@ -80,7 +82,7 @@ class ClientConfig {
8082
}
8183

8284
String toString() {
83-
"${this.class.getSimpleName()}[ server=$server, namespace=$namespace, token=${cut(token)}, sslCert=${cut(sslCert)}, clientCert=${cut(clientCert)}, clientKey=${cut(clientKey)}, verifySsl=$verifySsl, fromFile=$isFromCluster, httpReadTimeout=$httpReadTimeout, httpConnectTimeout=$httpConnectTimeout ]"
85+
"${this.class.getSimpleName()}[ server=$server, namespace=$namespace, token=${cut(token)}, sslCert=${cut(sslCert)}, clientCert=${cut(clientCert)}, clientKey=${cut(clientKey)}, verifySsl=$verifySsl, fromFile=$isFromCluster, httpReadTimeout=$httpReadTimeout, httpConnectTimeout=$httpConnectTimeout, maxErrorRetry=$maxErrorRetry ]"
8486
}
8587

8688
private String cut(String str) {
@@ -128,6 +130,9 @@ class ClientConfig {
128130
else if( map.clientKeyFile )
129131
result.clientKey = Paths.get(map.clientKeyFile.toString()).bytes
130132

133+
if( map.maxErrorRetry )
134+
result.maxErrorRetry = map.maxErrorRetry as Integer
135+
131136
return result
132137
}
133138

modules/nextflow/src/main/groovy/nextflow/k8s/client/K8sClient.groovy

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,16 @@ class K8sClient {
618618
*/
619619
protected K8sResponseApi makeRequest(String method, String path, String body=null) throws K8sResponseException {
620620

621-
final int maxAttempts = 5
621+
final int maxRetries = config.maxErrorRetry
622622
int attempt = 0
623623

624-
while ( attempt < maxAttempts ) {
625-
attempt++
626-
624+
while ( true ) {
627625
try {
628626
return makeRequestCall( method, path, body )
629627
} catch ( K8sResponseException | SocketException | SocketTimeoutException e ) {
630628
if ( e instanceof K8sResponseException && e.response.code != 500 )
631629
throw e
632-
if ( attempt >= maxAttempts )
630+
if ( ++attempt > maxRetries )
633631
throw e
634632
log.debug "[K8s] API request threw socket exception: $e.message for $method $path - Retrying request (attempt=$attempt)"
635633
final long delay = (Math.pow(3, attempt - 1) as long) * 250

modules/nextflow/src/test/groovy/nextflow/k8s/K8sConfigTest.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,21 @@ class K8sConfigTest extends Specification {
143143
client.serviceAccount == 'that'
144144
client.httpConnectTimeout == null // testing default null
145145
client.httpReadTimeout == null // testing default null
146+
client.maxErrorRetry == 4
146147

147148
}
148149

150+
def 'should set maxErrorRetry' () {
151+
given:
152+
def CONFIG = [maxErrorRetry: 10, namespace: 'this', serviceAccount: 'that', client: [server: 'http://foo']]
153+
154+
when:
155+
def config = new K8sConfig(CONFIG)
156+
def client = config.getClient()
157+
then:
158+
client.maxErrorRetry == 10
159+
}
160+
149161
def 'should create client config with http request timeouts' () {
150162

151163
given:

0 commit comments

Comments
 (0)