Fix K8s projected service account token expiry#7092
Draft
gavinelder wants to merge 1 commit intomasterfrom
Draft
Fix K8s projected service account token expiry#7092gavinelder wants to merge 1 commit intomasterfrom
gavinelder wants to merge 1 commit intomasterfrom
Conversation
Re-read the SA token from disk with a 30s TTL cache rather than snapshotting it at startup. Kubelet rotates projected tokens at ~80% of their lifetime (default ~48min), so the old approach caused 401s on pipelines running longer than ~1hr. The previous workaround (PR #6742 / #6925) periodically recreated K8sClient via a Guava cache, but K8sTaskHandler cached the client instance at construction time so the cache was never consulted. The root fix is in ClientConfig.getBearerToken(), which reads the token file fresh when the 30s TTL expires rather than at any higher layer. The Guava cache and clientRefreshInterval config option are removed as they are no longer needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Gavin Elder <gavin.elder@seqera.io>
✅ Deploy Preview for nextflow-docs-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6918 — pipelines running >1hr on Kubernetes clusters with projected service account tokens (AKS, RKE2, etc.) receive
401 Unauthorizedbecause the token read at startup expires mid-run.Root cause
ConfigDiscovery.fromCluster()read the SA token from/var/run/secrets/kubernetes.io/serviceaccount/tokenonce at startup and stored it as a string inClientConfig. The kubelet rotates this file on disk at ~80% of the token lifetime (~48min for the default 3607s expiry), but Nextflow never re-read it.The previous workaround (PR #6742 / #6925) periodically recreated
K8sClientvia a Guava cache inK8sExecutor, butK8sTaskHandlercached theK8sClientinstance at construction time, so the cache was never consulted after startup.Fix
ConfigDiscovery.fromCluster()now stores the token filePathinClientConfig.tokenFileinstead of eagerly reading the contentClientConfig.getBearerToken()reads fromtokenFilewith a 30s in-memory TTL cache — the file is re-read at most once per 30s perClientConfiginstance; on read failure the last known-good token is returned and a warning is loggedK8sClient.makeRequestCall()callsconfig.getBearerToken()instead ofconfig.tokenK8sExecutorand thek8s.clientRefreshIntervalconfig option are removed as they are no longer neededTest plan
./gradlew :plugins:nf-k8s:testpasses (244 tests)expirationSeconds: 3607) running a pipeline >1hr🤖 Generated with Claude Code