Skip to content

Commit c5dfd11

Browse files
committed
check resource requests also on UPDATE and SYNC + update docs
1 parent 9480b09 commit c5dfd11

File tree

6 files changed

+51
-10
lines changed

6 files changed

+51
-10
lines changed

docs/user.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
databases:
3131
foo: zalando
3232
postgresql:
33-
version: "10"
33+
version: "11"
3434
```
3535
3636
Once you cloned the Postgres Operator [repository](https://github.com/zalando/postgres-operator)
@@ -40,6 +40,10 @@ you can find this example also in the manifests folder:
4040
kubectl create -f manifests/minimal-postgres-manifest.yaml
4141
```
4242

43+
Note, that the minimum volume size to properly run the `postgresql` resource is
44+
`1Gi`. If a lower value is set in the manifest the operator will cancel ADD,
45+
UPDATE or SYNC events on this resource with an error.
46+
4347
## Watch pods being created
4448

4549
```bash
@@ -182,6 +186,32 @@ See [infrastructure roles secret](../manifests/infrastructure-roles.yaml)
182186
and [infrastructure roles configmap](../manifests/infrastructure-roles-configmap.yaml)
183187
for the examples.
184188

189+
## Resource definition
190+
191+
The compute resources to be used for the Postgres containers in the pods can be
192+
specified in the postgresql cluster manifest.
193+
194+
```yaml
195+
apiVersion: "acid.zalan.do/v1"
196+
kind: postgresql
197+
metadata:
198+
name: acid-minimal-cluster
199+
spec:
200+
resources:
201+
requests:
202+
cpu: 10m
203+
memory: 100Mi
204+
limits:
205+
cpu: 300m
206+
memory: 300Mi
207+
```
208+
209+
The minimum limit to properly run the `postgresql` resource is `256m` for `cpu`
210+
and `256Mi` for `memory`. If a lower value is set in the manifest the operator
211+
will cancel ADD, UPDATE or SYNC events on this resource with an error. If no
212+
resources are defined in the manifest the operator will obtain the configured
213+
[default requests](reference/operator_parameters.md#kubernetes-resource-requests).
214+
185215
## Use taints and tolerations for dedicated PostgreSQL nodes
186216

187217
To ensure Postgres pods are running on nodes without any other application pods,
@@ -305,7 +335,7 @@ Things to note:
305335
- There is no way to transform a non-standby cluster to a standby cluster
306336
through the operator. Adding the standby section to the manifest of a running
307337
Postgres cluster will have no effect. However, it can be done through Patroni
308-
by adding the [standby_cluster] (https://github.com/zalando/patroni/blob/bd2c54581abb42a7d3a3da551edf0b8732eefd27/docs/replica_bootstrap.rst#standby-cluster)
338+
by adding the [standby_cluster](https://github.com/zalando/patroni/blob/bd2c54581abb42a7d3a3da551edf0b8732eefd27/docs/replica_bootstrap.rst#standby-cluster)
309339
section using `patronictl edit-config`. Note that the transformed standby
310340
cluster will not be doing any streaming. It will be in standby mode and allow
311341
read-only transactions only.
@@ -376,7 +406,7 @@ spec:
376406

377407
## Increase volume size
378408

379-
PostgreSQL operator supports statefulset volume resize if you're using the
409+
Postgres operator supports statefulset volume resize if you're using the
380410
operator on top of AWS. For that you need to change the size field of the
381411
volume description in the cluster manifest and apply the change:
382412

manifests/standby-manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
size: 1Gi
1010
numberOfInstances: 1
1111
postgresql:
12-
version: "10"
12+
version: "11"
1313
# Make this a standby cluster and provide the s3 bucket path of source cluster for continuous streaming.
1414
standby:
1515
s3_wal_path: "s3://path/to/bucket/containing/wal/of/source/cluster/"

pkg/cluster/cluster.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (c *Cluster) Create() error {
228228
c.setStatus(acidv1.ClusterStatusCreating)
229229

230230
if err = c.validateResources(&c.Spec); err != nil {
231-
return fmt.Errorf("unsufficient ressources: %v", err)
231+
return fmt.Errorf("insufficient resources specified: %v", err)
232232
}
233233

234234
for _, role := range []PostgresRole{Master, Replica} {
@@ -595,6 +595,12 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
595595
}
596596
}
597597

598+
// check pod resources and volume size and cancel update if they are too low
599+
if err := c.validateResources(&c.Spec); err != nil {
600+
updateFailed = true
601+
return fmt.Errorf("insufficient resources specified: %v", err)
602+
}
603+
598604
// Volume
599605
if oldSpec.Spec.Size != newSpec.Spec.Size {
600606
c.logger.Debugf("syncing persistent volumes")

pkg/cluster/sync.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
3434
}
3535
}()
3636

37+
if err = c.validateResources(&c.Spec); err != nil {
38+
err = fmt.Errorf("insufficient resources specified: %v", err)
39+
return err
40+
}
41+
3742
if err = c.initUsers(); err != nil {
3843
err = fmt.Errorf("could not init users: %v", err)
3944
return err

pkg/controller/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sync"
77

88
"github.com/sirupsen/logrus"
9-
"k8s.io/api/core/v1"
9+
v1 "k8s.io/api/core/v1"
1010
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"k8s.io/apimachinery/pkg/types"
@@ -111,7 +111,7 @@ func (c *Controller) initOperatorConfig() {
111111

112112
if c.opConfig.SetMemoryRequestToLimit {
113113

114-
isSmaller, err := util.RequestIsSmallerThanLimit(c.opConfig.DefaultMemoryRequest, c.opConfig.DefaultMemoryLimit)
114+
isSmaller, err := util.IsSmallerQuantity(c.opConfig.DefaultMemoryRequest, c.opConfig.DefaultMemoryLimit)
115115
if err != nil {
116116
panic(err)
117117
}
@@ -120,7 +120,7 @@ func (c *Controller) initOperatorConfig() {
120120
c.opConfig.DefaultMemoryRequest = c.opConfig.DefaultMemoryLimit
121121
}
122122

123-
isSmaller, err = util.RequestIsSmallerThanLimit(c.opConfig.ScalyrMemoryRequest, c.opConfig.ScalyrMemoryLimit)
123+
isSmaller, err = util.IsSmallerQuantity(c.opConfig.ScalyrMemoryRequest, c.opConfig.ScalyrMemoryLimit)
124124
if err != nil {
125125
panic(err)
126126
}

pkg/util/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ func TestIsSmallerQuantity(t *testing.T) {
159159
for _, tt := range requestIsSmallerQuantityTests {
160160
res, err := IsSmallerQuantity(tt.request, tt.limit)
161161
if err != nil {
162-
t.Errorf("RequestIsSmallerThanLimit returned unexpected error: %#v", err)
162+
t.Errorf("IsSmallerQuantity returned unexpected error: %#v", err)
163163
}
164164
if res != tt.out {
165-
t.Errorf("RequestIsSmallerThanLimit expected: %#v, got: %#v", tt.out, res)
165+
t.Errorf("IsSmallerQuantity expected: %#v, got: %#v", tt.out, res)
166166
}
167167
}
168168
}

0 commit comments

Comments
 (0)