Skip to content

feat(cache): add configurable JetStream KV replica count#3024

Merged
jiparis merged 1 commit into
chainloop-dev:mainfrom
jiparis:jiparis/fix-policy-cache
Apr 13, 2026
Merged

feat(cache): add configurable JetStream KV replica count#3024
jiparis merged 1 commit into
chainloop-dev:mainfrom
jiparis:jiparis/fix-policy-cache

Conversation

@jiparis

@jiparis jiparis commented Apr 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Add WithReplicas option to pkg/cache so NATS JetStream KV buckets can be created with a configurable replica count. Max 3 replicas
  • Thread replica count from Helm values → proto config → natsconn.ConfigReloadableConnection → attestationbundle/policyevalbundle caches
  • Fixes inconsistent reads in clustered NATS deployments where KV buckets defaulted to 1 replica

Follow-up of PFM-5440.

Comment thread app/controlplane/cmd/main.go Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 12 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="deployment/chainloop/values.yaml">

<violation number="1" location="deployment/chainloop/values.yaml:197">
P3: Bump the Helm chart patch version in Chart.yaml when updating values.yaml so chart consumers can pick up the change.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread deployment/chainloop/values.yaml Outdated
@jiparis jiparis force-pushed the jiparis/fix-policy-cache branch 2 times, most recently from a4e865d to 00a734e Compare April 13, 2026 11:01
@jiparis jiparis marked this pull request as draft April 13, 2026 11:19
NATS KV buckets in pkg/cache were created with the default replica
count of 1, causing inconsistent reads in clustered NATS deployments.
Add a WithReplicas option to pkg/cache and thread the replica count
from Helm values through proto config, natsconn, and bundle caches.

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis jiparis force-pushed the jiparis/fix-policy-cache branch from 00a734e to 6c558bc Compare April 13, 2026 14:26
@jiparis jiparis marked this pull request as ready for review April 13, 2026 14:34

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 12 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/natsconn/natsconn.go">

<violation number="1" location="pkg/natsconn/natsconn.go:57">
P2: `Replicas` is documented as defaulting to 1, but `New` passes through `cfg.Replicas` without applying that default.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread pkg/natsconn/natsconn.go

l := log.NewHelper(log.With(logger, "component", "natsconn"))
rc := &ReloadableConnection{logger: l}
rc := &ReloadableConnection{logger: l, Replicas: cfg.Replicas}

@cubic-dev-ai cubic-dev-ai Bot Apr 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Replicas is documented as defaulting to 1, but New passes through cfg.Replicas without applying that default.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/natsconn/natsconn.go, line 57:

<comment>`Replicas` is documented as defaulting to 1, but `New` passes through `cfg.Replicas` without applying that default.</comment>

<file context>
@@ -52,7 +54,7 @@ func New(cfg *Config, logger log.Logger) (*ReloadableConnection, func(), error)
 
 	l := log.NewHelper(log.With(logger, "component", "natsconn"))
-	rc := &ReloadableConnection{logger: l}
+	rc := &ReloadableConnection{logger: l, Replicas: cfg.Replicas}
 
 	opts := []nats.Option{
</file context>
Suggested change
rc := &ReloadableConnection{logger: l, Replicas: cfg.Replicas}
replicas := cfg.Replicas
if replicas <= 0 {
replicas = 1
}
rc := &ReloadableConnection{logger: l, Replicas: replicas}
Fix with Cubic

@jiparis jiparis merged commit 4873f61 into chainloop-dev:main Apr 13, 2026
15 checks passed
@jiparis jiparis deleted the jiparis/fix-policy-cache branch April 13, 2026 14:55
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.

3 participants