Read API key from K8s secret on every RPC call#301
Merged
Conversation
Replaces the static capture of secret.Data in the dynamic credentials closure with a live K8s secret read via fetchAPIKeyFromSecret. This lets a rotated API key take effect on the next outgoing RPC without requiring a permission-denied cycle to evict the cached client first. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
veeral-patel
approved these changes
Apr 25, 2026
Shivs11
approved these changes
Apr 25, 2026
shashwatsuri
pushed a commit
to shashwatsuri/temporal-worker-controller
that referenced
this pull request
Apr 28, 2026
## Summary Follow-up to temporalio#300. Solves temporalio#295 more gracefully. - Replaces the static `secret.Data` capture in the `NewAPIKeyDynamicCredentials` closure with a live K8s secret read via a new `fetchAPIKeyFromSecret` helper - A rotated API key now takes effect on the next outgoing Temporal RPC — no permission-denied cycle needed to evict and re-dial the cached client - The k8s client is controller-runtime's cache-backed client, so reads hit the local informer cache (cheap in-memory lookup, not a raw API server call) - `fetchAPIKeyFromSecret` is extracted as a testable method; new test verifies the live-read and rotation behavior directly ## Test plan - [ ] `go test ./internal/controller/clientpool/...` — new `TestFetchAPIKey_CredentialClosureReadsLiveSecret` passes (verifies initial read and post-rotation read return correct values) - [ ] `go test ./internal/controller/...` — existing tests still pass - [ ] `go build ./...` — compiles clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Follow-up to #300. Solves #295 more gracefully.
secret.Datacapture in theNewAPIKeyDynamicCredentialsclosure with a live K8s secret read via a newfetchAPIKeyFromSecrethelperfetchAPIKeyFromSecretis extracted as a testable method; new test verifies the live-read and rotation behavior directlyTest plan
go test ./internal/controller/clientpool/...— newTestFetchAPIKey_CredentialClosureReadsLiveSecretpasses (verifies initial read and post-rotation read return correct values)go test ./internal/controller/...— existing tests still passgo build ./...— compiles clean🤖 Generated with Claude Code