Skip to content

Commit 1f0312a

Browse files
authored
make minimum limits boundaries configurable (zalando#808)
* make minimum limits boundaries configurable * add e2e test
1 parent fddaf0f commit 1f0312a

File tree

17 files changed

+175
-93
lines changed

17 files changed

+175
-93
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ spec:
179179
default_memory_request:
180180
type: string
181181
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
182+
min_cpu_limit:
183+
type: string
184+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
185+
min_memory_limit:
186+
type: string
187+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
182188
timeouts:
183189
type: object
184190
properties:

charts/postgres-operator/values-crd.yaml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,17 @@ configKubernetes:
115115
# configure resource requests for the Postgres pods
116116
configPostgresPodResources:
117117
# CPU limits for the postgres containers
118-
default_cpu_limit: "3"
119-
# cpu request value for the postgres containers
118+
default_cpu_limit: "1"
119+
# CPU request value for the postgres containers
120120
default_cpu_request: 100m
121121
# memory limits for the postgres containers
122-
default_memory_limit: 1Gi
122+
default_memory_limit: 500Mi
123123
# memory request value for the postgres containers
124124
default_memory_request: 100Mi
125+
# hard CPU minimum required to properly run a Postgres cluster
126+
min_cpu_limit: 250m
127+
# hard memory minimum required to properly run a Postgres cluster
128+
min_memory_limit: 250Mi
125129

126130
# timeouts related to some operator actions
127131
configTimeouts:
@@ -251,7 +255,7 @@ configScalyr:
251255
# CPU rquest value for the Scalyr sidecar
252256
scalyr_cpu_request: 100m
253257
# Memory limit value for the Scalyr sidecar
254-
scalyr_memory_limit: 1Gi
258+
scalyr_memory_limit: 500Mi
255259
# Memory request value for the Scalyr sidecar
256260
scalyr_memory_request: 50Mi
257261

@@ -272,13 +276,13 @@ serviceAccount:
272276

273277
priorityClassName: ""
274278

275-
resources: {}
276-
# limits:
277-
# cpu: 100m
278-
# memory: 300Mi
279-
# requests:
280-
# cpu: 100m
281-
# memory: 300Mi
279+
resources:
280+
limits:
281+
cpu: 500m
282+
memory: 500Mi
283+
requests:
284+
cpu: 100m
285+
memory: 250Mi
282286

283287
# Affinity for pod assignment
284288
# Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity

charts/postgres-operator/values.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,17 @@ configKubernetes:
108108
# configure resource requests for the Postgres pods
109109
configPostgresPodResources:
110110
# CPU limits for the postgres containers
111-
default_cpu_limit: "3"
112-
# cpu request value for the postgres containers
111+
default_cpu_limit: "1"
112+
# CPU request value for the postgres containers
113113
default_cpu_request: 100m
114114
# memory limits for the postgres containers
115-
default_memory_limit: 1Gi
115+
default_memory_limit: 500Mi
116116
# memory request value for the postgres containers
117117
default_memory_request: 100Mi
118+
# hard CPU minimum required to properly run a Postgres cluster
119+
min_cpu_limit: 250m
120+
# hard memory minimum required to properly run a Postgres cluster
121+
min_memory_limit: 250Mi
118122

119123
# timeouts related to some operator actions
120124
configTimeouts:
@@ -248,13 +252,13 @@ serviceAccount:
248252

249253
priorityClassName: ""
250254

251-
resources: {}
252-
# limits:
253-
# cpu: 100m
254-
# memory: 300Mi
255-
# requests:
256-
# cpu: 100m
257-
# memory: 300Mi
255+
resources:
256+
limits:
257+
cpu: 500m
258+
memory: 500Mi
259+
requests:
260+
cpu: 100m
261+
memory: 250Mi
258262

259263
# Affinity for pod assignment
260264
# Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity

docs/reference/operator_parameters.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,19 @@ CRD-based configuration.
318318

319319
* **default_cpu_limit**
320320
CPU limits for the Postgres containers, unless overridden by cluster-specific
321-
settings. The default is `3`.
321+
settings. The default is `1`.
322322

323323
* **default_memory_limit**
324324
memory limits for the Postgres containers, unless overridden by cluster-specific
325-
settings. The default is `1Gi`.
325+
settings. The default is `500Mi`.
326+
327+
* **min_cpu_limit**
328+
hard CPU minimum what we consider to be required to properly run Postgres
329+
clusters with Patroni on Kubernetes. The default is `250m`.
330+
331+
* **min_memory_limit**
332+
hard memory minimum what we consider to be required to properly run Postgres
333+
clusters with Patroni on Kubernetes. The default is `250Mi`.
326334

327335
## Operator timeouts
328336

@@ -579,4 +587,4 @@ scalyr sidecar. In the CRD-based configuration they are grouped under the
579587
CPU limit value for the Scalyr sidecar. The default is `1`.
580588

581589
* **scalyr_memory_limit**
582-
Memory limit value for the Scalyr sidecar. The default is `1Gi`.
590+
Memory limit value for the Scalyr sidecar. The default is `500Mi`.

docs/user.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ spec:
232232
memory: 300Mi
233233
```
234234

235-
The minimum limit to properly run the `postgresql` resource is `256m` for `cpu`
236-
and `256Mi` for `memory`. If a lower value is set in the manifest the operator
237-
will cancel ADD or UPDATE events on this resource with an error. If no
238-
resources are defined in the manifest the operator will obtain the configured
239-
[default requests](reference/operator_parameters.md#kubernetes-resource-requests).
235+
The minimum limits to properly run the `postgresql` resource are configured to
236+
`250m` for `cpu` and `250Mi` for `memory`. If a lower value is set in the
237+
manifest the operator will raise the limits to the configured minimum values.
238+
If no resources are defined in the manifest they will be obtained from the
239+
configured [default requests](reference/operator_parameters.md#kubernetes-resource-requests).
240240

241241
## Use taints and tolerations for dedicated PostgreSQL nodes
242242

e2e/tests/test_e2e.py

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,57 @@ def setUpClass(cls):
5858
k8s.create_with_kubectl("manifests/minimal-postgres-manifest.yaml")
5959
k8s.wait_for_pod_start('spilo-role=master')
6060

61+
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
62+
def test_min_resource_limits(self):
63+
'''
64+
Lower resource limits below configured minimum and let operator fix it
65+
'''
66+
k8s = self.k8s
67+
cluster_label = 'version=acid-minimal-cluster'
68+
_, failover_targets = k8s.get_pg_nodes(cluster_label)
69+
70+
# configure minimum boundaries for CPU and memory limits
71+
minCPULimit = '250m'
72+
minMemoryLimit = '250Mi'
73+
patch_min_resource_limits = {
74+
"data": {
75+
"min_cpu_limit": minCPULimit,
76+
"min_memory_limit": minMemoryLimit
77+
}
78+
}
79+
k8s.update_config(patch_min_resource_limits)
80+
81+
# lower resource limits below minimum
82+
pg_patch_resources = {
83+
"spec": {
84+
"resources": {
85+
"requests": {
86+
"cpu": "10m",
87+
"memory": "50Mi"
88+
},
89+
"limits": {
90+
"cpu": "200m",
91+
"memory": "200Mi"
92+
}
93+
}
94+
}
95+
}
96+
k8s.api.custom_objects_api.patch_namespaced_custom_object(
97+
"acid.zalan.do", "v1", "default", "postgresqls", "acid-minimal-cluster", pg_patch_resources)
98+
k8s.wait_for_master_failover(failover_targets)
99+
100+
pods = k8s.api.core_v1.list_namespaced_pod(
101+
'default', label_selector='spilo-role=master,' + cluster_label).items
102+
self.assert_master_is_unique()
103+
masterPod = pods[0]
104+
105+
self.assertEqual(masterPod.spec.containers[0].resources.limits['cpu'], minCPULimit,
106+
"Expected CPU limit {}, found {}"
107+
.format(minCPULimit, masterPod.spec.containers[0].resources.limits['cpu']))
108+
self.assertEqual(masterPod.spec.containers[0].resources.limits['memory'], minMemoryLimit,
109+
"Expected memory limit {}, found {}"
110+
.format(minMemoryLimit, masterPod.spec.containers[0].resources.limits['memory']))
111+
61112
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
62113
def test_multi_namespace_support(self):
63114
'''
@@ -76,10 +127,9 @@ def test_multi_namespace_support(self):
76127

77128
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
78129
def test_scaling(self):
79-
"""
130+
'''
80131
Scale up from 2 to 3 and back to 2 pods by updating the Postgres manifest at runtime.
81-
"""
82-
132+
'''
83133
k8s = self.k8s
84134
labels = "version=acid-minimal-cluster"
85135

@@ -93,9 +143,9 @@ def test_scaling(self):
93143

94144
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
95145
def test_taint_based_eviction(self):
96-
"""
146+
'''
97147
Add taint "postgres=:NoExecute" to node with master. This must cause a failover.
98-
"""
148+
'''
99149
k8s = self.k8s
100150
cluster_label = 'version=acid-minimal-cluster'
101151

@@ -145,15 +195,15 @@ def test_taint_based_eviction(self):
145195

146196
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
147197
def test_logical_backup_cron_job(self):
148-
"""
198+
'''
149199
Ensure we can (a) create the cron job at user request for a specific PG cluster
150200
(b) update the cluster-wide image for the logical backup pod
151201
(c) delete the job at user request
152202
153203
Limitations:
154204
(a) Does not run the actual batch job because there is no S3 mock to upload backups to
155205
(b) Assumes 'acid-minimal-cluster' exists as defined in setUp
156-
"""
206+
'''
157207

158208
k8s = self.k8s
159209

@@ -208,10 +258,10 @@ def test_logical_backup_cron_job(self):
208258
"Expected 0 logical backup jobs, found {}".format(len(jobs)))
209259

210260
def assert_master_is_unique(self, namespace='default', version="acid-minimal-cluster"):
211-
"""
261+
'''
212262
Check that there is a single pod in the k8s cluster with the label "spilo-role=master"
213263
To be called manually after operations that affect pods
214-
"""
264+
'''
215265

216266
k8s = self.k8s
217267
labels = 'spilo-role=master,version=' + version

manifests/complete-postgres-manifest.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ spec:
4242
cpu: 10m
4343
memory: 100Mi
4444
limits:
45-
cpu: 300m
46-
memory: 300Mi
45+
cpu: 500m
46+
memory: 500Mi
4747
patroni:
4848
initdb:
4949
encoding: "UTF8"

manifests/configmap.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ data:
1515
# custom_pod_annotations: "keya:valuea,keyb:valueb"
1616
db_hosted_zone: db.example.com
1717
debug_logging: "true"
18-
# default_cpu_limit: "3"
18+
# default_cpu_limit: "1"
1919
# default_cpu_request: 100m
20-
# default_memory_limit: 1Gi
20+
# default_memory_limit: 500Mi
2121
# default_memory_request: 100Mi
2222
docker_image: registry.opensource.zalan.do/acid/spilo-cdp-12:1.6-p16
2323
# enable_admin_role_for_users: "true"
@@ -48,6 +48,8 @@ data:
4848
# master_pod_move_timeout: 10m
4949
# max_instances: "-1"
5050
# min_instances: "-1"
51+
# min_cpu_limit: 250m
52+
# min_memory_limit: 250Mi
5153
# node_readiness_label: ""
5254
# oauth_token_secret_name: postgresql-operator
5355
# pam_configuration: |

manifests/operatorconfiguration.crd.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ spec:
155155
default_memory_request:
156156
type: string
157157
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
158+
min_cpu_limit:
159+
type: string
160+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
161+
min_memory_limit:
162+
type: string
163+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
158164
timeouts:
159165
type: object
160166
properties:

manifests/postgres-operator.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ spec:
1919
imagePullPolicy: IfNotPresent
2020
resources:
2121
requests:
22-
cpu: 500m
22+
cpu: 100m
2323
memory: 250Mi
2424
limits:
25-
cpu: 2000m
25+
cpu: 500m
2626
memory: 500Mi
2727
securityContext:
2828
runAsUser: 1000

0 commit comments

Comments
 (0)