Skip to content

Commit 83689f3

Browse files
jkatzJonathan S. Katz
authored andcommitted
Add flags for setting resource limits
While the PostgreSQL Operator attempted to put in safeguards around setting memory limits with PostgreSQL instances, it appears that this may have provided too many guard rails around how things are deployed out in the wild. As such, this commit introduces many new flags to allow users to set their own resource limits. These include: - pgo create cluster --cpu-limit - pgo create cluster --memory-limit - pgo create cluster --pgbackrest-cpu-limit - pgo create cluster --pgbackrest-memory-limit - pgo create cluster --pgbouncer-cpu-limit - pgo create cluster --pgbouncer-memory-limit - pgo update cluster --cpu-limit - pgo update cluster --memory-limit - pgo update cluster --pgbackrest-cpu-limit - pgo update cluster --pgbackrest-memory-limit - pgo create pgbouncer --cpu-limit - pgo create pgbouncer --memory-limit - pgo update pgbouncer --cpu-limit - pgo update pgbouncer --memory-limit This commit also removes the set of "enable/disable" memory limit flags, as they are effectively mooted by this. Issue: [ch8331] Issue: #1538
1 parent 0d1db07 commit 83689f3

File tree

26 files changed

+550
-446
lines changed

26 files changed

+550
-446
lines changed

apis/crunchydata.com/v1/cluster.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ type PgclusterSpec struct {
5959
// Resources behaves just like the "Requests" section of a Kubernetes
6060
// container definition. You can set individual items such as "cpu" and
6161
// "memory", e.g. "{ cpu: "0.5", memory: "2Gi" }"
62+
Resources v1.ResourceList `json:"resources"`
63+
// Limits stores the CPU/memory limits to use with PostgreSQL instances
6264
//
63-
// For memory requests, we only set the "Request" portion of the Container
64-
// resource definition, but if we do allow for the "Limit" portion to be set,
65-
// we would keep it unified to get a "Guaranteed" QoS.
65+
// A long note on memory limits.
6666
//
67-
// We don't set the Limit you say? Yes: we want to avoid the OOM killer coming
68-
// for the PostgreSQL process or any of their backends per lots of guidance
69-
// from the PostgreSQL documentation. Based on Kubernetes' behavior with
70-
// limits, the best thing is to not set them. However, if they ever do set,
71-
// we'll ensure that we get the Guaranteed QoS to help avoid OOM risks.
67+
// We want to avoid the OOM killer coming for the PostgreSQL process or any
68+
// of their backends per lots of guidance from the PostgreSQL documentation.
69+
// Based on Kubernetes' behavior with limits, the best thing is to not set
70+
// them. However, if they ever do set, we suggest that you have
71+
// Request == Limit to get the Guaranteed QoS
7272
//
7373
// Guaranteed QoS prevents a backend from being first in line to be killed if
7474
// the *Node* has memory pressure, but if there is, say
@@ -84,19 +84,13 @@ type PgclusterSpec struct {
8484
//
8585
// https://www.postgresql.org/docs/current/kernel-resources.html#LINUX-MEMORY-OVERCOMMIT
8686
// https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#how-pods-with-resource-limits-are-run
87-
//
88-
// Now, for CPU, we set both the Request and the Limit, based on how
89-
// Kubernetes interacts with these parameters
90-
Resources v1.ResourceList `json:"resources"`
91-
// EnableMemoryLimit specifies whether or not the "Limit" for memory
92-
// should be set on the Pod. Defaults to false
93-
EnableMemoryLimit bool `json:"enableMemoryLimit"`
87+
Limits v1.ResourceList `json:"limits"`
9488
// BackrestResources, if specified, contains the container request resources
9589
// for the pgBackRest Deployment for this PostgreSQL cluster
9690
BackrestResources v1.ResourceList `json:"backrestResources"`
97-
// EnableBackrestMemoryLimit specifies whether or not the "Limit" for memory
98-
// should be set on the Pod. Defaults to false
99-
EnableBackrestMemoryLimit bool `json:"enableBackrestMemoryLimit"`
91+
// BackrestLimits, if specified, contains the container resource limits
92+
// for the pgBackRest Deployment for this PostgreSQL cluster
93+
BackrestLimits v1.ResourceList `json:"backrestLimits"`
10094
// PgBouncer contains all of the settings to properly maintain a pgBouncer
10195
// implementation
10296
PgBouncer PgBouncerSpec `json:"pgBouncer"`
@@ -178,9 +172,6 @@ type PodAntiAffinitySpec struct {
178172
// - what resources it should consume
179173
// - the total number of replicas
180174
type PgBouncerSpec struct {
181-
// EnableMemoryLimit specifies whether or not the "Limit" for memory
182-
// should be set on the Pod. Defaults to false
183-
EnableMemoryLimit bool `json:"enableMemoryLimit"`
184175
// Replicas represents the total number of Pods to deploy with pgBouncer,
185176
// which effectively enables/disables the pgBouncer.
186177
//
@@ -191,6 +182,9 @@ type PgBouncerSpec struct {
191182
// Resources, if specified, contains the container request resources
192183
// for any pgBouncer Deployments that are part of a PostgreSQL cluster
193184
Resources v1.ResourceList `json:"resources"`
185+
// Limits, if specified, contains the container resource limits
186+
// for any pgBouncer Deployments that are part of a PostgreSQL cluster
187+
Limits v1.ResourceList `json:"limits"`
194188
}
195189

196190
// Enabled returns true if the pgBouncer is enabled for the cluster, i.e. there

apis/crunchydata.com/v1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)