You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1248d79
Browse filesBrowse the repository at this point in the historyBrowse files
authored
redis: vendor redis.conf and auto-size maxmemory from the memory limit (#922)
## Summary
Add **opt-in** Redis configuration management and memory sizing. Both
Redis images default to `maxmemory 6gb`, which can exceed a smaller pod
memory limit and cause OOM kills before eviction runs.
`redisCache.config.enabled` and `redisStore.config.enabled` both default
to **false**. Default deployments retain their image configs, custom
mounts, authentication, and memory settings. All 69 default rendered
resources are byte-identical to current `main`.
Enable either service independently, or both:
```yaml
redisCache:
config:
enabled: true
redisStore:
config:
enabled: true
```
When enabled, the chart vendors the pinned images' Redis config, renders
a ConfigMap, and mounts it at `/etc/redis/redis.conf` using `subPath`.
The image entrypoint is unchanged. The chart appends `maxmemory` at
`config.maxmemoryRatio` (default 0.75) of the container memory limit,
unless `config.maxmemory` is explicitly set. Ratios must be greater than
0 and less than 1. Missing or unrecognised limits, and
`sourcegraph.localDevMode`, skip auto-sizing and retain the vendored 6gb
default unless explicitly overridden.
Other options are `existingConfig`, `maxmemoryPolicy`, and
`additionalConfig`. All config options are ignored unless
`config.enabled` is true. Chart-managed changes trigger a rollout
through a checksum annotation; existing ConfigMaps and Secret-mounted
files require a manual restart.
## Before opting in
- The chart-managed file replaces image-baked configuration, including
custom authentication, ACL, TLS, and persistence settings. Keep
management disabled to preserve those settings, or migrate them
explicitly before enabling it.
- Existing custom config mounts remain valid by default. When opting in,
remove conflicting mounts and use `config.existingConfig`, or leave
management disabled. Render-time guards explain conflicting mounts and
reserved volume names.
- `additionalConfig` and `existingConfig` use plaintext ConfigMaps. For
credentials, leave management disabled and use a Secret-mounted config.
Configure client credentials and
`redisExporter.env.REDIS_PASSWORD.valueFrom.secretKeyRef` as
appropriate; readiness alone does not verify exporter authentication.
- At the default 7Gi pod limit, opting in lowers the Redis cap from 6GiB
to 5.25GiB. Cache evicts earlier; store retains `noeviction` and rejects
writes sooner when full. An explicit `config.maxmemory: 6gb` restores
the old cap if the pod has enough memory. Auto-sizing reduces but does
not eliminate OOM risk.
- Without opting in, the old 6GiB limit and its OOM risk with smaller
pod limits remain unchanged.
Leaving management disabled is a no-op for existing deployments that
have never enabled it: no new config, mounts, checksum, or Redis
pod-template changes. Turning it off after enabling it is different:
removing the managed mount and checksum changes the pod template and
restarts Redis. Unrelated changes in a chart upgrade can still affect an
instance.
See [Enabling Redis config
management](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/michaellzc/redis-maxmemory-include-directive/charts/sourcegraph/README.md#enabling-redis-config-management)
for configuration and migration guidance.
## Verification
Final opt-in revision, after incorporating current `main`:
- `scripts/ci/lint.sh`: all four charts pass.
- `helm unittest charts/sourcegraph`: 30 suites, 173 tests, and 12
snapshots pass. Tests cover default-off behavior, independent
cache/store opt-in, parser cases, ratio validation, local-dev mode,
existing ConfigMaps, Secret mounts, collision guards, and checksum/mount
wiring.
- Default render: all 69 resources are byte-identical to `origin/main`.
Enabling both services produces byte-identical manifests to the
previously tested enabled implementation. The updated regression tests
reject the old enabled-by-default behavior.
- No-op compatibility: whole-release renders match `origin/main`
byte-for-byte for omitted flags, explicit `false`, existing
resource/image/argument/annotation overrides, and existing Secret-backed
config mounts.
- Disposable kind cluster: default-off, cache-only, store-only, and
both-enabled configurations all passed. With cache/store pod limits of
512Mi/256Mi, enabled services reported caps of 402653184/201326592
bytes; disabled services retained 6442450944 bytes. Mounts and checksum
annotations appeared only on opted-in services. All eight pods were
ready with zero restarts.
- Helm docs regenerated; clean worktree and `git diff --check`.
Runtime checks performed on the same enabled implementation before
changing the defaults:
- Cache handled 12,000 writes of 64KiB, evicted 5,394 keys, and had zero
restarts.
- Changing the ratio rolled both pods to the new caps and preserved
store data.
- Local-dev mode retained the vendored 6GiB cap.
- Secret-backed authentication rejected unauthenticated requests, passed
the chart's real readiness probes, and reported `redis_up 1` on both
exporters with Secret-backed exporter credentials.
These follow-up runtime checks cover Redis, not a fresh full Sourcegraph
deployment. The original PR reported a successful full-chart kind
deployment; that older result is not a new run of this revision.
## Checklist
- [x] Run chart lint, unit tests, render comparison, and Redis runtime
checks
- [x] Update the changelog
- [x] Document opt-in behavior and migration warnings in the chart
README
- [ ] Update the external Kubernetes update documentation, if required
(not changed in this PR)
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Filip Haftek <filip.haftek@sourcegraph.com>
Copy file name to clipboardExpand all lines: charts/sourcegraph/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ Use `**BREAKING**:` to denote a breaking change
8
8
9
9
## Unreleased
10
10
11
+
- Added opt-in Redis config management through `redisCache.config.enabled` and `redisStore.config.enabled` (both default to `false`). Default deployments retain their image configs, custom mounts, authentication, and memory settings. When enabled, the chart mounts `/etc/redis/redis.conf` and supports `existingConfig`, `maxmemory`, `maxmemoryRatio`, `maxmemoryPolicy`, and `additionalConfig`. See [Enabling Redis config management](README.md#enabling-redis-config-management) before opting in, especially when using custom images or Secret-mounted configs.
12
+
- With Redis config management enabled, the chart sizes `maxmemory` at 75% of `resources.limits.memory` to leave room for overhead; this reduces, but does not eliminate, OOM risk. Ratios must be greater than 0 and less than 1. Auto-sizing is skipped in local development mode or when the limit is absent or unrecognised. At the default 7Gi limit, opting in lowers the effective cap from 6GiB to 5.25GiB: `redis-cache` evicts earlier, but `redis-store` uses `noeviction`, so its write-error ceiling drops too. Set `redisStore.config.maxmemory: 6gb` to keep the old ceiling if the pod has sufficient memory.
11
13
- Added a `network-policy` example, which limits Executor and Executor job pods to the frontend API
12
14
- Corrected the external object storage examples to configure the shared store for frontend, worker, precise code intel, syntactic code intel, gitserver, and searcher, including credentials or workload service accounts as required.
13
15
- Removed the unused application ports from the precise and syntactic code intel worker Deployments and Services; health checks and Prometheus metrics continue to use the debug server on port 6060.
Redis readiness alone does not verify exporter authentication; check `redis_up`.
52
+
53
+
While config management is disabled, all other `config` options are ignored,
54
+
including auto-sizing, so you must size Redis memory yourself. With management enabled,
55
+
an explicit `config.maxmemory` takes precedence over auto-sizing, and
56
+
`additionalConfig`is appended last. Supported memory limits are plain byte
57
+
counts or numbers with `k`, `M`, `G`, `T`, `P`, `E`, `Ki`, `Mi`, `Gi`, `Ti`,
58
+
`Pi`, or `Ei` suffixes. If the limit is absent or unrecognised, or
59
+
`sourcegraph.localDevMode`is enabled, the vendored 6gb default remains unless
60
+
overridden explicitly.
61
+
62
+
Chart-managed config changes restart the Redis pod through a checksum
63
+
annotation. Changes to an existing ConfigMap or Secret require a manual pod
64
+
restart because `subPath` mounts do not update in running containers.
65
+
10
66
## Configuration Options
11
67
12
68
Reference the below chart for all available configuration parameters.
@@ -301,6 +357,12 @@ In addition to the documented values, all services also support the following va
301
357
| prometheus.storageAnnotations | object | `{}` | Optional annotations to add to the `prometheus` PVC |
302
358
| prometheus.storageSize | string | `"200Gi"` | PVC Storage Request for `prometheus` data volume |
303
359
| prometheus.storageSubPath | string | `""` | Optional subPath for the `prometheus` primary data volume mount |
360
+
| redisCache.config.additionalConfig | string | `""` | Additional raw redis directives appended to the vendored `redis-cache` config. Notes: This is expecting a multiline string. It renders into a ConfigMap in plaintext, so do not put secrets such as `requirepass` here or in `existingConfig` (also a ConfigMap). For secrets, set `config.enabled: false` and mount a Secret using `extraVolumeMounts`. |
361
+
| redisCache.config.enabled | bool | `false` | Opt in to a chart-managed Redis config and automatic memory sizing. Disabled by default to preserve image-baked configuration and custom `extraVolumeMounts` (including Secret mounts). When false, all other `config` options are ignored and auto-sizing is disabled. |
362
+
| redisCache.config.existingConfig | string | `""` | Name of an existing ConfigMap for `redis-cache`. It must contain a `redis.conf` key. When set, the chart-managed ConfigMap is not rendered and this one is mounted instead, so the chart no longer sizes `maxmemory`. Mutually exclusive with `additionalConfig`. |
363
+
| redisCache.config.maxmemory | string | `""` | Explicit redis `maxmemory` for `redis-cache` (for example `6gb`). Overrides the auto-computed value. Empty means compute it from the container memory limit. |
364
+
| redisCache.config.maxmemoryPolicy | string | `""` | Override the redis `maxmemory-policy` for `redis-cache`. Empty keeps the vendored default (`allkeys-lru`). |
365
+
| redisCache.config.maxmemoryRatio | float | `0.75` | Fraction of `redisCache.resources.limits.memory` used for `maxmemory` when `maxmemory` is empty. Must be greater than 0 and less than 1. Ignored when no memory limit is set or `sourcegraph.localDevMode` is enabled. An absent or unrecognised limit keeps the vendored 6gb default; use an explicit maxmemory if needed. |
304
366
| redisCache.connection.endpoint | string | `"redis-cache:6379"` | Endpoint to use for redis-cache. Supports either host:port or IANA specification |
305
367
| redisCache.connection.existingSecret | string | `""` | Name of existing secret to use for Redis endpoint The secret must contain the key `endpoint` and should follow IANA specification learn more from the [Helm docs](https://docs.sourcegraph.com/admin/install/kubernetes/helm#using-external-redis-instances) |
306
368
| redisCache.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":1000,"runAsUser":999}` | Security context for the `redis-cache` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |
@@ -320,6 +382,12 @@ In addition to the documented values, all services also support the following va
320
382
| redisExporter.image.defaultTag | string | `"6.0.0@sha256:b2ec48fc6adef31f36d525170138dec303c1c0c20c530d659f1fb7c6c54698af"` | Docker image tag for the `redis-exporter` image |
321
383
| redisExporter.image.name | string | `"redis_exporter"` | Docker image name for the `redis-exporter` image |
322
384
| redisExporter.resources | object | `{"limits":{"cpu":"10m","memory":"100Mi"},"requests":{"cpu":"10m","memory":"100Mi"}}` | Resource requests & limits for the `redis-exporter` sidecar container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
385
+
| redisStore.config.additionalConfig | string | `""` | Additional raw redis directives appended to the vendored `redis-store` config. Notes: This is expecting a multiline string. It renders into a ConfigMap in plaintext, so do not put secrets such as `requirepass` here or in `existingConfig` (also a ConfigMap). For secrets, set `config.enabled: false` and mount a Secret using `extraVolumeMounts`. |
386
+
| redisStore.config.enabled | bool | `false` | Opt in to a chart-managed Redis config and automatic memory sizing. Disabled by default to preserve image-baked configuration and custom `extraVolumeMounts` (including Secret mounts). When false, all other `config` options are ignored and auto-sizing is disabled. |
387
+
| redisStore.config.existingConfig | string | `""` | Name of an existing ConfigMap for `redis-store`. It must contain a `redis.conf` key. When set, the chart-managed ConfigMap is not rendered and this one is mounted instead, so the chart no longer sizes `maxmemory`. Mutually exclusive with `additionalConfig`. |
388
+
| redisStore.config.maxmemory | string | `""` | Explicit redis `maxmemory` for `redis-store` (for example `6gb`). Overrides the auto-computed value. Empty means compute it from the container memory limit. |
389
+
| redisStore.config.maxmemoryPolicy | string | `""` | Override the redis `maxmemory-policy` for `redis-store`. Empty keeps the vendored default (`noeviction`). |
390
+
| redisStore.config.maxmemoryRatio | float | `0.75` | Fraction of `redisStore.resources.limits.memory` used for `maxmemory` when `maxmemory` is empty. Must be greater than 0 and less than 1. Ignored when no memory limit is set or `sourcegraph.localDevMode` is enabled. An absent or unrecognised limit keeps the vendored 6gb default; use an explicit maxmemory if needed. |
323
391
| redisStore.connection.endpoint | string | `"redis-store:6379"` | Endpoint to use for redis-store. Supports either host:port or IANA specification |
324
392
| redisStore.connection.existingSecret | string | `""` | Name of existing secret to use for Redis endpoint The secret must contain the key `endpoint` and should follow IANA specification learn more from the [Helm docs](https://docs.sourcegraph.com/admin/install/kubernetes/helm#using-external-redis-instances) |
325
393
| redisStore.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":1000,"runAsUser":999}` | Security context for the `redis-store` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |
{{- range ($values.extraVolumeMounts| default list) -}}
368
+
{{- if has .mountPath (list "/etc/redis/redis.conf""/etc/redis""/etc/redis/") -}}
369
+
{{- fail (printf"%s.extraVolumeMounts must not mount over /etc/redis/redis.conf; the chart now manages that file. Move your custom redis config to %s.config.existingConfig or %s.config.additionalConfig, or set %s.config.enabled=false to preserve your existing mount."$service$service$service$service) -}}
370
+
{{- end -}}
371
+
{{- end -}}
372
+
{{- range (concat ($values.extraVolumes| default list) ($values.extraVolumeMounts| default list)) -}}
373
+
{{- ifeq (.name| toString) "redis-conf" -}}
374
+
{{- fail (printf"%s must not define a volume named 'redis-conf'; the chart reserves that name for the redis config mount."$service) -}}
0 commit comments