feat: hot-reload apiToken#592
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #592 +/- ##
==========================================
+ Coverage 70.93% 71.51% +0.57%
==========================================
Files 24 25 +1
Lines 2164 2243 +79
==========================================
+ Hits 1535 1604 +69
- Misses 500 507 +7
- Partials 129 132 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds support for hot-reloading the Linode API token (PAT) by reading it from a mounted Secret file with a short TTL cache, enabling token rotation without restarting the CSI controller. It updates the Linode client authentication flow to inject the bearer token per HTTP request via a TokenProvider, and wires Helm/kustomize deployment options and documentation to support the file-mount mode.
Changes:
- Introduces a token abstraction (
TokenProvider) plus file-backed token loading with TTL caching and env fallback (pkg/linode-client/token.go), with unit tests. - Updates Linode client creation to authenticate per-request using a custom HTTP transport, enabling token hot-reload without rebuilding the client.
- Adds Helm chart + deployment manifest options/docs for mounting the token Secret as a file and configuring the token file path/TTL.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/linode-client/token.go | Adds token providers (static + file-backed w/ TTL cache) and selection logic from file/env. |
| pkg/linode-client/token_test.go | Unit tests for token providers, cache behavior, and env/file selection. |
| pkg/linode-client/linode_client.go | Switches auth to per-request token injection via a custom RoundTripper. |
| pkg/linode-client/linode_client_test.go | Adds tests validating per-request Authorization and error behavior. |
| main.go | Uses token providers to build the Linode client and logs token source for controller mode. |
| helm-chart/csi-driver/values.yaml | Documents new secretRef.mountSecret / secretRef.mountPath options and updates examples. |
| helm-chart/csi-driver/templates/csi-linode-controller.yaml | Adds conditional token Secret mount + LINODE_API_TOKEN_FILE wiring for hot-reload mode. |
| docs/deployment.md | Documents how to enable hot-reload token mode via Helm and what behavior to expect. |
| deploy/kubernetes/base/ss-csi-linode-controller.yaml | Adds commented opt-in blocks for file-mounted token mode in raw manifests. |
340ca49 to
337767f
Compare
Quote remaining Helm Secret fields to avoid YAML type coercion, and clarify StaticTokenProvider's empty-token error for flag/env/secret sources.
Inspired by linode/linode-cloud-controller-manager#576, adds the ability to store
apiTokenfor hot-reloading the token when rotated.General:
Pull Request Guidelines:
➜ linode-blockstorage-csi-driver git:(feat/hot-reload-token) go test -v ./pkg/linode-client/... === RUN TestNewLinodeClient === RUN TestNewLinodeClient/Valid_input_without_custom_API_URL === RUN TestNewLinodeClient/Valid_input_with_custom_API_URL === RUN TestNewLinodeClient/Invalid_API_URL --- PASS: TestNewLinodeClient (0.00s) --- PASS: TestNewLinodeClient/Valid_input_without_custom_API_URL (0.00s) --- PASS: TestNewLinodeClient/Valid_input_with_custom_API_URL (0.00s) --- PASS: TestNewLinodeClient/Invalid_API_URL (0.00s) === RUN TestNewLinodeClientWithTokenProviderNil --- PASS: TestNewLinodeClientWithTokenProviderNil (0.00s) === RUN TestTokenTransportAuthorization --- PASS: TestTokenTransportAuthorization (0.00s) === RUN TestTokenTransportUsesProviderError --- PASS: TestTokenTransportUsesProviderError (0.00s) === RUN TestTokenFileProviderCache --- PASS: TestTokenFileProviderCache (0.00s) === RUN TestTokenFileProviderEmptyFile --- PASS: TestTokenFileProviderEmptyFile (0.00s) === RUN TestTokenFileProviderMissingFile --- PASS: TestTokenFileProviderMissingFile (0.00s) === RUN TestTokenFileCacheTTLFromEnv === RUN TestTokenFileCacheTTLFromEnv/default === RUN TestTokenFileCacheTTLFromEnv/configured === RUN TestTokenFileCacheTTLFromEnv/invalid === RUN TestTokenFileCacheTTLFromEnv/non-positive --- PASS: TestTokenFileCacheTTLFromEnv (0.00s) --- PASS: TestTokenFileCacheTTLFromEnv/default (0.00s) --- PASS: TestTokenFileCacheTTLFromEnv/configured (0.00s) --- PASS: TestTokenFileCacheTTLFromEnv/invalid (0.00s) --- PASS: TestTokenFileCacheTTLFromEnv/non-positive (0.00s) === RUN TestTokenProviderFromFileOrEnv === RUN TestTokenProviderFromFileOrEnv/uses_file_when_available === RUN TestTokenProviderFromFileOrEnv/falls_back_to_env_when_file_missing === RUN TestTokenProviderFromFileOrEnv/errors_when_both_unavailable --- PASS: TestTokenProviderFromFileOrEnv (0.00s) --- PASS: TestTokenProviderFromFileOrEnv/uses_file_when_available (0.00s) --- PASS: TestTokenProviderFromFileOrEnv/falls_back_to_env_when_file_missing (0.00s) --- PASS: TestTokenProviderFromFileOrEnv/errors_when_both_unavailable (0.00s) === RUN TestStaticTokenProvider --- PASS: TestStaticTokenProvider (0.00s) PASS ok github.com/linode/linode-blockstorage-csi-driver/pkg/linode-client (cached)Continuation of #591 - CI doesn't like my fork☹️