Cache CRD lookup and only retrieve required CRD #349

Merged
tobru merged 1 commit from feature/cache-crd-lookup into main 2026-01-16 14:31:26 +00:00
Owner

Previously, every page load for a ServiceInstance would call list_custom_resource_definition() to fetch ALL CRDs from Kubernetes,
then loop through them to find the matching one. This caused ~300ms+ latency per request, which was especially painful over the NetBird SOCKS proxy where each API call has ~66ms network overhead.

Now we:

  1. Check Django cache first (24h TTL)
  2. Use K8s API discovery (/apis/{group}/{version}) to get the correct plural name for the resource kind (handles irregular plurals like VSHNForgejo -> vshnforgejoes)
  3. Use read_custom_resource_definition(name) to fetch a single CRD directly by its name ({plural}.{group})
  4. Fall back to listing only if discovery or direct lookup fails

This reduces CRD-related latency from ~300ms to ~0ms (cached) or ~70ms (single fetch on cache miss).

Previously, every page load for a ServiceInstance would call list_custom_resource_definition() to fetch ALL CRDs from Kubernetes, then loop through them to find the matching one. This caused ~300ms+ latency per request, which was especially painful over the NetBird SOCKS proxy where each API call has ~66ms network overhead. Now we: 1. Check Django cache first (24h TTL) 2. Use K8s API discovery (/apis/{group}/{version}) to get the correct plural name for the resource kind (handles irregular plurals like VSHNForgejo -> vshnforgejoes) 3. Use read_custom_resource_definition(name) to fetch a single CRD directly by its name ({plural}.{group}) 4. Fall back to listing only if discovery or direct lookup fails This reduces CRD-related latency from ~300ms to ~0ms (cached) or ~70ms (single fetch on cache miss).
tobru force-pushed feature/cache-crd-lookup from 97a30ab2e5 to 4f735c5a83
All checks were successful
Tests / test (push) Successful in 35s
2026-01-16 13:48:27 +00:00
Compare
tobru merged commit e480381aa6 into main 2026-01-16 14:31:26 +00:00
tobru deleted branch feature/cache-crd-lookup 2026-01-16 14:31:26 +00:00
Sign in to join this conversation.
No description provided.