Skip to content

Commit 69008df

Browse files
feat(haproxy): add configurable cache support with global toggle
Add haproxy_lb_cache_enabled variable to control cache functionality and conditionally render cache configuration based on this setting
1 parent cb84ef3 commit 69008df

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

roles/haproxy_lb/defaults/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ haproxy_lb_k8s_cluster_nodes: {}
2121
# - Domain groups: domain name (e.g., "example.com")
2222
haproxy_lb_backend_extra_config: {}
2323
haproxy_lb_quic_enabled: false
24+
haproxy_lb_cache_enabled: false

roles/haproxy_lb/templates/haproxy.conf.j2

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ userlist {{ group.group }}
5858
{% endfor %}
5959
{% endfor %}
6060

61+
{% if haproxy_lb_cache_enabled | default(false) %}
6162
cache global_cache
6263
total-max-size 512 # 512 MB
6364
max-object-size 102400 # 100 KB
6465
max-age 600 # Stay in cache for 10 minutes
6566
process-vary on
6667
max-secondary-entries 12
68+
{% endif %}
6769

6870
listen stats
6971
bind 127.0.0.1:32700
@@ -216,7 +218,7 @@ frontend http
216218
{% if haproxy_lb_sites[site].path is defined %}
217219
acl path_{{ site }} path -i -m beg {{ haproxy_lb_sites[site].path }}
218220
{% endif %}
219-
{% if haproxy_lb_sites[site].use_cache is defined and haproxy_lb_sites[site].use_cache == 'true' %}
221+
{% if (haproxy_lb_cache_enabled | default(false)) and haproxy_lb_sites[site].use_cache is defined and haproxy_lb_sites[site].use_cache == 'true' %}
220222
http-request cache-use global_cache if host_{{ site }}
221223
http-response cache-store global_cache if host_{{ site }}
222224
{% endif %}
@@ -263,7 +265,7 @@ frontend http
263265
{% if svc.metadata.annotations["ethquokkaops.io/internal-only"] is defined %}
264266
http-request deny if host_{{ cluster.item }}_{{ svc.metadata.namespace }}_{{ svc.metadata.name }}_{{ portname }} !{ src 10.128.0.0/9 }
265267
{% endif %}
266-
{% if svc.metadata.annotations["ethquokkaops.io/use_cache"] is defined and svc.metadata.annotations["ethquokkaops.io/use_cache"] == 'true' %}
268+
{% if (haproxy_lb_cache_enabled | default(false)) and svc.metadata.annotations["ethquokkaops.io/use_cache"] is defined and svc.metadata.annotations["ethquokkaops.io/use_cache"] == 'true' %}
267269
http-request cache-use global_cache if host_{{ cluster.item }}_{{ svc.metadata.namespace }}_{{ svc.metadata.name }}_{{ portname }}
268270
http-response cache-store global_cache if host_{{ cluster.item }}_{{ svc.metadata.namespace }}_{{ svc.metadata.name }}_{{ portname }}
269271
{% endif %}
@@ -298,7 +300,7 @@ frontend http
298300
{% if svc.metadata.annotations["ethquokkaops.io/internal-only"] is defined %}
299301
http-request deny if { hdr(host) -i {{ domain }} } !{ src 10.128.0.0/9 }
300302
{% endif %}
301-
{% if svc.metadata.annotations["ethquokkaops.io/use_cache"] is defined and svc.metadata.annotations["ethquokkaops.io/use_cache"] == 'true' %}
303+
{% if (haproxy_lb_cache_enabled | default(false)) and svc.metadata.annotations["ethquokkaops.io/use_cache"] is defined and svc.metadata.annotations["ethquokkaops.io/use_cache"] == 'true' %}
302304
http-request cache-use global_cache if host_{{ cluster.item }}_{{ svc.metadata.namespace }}_{{ svc.metadata.name }}
303305
http-response cache-store global_cache if host_{{ cluster.item }}_{{ svc.metadata.namespace }}_{{ svc.metadata.name }}
304306
{% endif %}

0 commit comments

Comments
 (0)