Skip to content

Add ThreadSafe client caching to IdentityAwareBuilder#429

Open
siddimore wants to merge 1 commit intocrossplane-contrib:mainfrom
siddimore:perf/kube-client-pooling
Open

Add ThreadSafe client caching to IdentityAwareBuilder#429
siddimore wants to merge 1 commit intocrossplane-contrib:mainfrom
siddimore:perf/kube-client-pooling

Conversation

@siddimore
Copy link
Copy Markdown

@siddimore siddimore commented Mar 5, 2026

Description of your changes

Adds thread-safe client caching to IdentityAwareBuilder to avoid creating redundant Kubernetes clients for the same ProviderConfig identity. This reduces connection overhead when multiple Objects reference the same ProviderConfig.

Changes:

  • Added cachedClient struct wrapping client.Client with createdAt timestamp
  • Added cache (sync.Map) and cacheTTL fields to IdentityAwareBuilder
  • KubeForProviderConfig() now checks cache before creating clients
  • Added cacheKeyForProviderConfig() helper generating stable keys from identity source
  • Default TTL: 30 minutes (change to configurable)

Fixes #430

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Defined new tests:

  • Builder construction
  • Cache key generation
  • Cache key uniqueness
  • Client expiry behavior
  • Cache hit with valid client

@siddimore siddimore marked this pull request as ready for review March 5, 2026 19:20
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.

[Perf][IdentityAwareBuilder] Client connection pooling for ProviderConfig identities

1 participant