Skip to content

Renew token from token file before it expires#49

Merged
iabudiab merged 6 commits into
swiftkube:mainfrom
t089:renew-token
Mar 29, 2026
Merged

Renew token from token file before it expires#49
iabudiab merged 6 commits into
swiftkube:mainfrom
t089:renew-token

Conversation

@t089

@t089 t089 commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Currently the client reads the token from the service account only once when the client is created. When the service account token is short-lived, the client will fail to execute any request with a 401 error once the token has expired. The only current workaround is to re-create the entire client.

This fix adds a new KubernetesClientAuthentication.tokenFile and a CachedFileTokenSource which reads the token from the token file and caches it for 1 minute. If the client needs a token after it expired, the CachedFileTokenSource will read it again and cache it. This follows roughly the strategy used by client-go.

@iabudiab

Copy link
Copy Markdown
Member

@t089 Hey there, thank you for the PR. Nice addition. Lots of things going on right now but I'll definitely try to merge this as soon as possible.

@t089

t089 commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Note, that this PR contains a some unrelated linter fixes to make the CI happy. If you prefer, we can split this out.

/// Bearer token authentication scheme via a valid API token.
case bearer(token: String)
/// File-backed bearer token with a cached token source that re-reads from disk periodically.
case tokenFile(source: CachedFileTokenSource)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a new case to a public enum is strictly speaking a SemVer major breaking change. Since this lib has no tagged 1.0 version, I think we are fine.

@iabudiab

Copy link
Copy Markdown
Member

Note, that this PR contains a some unrelated linter fixes to make the CI happy. If you prefer, we can split this out.

Hey, no need to split. I've skimmed through and all the changes look good. Will merge probably tomorrow after work.
Thanks again 👍

@iabudiab iabudiab merged commit e30bd03 into swiftkube:main Mar 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants