Repository navigation
Expand file tree
/
Copy pathredisfailover.yaml
More file actions
214 lines (211 loc) · 9.71 KB
/
Copy pathredisfailover.yaml
File metadata and controls
214 lines (211 loc) · 9.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
{{- /* One image for the data pods and the Sentinels, resolved once so they cannot drift apart. */}}
{{- $redisImage := printf "redis:%s" (include "redis.versionMap" $) }}
{{- $tlsEnabled := (include "redis.tls.enabled" .) | eq "true" -}}
{{- /*
A Sentinel holds only its configuration and failover state, so the Redis
sizing over-provisions it. An empty sentinel block still falls back to the
Redis sizing, so existing instances render unchanged on upgrade.
An empty sentinel.resources map counts as unset, mirroring how an empty
top-level resources falls back to resourcesPreset.
*/}}
{{- $sentinel := .Values.sentinel | default dict -}}
{{- /*
A lone Redis pod has no replica to promote, so three Sentinels would only
watch it. One Sentinel still lets the operator find the master (its quorum is
replicas/2+1, so 1). The operator gives the Sentinel Deployment a PDB with
minAvailable 1 whenever Redis has two replicas or fewer, which on a single
Sentinel would block every node drain, so that PDB is dropped with it; the
operator does not delete a PDB it stops managing, hence
hooks/sentinel-pdb.yaml.
*/}}
{{- $sentinelReplicas := include "redis.sentinelReplicas" . | int -}}
{{- $sentinelPreset := $sentinel.resourcesPreset | default .Values.resourcesPreset -}}
{{- $sentinelResources := .Values.resources -}}
{{- if or $sentinel.resources $sentinel.resourcesPreset -}}
{{- $sentinelResources = $sentinel.resources | default dict -}}
{{- end -}}
{{- if .Values.authEnabled }}
{{- $existingPassword := lookup "v1" "Secret" .Release.Namespace (printf "%s-auth" .Release.Name) }}
{{- $password := randAlphaNum 32 | b64enc }}
{{- if $existingPassword }}
{{- $password = index $existingPassword.data "password" }}
{{- end }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-auth
data:
password: {{ $password }}
{{- end }}
---
apiVersion: databases.spotahome.com/v1
kind: RedisFailover
metadata:
name: {{ .Release.Name }}
labels:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
# The freshworks-oss operator reconciles only RedisFailovers whose
# operator-group label matches its OPERATOR_GROUP_ID (see
# packages/system/redis-operator/values.yaml); without it the CR is
# silently ignored. Keep both sides in sync.
redis-failover.freshworks.com/operator-group: cozystack
spec:
{{- if $tlsEnabled }}
tls:
enabled: true
authClients: {{ include "redis.tls.authClients" . | quote }}
# When TLS is on the operator always publishes an Opaque Secret holding just
# ca.crt; this only chooses its name, which otherwise defaults to
# "<tls-secret>-ca" — a name that reads as though it belonged to the leaf.
# Nothing in the tenant read path consumes it: the trust anchor reaches the
# tenant as the <release>.tenant-ca projection declared in
# templates/tenant-projection.yaml, sourced from the chart's own CA Secret.
caCertSecretName: {{ .Release.Name }}.ca-cert
certificateSecret:
secretName: {{ .Release.Name }}.tls
{{- end }}
sentinel:
# Sentinels run the same image as the data pods. Pinned explicitly because
# the operator's compiled-in default (redis:7.2.4-alpine in freshworks-oss
# v3.3.5) would otherwise move them on an operator upgrade. Unlike the data
# pods they keep no RDB, only a sentinel.conf the init container rewrites
# on every start, so a chart rollback to an older engine is safe here.
image: {{ $redisImage | quote }}
replicas: {{ $sentinelReplicas }}
{{- if eq $sentinelReplicas 1 }}
disablePodDisruptionBudget: true
{{- end }}
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list $sentinelPreset $sentinelResources $) | nindent 6 }}
{{- with (.Values.affinity).sentinel }}
affinity: {{- toYaml . | nindent 6 }}
{{- end }}
redis:
image: {{ $redisImage | quote }}
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.resourcesPreset .Values.resources $) | nindent 6 }}
{{- with (.Values.affinity).redis }}
affinity: {{- toYaml . | nindent 6 }}
{{- end }}
replicas: {{ .Values.replicas }}
{{- with .Values.size }}
storage:
persistentVolumeClaim:
metadata:
name: redisfailover-persistent-data
labels:
app.kubernetes.io/component: redis
app.kubernetes.io/instance: {{ $.Release.Name }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ . }}
{{- with $.Values.storageClass }}
storageClassName: {{ . }}
{{- end }}
{{- end }}
exporter:
enabled: true
image: oliver006/redis_exporter:v1.55.0@sha256:d82625bda93823fb40de881ffbb45b65aca772a39c30141387f92314c258da5d
args:
- --web.telemetry-path
- /metrics
env:
- name: REDIS_EXPORTER_LOG_FORMAT
value: txt
customConfig:
- tcp-keepalive 0
- loglevel notice
{{- if not .Values.size }}
- appendonly no
{{- end }}
{{- /* The operator applies these lines with CONFIG SET on every reconcile and never
resets a line that disappears, so each one is always rendered with an explicit
value: switching back to the default must reach the running pods too. The
schedule is the Redis 7 and 8 default. */}}
{{- if and .Values.size .Values.snapshots }}
- save 3600 1 300 100 60 10000
{{- else }}
- save ""
{{- end }}
{{- $maxmemory := 0 }}
{{- if not (kindIs "invalid" .Values.maxmemory) }}
{{- $maxmemoryBytes := include "cozy-lib.resources.toFloat" (.Values.maxmemory | toString) | float64 }}
{{- /* Checked before the int64 cast, which would truncate a sub-byte quantity such
as 512m (0.512 bytes) or -512m to 0, and Redis reads 0 as no limit. */}}
{{- if lt $maxmemoryBytes 0.0 }}
{{- fail (printf "maxmemory (%v) must not be negative" .Values.maxmemory) }}
{{- end }}
{{- if ne (floor $maxmemoryBytes) $maxmemoryBytes }}
{{- fail (printf "maxmemory (%v) must be a whole number of bytes, e.g. 512Mi rather than 512m (millibytes)" .Values.maxmemory) }}
{{- end }}
{{- $maxmemory = $maxmemoryBytes | int64 }}
{{- $redisResources := include "cozy-lib.resources.defaultingSanitize" (list .Values.resourcesPreset .Values.resources $) | fromYaml }}
{{- $memoryRequest := include "cozy-lib.resources.toFloat" (dig "requests" "memory" "0" $redisResources | toString) | float64 }}
{{- /* The operator compares maxmemory with 90% of the pod's memory request
(reservedPodMemoryPercent) and silently skips the line when it is larger. */}}
{{- $allowed := mulf $memoryRequest 0.9 | int64 }}
{{- if gt $maxmemory $allowed }}
{{- fail (printf "maxmemory (%v, %d bytes) must be at most 90%% of the Redis memory request (%d bytes): the operator ignores a larger value" .Values.maxmemory $maxmemory $allowed) }}
{{- end }}
{{- end }}
{{- /* The operator sends these in list order, and lowering maxmemory below the
dataset evicts at once, so the policy has to be in place first. */}}
- maxmemory-policy {{ .Values.maxmemoryPolicy | default "noeviction" }}
- maxmemory {{ $maxmemory }}
{{- /* A master with `replicas` pods has replicas-1 replicas, so a requirement of
`replicas` or more can never be met and the master would refuse every write. */}}
{{- if and (not (kindIs "invalid" .Values.minReplicasToWrite)) (ge (.Values.minReplicasToWrite | int) (.Values.replicas | int)) }}
{{- fail (printf "minReplicasToWrite (%d) must be below replicas (%d): the master has replicas-1 replicas, so the master would refuse every write" (.Values.minReplicasToWrite | int) (.Values.replicas | int)) }}
{{- end }}
{{- if not (kindIs "invalid" .Values.minReplicasToWrite) }}
- min-replicas-to-write {{ .Values.minReplicasToWrite | int }}
{{- end }}
{{- /* Redis treats 0 in either directive as "check disabled" (redis.conf), so a lag of 0
next to a replica requirement would silently turn the protection off. */}}
{{- if and (not (kindIs "invalid" .Values.minReplicasToWrite)) (gt (.Values.minReplicasToWrite | int) 0) (not (kindIs "invalid" .Values.minReplicasMaxLag)) (le (.Values.minReplicasMaxLag | int) 0) }}
{{- fail "minReplicasMaxLag must be at least 1 when minReplicasToWrite is set: Redis treats 0 as disabling the check" }}
{{- end }}
{{- if not (kindIs "invalid" .Values.minReplicasMaxLag) }}
- min-replicas-max-lag {{ .Values.minReplicasMaxLag | int }}
{{- end }}
{{- if .Values.authEnabled }}
auth:
secretPath: {{ .Release.Name }}-auth
{{- end }}
---
apiVersion: cozystack.io/v1alpha1
kind: WorkloadMonitor
metadata:
name: {{ $.Release.Name }}-redis
namespace: {{ $.Release.Namespace }}
labels:
workloads.cozystack.io/resource-preset: {{ .Values.resourcesPreset | quote }}
spec:
minReplicas: 1
replicas: {{ .Values.replicas }}
kind: redis
type: redis
selector:
app.kubernetes.io/component: redis
app.kubernetes.io/instance: {{ $.Release.Name }}
version: {{ $.Chart.Version }}
---
apiVersion: cozystack.io/v1alpha1
kind: WorkloadMonitor
metadata:
name: {{ $.Release.Name }}-sentinel
namespace: {{ $.Release.Namespace }}
labels:
workloads.cozystack.io/resource-preset: {{ $sentinelPreset | quote }}
spec:
minReplicas: {{ ternary 1 2 (eq $sentinelReplicas 1) }}
replicas: {{ $sentinelReplicas }}
kind: redis
type: sentinel
selector:
app.kubernetes.io/component: sentinel
app.kubernetes.io/instance: {{ $.Release.Name }}
version: {{ $.Chart.Version }}