Skip to content

Commit 064f9bc

Browse files
committed
Add httpReadTimeout and httpConnectTimeout config to K8s client [ci fast]
Signed-off-by: naineshmp <pnainesh18@gmail.com> Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
1 parent aed6c23 commit 064f9bc

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

docs/config.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ storageSubPath The path in the persistent volume to be mounted (default: ro
423423
computeResourceType Define whether use Kubernetes ``Pod`` or ``Job`` resource type to carry out Nextflow tasks (default: ``Pod``).
424424
fetchNodeName If you trace the hostname, activate this option (default: ``false``, requires version ``22.05.0-edge`` or later).
425425
volumeClaims (deprecated)
426+
httpReadTimeout Defines the Kubernetes client request HTTP connection read timeout e.g. ``'60s'`` (requires version ``22.10.0`` or later).
427+
httpConnectTimeout Defines the Kubernetes client request HTTP connection timeout e.g. ``'60s'`` (requires version ``22.10.0`` or later).
426428
=================== ================
427429

428430
See the :ref:`k8s-page` documentation for more details.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import nextflow.k8s.model.PodOptions
3030
import nextflow.k8s.model.PodSecurityContext
3131
import nextflow.k8s.model.PodVolumeClaim
3232
import nextflow.k8s.model.ResourceType
33+
import nextflow.util.Duration
3334

3435
/**
3536
* Model Kubernetes specific settings defined in the nextflow
@@ -203,7 +204,6 @@ class K8sConfig implements Map<String,Object> {
203204
return result ? result.claimName : null
204205
}
205206

206-
207207
@Memoized
208208
ClientConfig getClient() {
209209

@@ -220,6 +220,12 @@ class K8sConfig implements Map<String,Object> {
220220
result.serviceAccount = target.serviceAccount as String
221221
}
222222

223+
if( target.httpConnectTimeout )
224+
result.httpConnectTimeout = target.httpConnectTimeout as Duration
225+
226+
if( target.httpReadTimeout )
227+
result.httpReadTimeout = target.httpReadTimeout as Duration
228+
223229
return result
224230
}
225231

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717

1818
package nextflow.k8s.client
19+
20+
import nextflow.util.Duration
21+
1922
import javax.net.ssl.KeyManager
2023
import java.nio.file.Path
2124
import java.nio.file.Paths
@@ -53,6 +56,18 @@ class ClientConfig {
5356

5457
KeyManager[] keyManagers
5558

59+
/**
60+
* Timeout when reading from Input stream when a connection is established to a resource.
61+
* If the timeout expires before there is data available for read, a {@link java.net.SocketTimeoutException} is raised
62+
*/
63+
Duration httpReadTimeout
64+
65+
/**
66+
* Timeout when opening a communications link to the resource referenced by K8sClient request connection
67+
* If the timeout expires before there is data available for read, a {@link java.net.SocketTimeoutException} is raised
68+
*/
69+
Duration httpConnectTimeout
70+
5671
/**
5772
* When true signal that the configuration was retrieved from within a K8s cluster
5873
*/
@@ -65,7 +80,7 @@ class ClientConfig {
6580
}
6681

6782
String toString() {
68-
"${this.class.getSimpleName()}[ server=$server, namespace=$namespace, token=${cut(token)}, sslCert=${cut(sslCert)}, clientCert=${cut(clientCert)}, clientKey=${cut(clientKey)}, verifySsl=$verifySsl, fromFile=$isFromCluster ]"
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 ]"
6984
}
7085

7186
private String cut(String str) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ class K8sClient {
590590
}
591591

592592
protected void setupHttpsConn( HttpsURLConnection conn ) {
593+
if (config.httpReadTimeout != null) {
594+
conn.setReadTimeout(config.httpReadTimeout.toMillis() as int)
595+
}
596+
if (config.httpConnectTimeout != null) {
597+
conn.setConnectTimeout(config.httpConnectTimeout.toMillis() as int)
598+
}
593599
if (config.keyManagers != null || trustManagers != null) {
594600
SSLContext sslContext = SSLContext.getInstance("TLS");
595601
sslContext.init(config.keyManagers, trustManagers, new SecureRandom());

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import nextflow.k8s.client.ClientConfig
2222
import nextflow.k8s.model.PodEnv
2323
import nextflow.k8s.model.PodSecurityContext
2424
import nextflow.k8s.model.PodVolumeClaim
25+
import nextflow.util.Duration
2526
import spock.lang.Specification
2627
/**
2728
*
@@ -140,6 +141,30 @@ class K8sConfigTest extends Specification {
140141
client.server == 'http://foo'
141142
client.namespace == 'this'
142143
client.serviceAccount == 'that'
144+
client.httpConnectTimeout == null // testing default null
145+
client.httpReadTimeout == null // testing default null
146+
147+
}
148+
149+
def 'should create client config with http request timeouts' () {
150+
151+
given:
152+
def CONFIG = [
153+
namespace: 'this',
154+
serviceAccount: 'that',
155+
client: [server: 'http://foo'],
156+
httpReadTimeout: '20s',
157+
httpConnectTimeout: '25s' ]
158+
159+
when:
160+
def config = new K8sConfig(CONFIG)
161+
def client = config.getClient()
162+
then:
163+
client.server == 'http://foo'
164+
client.namespace == 'this'
165+
client.serviceAccount == 'that'
166+
client.httpConnectTimeout == Duration.of('25s')
167+
client.httpReadTimeout == Duration.of('20s')
143168

144169
}
145170

0 commit comments

Comments
 (0)