fix: refresh bearer token on each Prometheus query#150
Merged
Conversation
The previous implementation read the bearer token from the in-memory Kubernetes Configuration singleton, which was set once at server startup. OpenShift tokens expire (typically 12-24h), causing all Prometheus queries to fail with "authentication failed" while other K8s API calls continued working (the K8s client handles refresh internally). New fallback chain: 1. `oc whoami -t` — always returns a fresh token 2. Re-read kubeconfig file — covers non-oc environments 3. In-memory config — kept as last resort 4. ServiceAccount token file — in-cluster 5. Environment variables — manual override Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
olegbet
approved these changes
Jul 2, 2026
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
oc whoami -tas primary token source (always fresh), with kubeconfig re-read as fallbackProblem
_get_k8s_bearer_token()read the token fromConfiguration.get_default_copy()— an in-memory snapshot from MCP server startup. OpenShift tokens expire (12-24h), so after some time all Prometheus/Thanos queries failed while other K8s API calls continued working (the K8s client handles refresh internally, but raw HTTP requests to Prometheus routes used the stale extracted token).Test plan
/mcprestart🤖 Generated with Claude Code