Files
computer-playbook/roles/svc-db-redis/templates/service.yml.j2
kevinveenbirkenbachandClaude Opus 5.5 45d956e5ea fix(sidecars): cap an engine's sidecar at its provider's size
A Redis sidecar whose consumer declares no services.redis.mem_limit
runs in a container that inherits the consumer's primary entity limit.
Since the lookup replaced the old filter, maxmemory followed that limit
and rose from 204 MiB to between 819 and 3276 MiB in 17 roles.

lookup('service_memory_mb', ..., provider=<role>) caps the result at
the same share of the provider's own limit when the application does
not declare one for that service. A declared limit is not capped, and a
container smaller than the provider keeps its own share. The Redis
sidecar passes provider='svc-db-redis': those 17 roles get 409 MiB, the
seven with a 256 MiB container stay at 204.

The lookup now rejects unknown options and a provider that is no role
or declares no limit for the service, so a misspelled option fails
instead of silently lifting the cap.

The memcached sidecar's literal -m 64 takes the same lookup and keeps
its value.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 01:30:01 +02:00

43 lines
1.8 KiB
Django/Jinja

# This template needs to be included in compose.yml, which depend on redis
redis:
{{ lookup('container_image', 'svc-db-redis', 'redis') }}
{{ lookup('compose_only', 'container_name', ((application_id | get_entity_name) ~ '-redis')) }}
{{ lookup('compose_restart') }}
logging:
driver: journald
volumes:
- redis:/data
command:
- redis-server
- --appendonly
- "no"
- --save
- ""
- --maxmemory {{ lookup('service_memory_mb', application_id, 'redis', 0.8, provider='svc-db-redis') }}mb
- --maxmemory-policy
- "allkeys-lru"
# nocheck: container-healthcheck-literal probes every second, so the SPOT's 5s start cadence would report healthy later than this block already does
healthcheck: # nocheck: healthcheck-timing-override, healthcheck-start-period-covers-interval a swarm-init gate that must clear in seconds, so it runs without a start window rather than inside one
test: ["CMD", "redis-cli", "ping"]
# nocheck: healthcheck-timing-override probes every second on purpose, which is why start_interval is left off
interval: 1s
# nocheck: healthcheck-timing-override a redis ping needs no five seconds
timeout: 3s
retries: 30
networks: # nocheck: networks-literal local sidecar inside consumer stack, default-only attachment
- default
{% macro include_resource_for(svc, indent=4) -%}
{% set service_name = svc -%}
{%- set _snippet -%}
{% include 'roles/sys-svc-container/templates/resource.yml.j2' %}
{%- endset -%}
{{ _snippet | indent(indent, true) }}
{%- endmacro %}
{% if DEPLOYMENT_MODE == 'compose' %}
{{ include_resource_for('redis') }}
{% endif %}
{% set service_name = 'redis' %}
{% set service_replicas_forced = 1 %}
{% include 'roles/sys-svc-container/templates/deploy.yml.j2' %}
{{ "\n" }}