Skip to content

Commit 43c6241

Browse files
committed
Fix K8s token refresh by delegating getClient() to K8sConfig cache
K8sConfig.getClient() uses a Guava cache with a 50-minute expiry to refresh the service account token (added in PR #6742). However, K8sExecutor.register() called k8sConfig.getClient() once at startup and stored the result in a private field. K8sExecutor.getClient() returned that stored field directly, and K8sTaskHandler stored executor.client in its constructor — so the Guava cache was never consulted again after startup. This caused 401 Unauthorized errors after ~60 minutes on clusters with short-lived projected SA tokens (e.g. AKS, RKE2 with default ~1hr token lifetime). Fix: - Remove the private K8sClient field from K8sExecutor - Change getClient() to delegate to k8sConfig.getClient() on each invocation, letting the Guava cache handle token refresh - Fix K8sTaskHandler constructor to use executor.getClient() instead of accessing executor.client directly Fixes #6918 Generated by Claude Code Signed-off-by: adamrtalbot <12817534+adamrtalbot@users.noreply.github.com>
1 parent 021c77c commit 43c6241

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

plugins/nf-k8s/src/main/nextflow/k8s/K8sExecutor.groovy

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ import org.pf4j.ExtensionPoint
4040
@ServiceName('k8s')
4141
class K8sExecutor extends Executor implements ExtensionPoint {
4242

43-
/**
44-
* The Kubernetes HTTP client
45-
*/
46-
private K8sClient client
47-
48-
protected K8sClient getClient() {
49-
client
50-
}
51-
5243
/**
5344
* @return The `k8s` configuration scope in the nextflow configuration object
5445
*/
@@ -57,6 +48,15 @@ class K8sExecutor extends Executor implements ExtensionPoint {
5748
new K8sConfig( (Map<String,Object>)session.config.k8s )
5849
}
5950

51+
/**
52+
* @return The Kubernetes HTTP client. Delegates to {@link K8sConfig#getClient()} on each
53+
* invocation so that the underlying Guava cache can refresh the client configuration
54+
* (including the service account token) when it expires.
55+
*/
56+
protected K8sClient getClient() {
57+
new K8sClient(k8sConfig.getClient())
58+
}
59+
6060
/**
6161
* Initialise the executor setting-up the kubernetes client configuration
6262
*/
@@ -65,7 +65,6 @@ class K8sExecutor extends Executor implements ExtensionPoint {
6565
super.register()
6666
final k8sConfig = getK8sConfig()
6767
final clientConfig = k8sConfig.getClient()
68-
this.client = new K8sClient(clientConfig)
6968
log.debug "[K8s] config=$k8sConfig; API client config=$clientConfig"
7069
}
7170

plugins/nf-k8s/src/main/nextflow/k8s/K8sTaskHandler.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class K8sTaskHandler extends TaskHandler implements FusionAwareTask {
9393
K8sTaskHandler( TaskRun task, K8sExecutor executor ) {
9494
super(task)
9595
this.executor = executor
96-
this.client = executor.client
96+
this.client = executor.getClient()
9797
this.outputFile = task.workDir.resolve(TaskRun.CMD_OUTFILE)
9898
this.errorFile = task.workDir.resolve(TaskRun.CMD_ERRFILE)
9999
this.exitFile = task.workDir.resolve(TaskRun.CMD_EXIT)

0 commit comments

Comments
 (0)