feat: cache project-id got from project-slug#102
Conversation
|
💬 Discussion in Slack: #pr-review-kubernetes-operator-102-feat-cache-project-id Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel. |
|
| Filename | Overview |
|---|---|
| internal/cache/resource_cache.go | New ristretto-backed cache for project-ID lookups; SetWithTTL return value is silently ignored, and NumCounters:1000 is low relative to MaxCost:1<<20. |
| internal/cache/resource_cache_test.go | Comprehensive test suite covering basic ops, TTL expiry, concurrent access, cleanup, and cache key determinism. |
| internal/services/infisicalstaticsecret/reconciler.go | Introduces getProjectIDBySlug with cache read-through pattern using InfisicalAuthRef (namespace+name) as the discriminator; nil-safe on both read and write paths. |
| internal/services/infisicalstaticsecret/handler.go | Adds resourceCache parameter to constructor and threads it into the inner reconciler; no field stored on the handler itself, which is clean. |
| internal/controller/v1beta1/infisicalstaticsecret_controller.go | Adds ResourceCache field to the reconciler struct and passes it to the handler constructor; straightforward wiring. |
| cmd/main.go | Initialises a 5-minute TTL ResourceCache at startup with proper defer Cleanup() and error handling. |
| internal/services/infisicalstaticsecret/reconciler_test.go | Import ordering tidied (no logic changes). |
Reviews (2): Last reviewed commit: "30 min cache ttl" | Re-trigger Greptile
|
@greptile review again |
adilsitos
left a comment
There was a problem hiding this comment.
just two question. But looks good!
| cache, err := ristretto.NewCache(&ristretto.Config[string, string]{ | ||
| NumCounters: 1000, | ||
| MaxCost: 1 << 20, | ||
| BufferItems: 64, | ||
| IgnoreInternalCost: true, | ||
| }) |
There was a problem hiding this comment.
question: is there a reason for us to define those as static? Couldn't we let the user define those and have a default in case they don't provide anything?
There was a problem hiding this comment.
not really, just for simplicity. Just like we do in https://github.com/Infisical/kubernetes-operator/blob/main/internal/cache/auth_cache.go#L33
adilsitos
left a comment
There was a problem hiding this comment.
LGTM! (generics were an error on the go design, it lost its essence)
We call an endpoint to resolve the project id from the projectSlug, this is not cached, so it contributes to the 429 response errors if user prefer slugs over ids.
This PR caches those calls using:
As
InfisicalAuthis bound to an org, we ensure the cached entry cannot be referencing another project with same slug from another organization.