Skip to content

Commit 8723462

Browse files
committed
feat(redis): add affinity configuration
Signed-off-by: kastakhov <[email protected]>
1 parent 215e582 commit 8723462

8 files changed

Lines changed: 163 additions & 14 deletions

File tree

‎api/apps/v1alpha1/redis/types.go‎

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/redis/zz_generated.deepcopy.go‎

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/apps/redis/README.md‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ Service utilizes the freshworks-oss Redis Operator (a maintained fork of the arc
1515

1616
### Common parameters
1717

18-
| Name | Description | Type | Value |
19-
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- | --------- |
20-
| `replicas` | Number of Redis replicas. | `int` | `2` |
21-
| `resources` | Explicit CPU and memory configuration for each Redis replica. When omitted, the preset defined in `resourcesPreset` is applied. | `object` | `{}` |
22-
| `resources.cpu` | CPU available to each replica. | `quantity` | `""` |
23-
| `resources.memory` | Memory (RAM) available to each replica. | `quantity` | `""` |
24-
| `resourcesPreset` | Default sizing preset used when `resources` is omitted. | `string` | `t1.nano` |
25-
| `size` | Persistent Volume Claim size available for application data. | `quantity` | `1Gi` |
26-
| `storageClass` | StorageClass used to store the data. | `string` | `""` |
27-
| `external` | Enable external access from outside the cluster. Can be enabled only when the instance is created, together with `tls.enabled: true`; turning it on for an existing instance, or changing `tls.enabled` while it is on, is refused at admission. | `bool` | `false` |
28-
| `version` | Redis major version to deploy. The Redis and Sentinel pods run the same image. | `string` | `v8` |
18+
| Name | Description | Type | Value |
19+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- | --------- |
20+
| `replicas` | Number of Redis replicas. | `int` | `2` |
21+
| `resources` | Explicit CPU and memory configuration for each Redis replica. When omitted, the preset defined in `resourcesPreset` is applied. | `object` | `{}` |
22+
| `resources.cpu` | CPU available to each replica. | `quantity` | `""` |
23+
| `resources.memory` | Memory (RAM) available to each replica. | `quantity` | `""` |
24+
| `resourcesPreset` | Default sizing preset used when `resources` is omitted. | `string` | `t1.nano` |
25+
| `affinity` | Kubernetes affinity configuration for Redis and Sentinel pods. | `object` | `{}` |
26+
| `affinity.redis` | Kubernetes Affinity for Redis pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended. | `*object` | `{}` |
27+
| `affinity.sentinel` | Kubernetes Affinity for Sentinel pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended. | `*object` | `{}` |
28+
| `size` | Persistent Volume Claim size available for application data. | `quantity` | `1Gi` |
29+
| `storageClass` | StorageClass used to store the data. | `string` | `""` |
30+
| `external` | Enable external access from outside the cluster. Can be enabled only when the instance is created, together with `tls.enabled: true`; turning it on for an existing instance, or changing `tls.enabled` while it is on, is refused at admission. | `bool` | `false` |
31+
| `version` | Redis major version to deploy. The Redis and Sentinel pods run the same image. | `string` | `v8` |
2932

3033

3134
### TLS parameters

‎packages/apps/redis/templates/redisfailover.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ spec:
6767
image: {{ $redisImage | quote }}
6868
replicas: 3
6969
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list $sentinelPreset $sentinelResources $) | nindent 6 }}
70+
{{- with (.Values.affinity).sentinel }}
71+
affinity: {{- toYaml . | nindent 6 }}
72+
{{- end }}
7073
redis:
7174
image: {{ $redisImage | quote }}
7275
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.resourcesPreset .Values.resources $) | nindent 6 }}
76+
{{- with (.Values.affinity).redis }}
77+
affinity: {{- toYaml . | nindent 6 }}
78+
{{- end }}
7379
replicas: {{ .Values.replicas }}
7480
{{- with .Values.size }}
7581
storage:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
suite: Redis and Sentinel affinity
2+
3+
release:
4+
name: my-redis
5+
namespace: tenant-test
6+
7+
templates:
8+
- templates/redisfailover.yaml
9+
10+
tests:
11+
- it: omits affinity by default
12+
documentSelector:
13+
path: kind
14+
value: RedisFailover
15+
asserts:
16+
- notExists:
17+
path: spec.redis.affinity
18+
- notExists:
19+
path: spec.sentinel.affinity
20+
21+
- it: omits affinity when parent is null
22+
set:
23+
affinity: null
24+
documentSelector:
25+
path: kind
26+
value: RedisFailover
27+
asserts:
28+
- notExists:
29+
path: spec.redis.affinity
30+
- notExists:
31+
path: spec.sentinel.affinity
32+
33+
- it: keeps Redis and Sentinel affinity independent
34+
set:
35+
affinity:
36+
redis:
37+
nodeAffinity:
38+
requiredDuringSchedulingIgnoredDuringExecution:
39+
nodeSelectorTerms:
40+
- matchExpressions:
41+
- key: topology.kubernetes.io/zone
42+
operator: In
43+
values: [zone-a]
44+
sentinel:
45+
podAntiAffinity:
46+
requiredDuringSchedulingIgnoredDuringExecution:
47+
- labelSelector:
48+
matchLabels:
49+
app.kubernetes.io/component: sentinel
50+
topologyKey: kubernetes.io/hostname
51+
documentSelector:
52+
path: kind
53+
value: RedisFailover
54+
asserts:
55+
- equal:
56+
path: spec.redis.affinity
57+
value:
58+
nodeAffinity:
59+
requiredDuringSchedulingIgnoredDuringExecution:
60+
nodeSelectorTerms:
61+
- matchExpressions:
62+
- key: topology.kubernetes.io/zone
63+
operator: In
64+
values: [zone-a]
65+
- equal:
66+
path: spec.sentinel.affinity
67+
value:
68+
podAntiAffinity:
69+
requiredDuringSchedulingIgnoredDuringExecution:
70+
- labelSelector:
71+
matchLabels:
72+
app.kubernetes.io/component: sentinel
73+
topologyKey: kubernetes.io/hostname

‎packages/apps/redis/values.schema.json‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@
9494
"2xlarge"
9595
]
9696
},
97+
"affinity": {
98+
"description": "Kubernetes affinity configuration for Redis and Sentinel pods.",
99+
"type": "object",
100+
"default": {},
101+
"properties": {
102+
"redis": {
103+
"description": "Kubernetes Affinity for Redis pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended.",
104+
"type": "object",
105+
"default": {},
106+
"x-kubernetes-preserve-unknown-fields": true
107+
},
108+
"sentinel": {
109+
"description": "Kubernetes Affinity for Sentinel pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended.",
110+
"type": "object",
111+
"default": {},
112+
"x-kubernetes-preserve-unknown-fields": true
113+
}
114+
}
115+
},
97116
"size": {
98117
"description": "Persistent Volume Claim size available for application data.",
99118
"default": "1Gi",

‎packages/apps/redis/values.yaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ resources: {}
6464
## @param {ResourcesPreset} resourcesPreset="t1.nano" - Default sizing preset used when `resources` is omitted.
6565
resourcesPreset: "t1.nano"
6666

67+
## @typedef {struct} AffinitySpec - Kubernetes affinity configuration.
68+
## @field {*object} [redis] - Kubernetes Affinity for Redis pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended.
69+
## @field {*object} [sentinel] - Kubernetes Affinity for Sentinel pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended.
70+
71+
## @param {AffinitySpec} [affinity] - Kubernetes affinity configuration for Redis and Sentinel pods.
72+
affinity:
73+
redis: {}
74+
sentinel: {}
75+
6776
## @param {quantity} size - Persistent Volume Claim size available for application data.
6877
size: 1Gi
6978

0 commit comments

Comments
 (0)