Skip to content

Commit f8ba188

Browse files
Jonathan S. Katzjkatz
authored andcommitted
Set memory request defaults for PostgreSQL, pgBackRest, pgBouncer
1 parent a4a306a commit f8ba188

File tree

11 files changed

+169
-68
lines changed

11 files changed

+169
-68
lines changed

apiserver/clusterservice/clusterimpl.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@ limitations under the License.
1818
import (
1919
"errors"
2020
"fmt"
21-
2221
"io/ioutil"
2322
"strconv"
2423
"strings"
2524
"time"
2625

2726
crv1 "github.com/crunchydata/postgres-operator/apis/crunchydata.com/v1"
2827
"github.com/crunchydata/postgres-operator/apiserver"
29-
log "github.com/sirupsen/logrus"
30-
3128
msgs "github.com/crunchydata/postgres-operator/apiservermsgs"
3229
"github.com/crunchydata/postgres-operator/config"
3330
"github.com/crunchydata/postgres-operator/kubeapi"
3431
"github.com/crunchydata/postgres-operator/util"
3532

33+
log "github.com/sirupsen/logrus"
3634
v1 "k8s.io/api/core/v1"
3735
kerrors "k8s.io/apimachinery/pkg/api/errors"
3836
"k8s.io/apimachinery/pkg/api/resource"
@@ -1017,6 +1015,8 @@ func getClusterParams(request *msgs.CreateClusterRequest, name string, userLabel
10171015
// as this was already validated, we can ignore the error
10181016
quantity, _ := resource.ParseQuantity(request.MemoryRequest)
10191017
spec.Resources[v1.ResourceMemory] = quantity
1018+
} else {
1019+
spec.Resources[v1.ResourceMemory] = apiserver.Pgo.Cluster.DefaultInstanceResourceMemory
10201020
}
10211021

10221022
// similarly, if there are any overriding pgBackRest repository container
@@ -1031,6 +1031,8 @@ func getClusterParams(request *msgs.CreateClusterRequest, name string, userLabel
10311031
// as this was already validated, we can ignore the error
10321032
quantity, _ := resource.ParseQuantity(request.BackrestMemoryRequest)
10331033
spec.BackrestResources[v1.ResourceMemory] = quantity
1034+
} else {
1035+
spec.BackrestResources[v1.ResourceMemory] = apiserver.Pgo.Cluster.DefaultBackrestResourceMemory
10341036
}
10351037

10361038
// similarly, if there are any overriding pgBouncer container resource request
@@ -1045,6 +1047,8 @@ func getClusterParams(request *msgs.CreateClusterRequest, name string, userLabel
10451047
// as this was already validated, we can ignore the error
10461048
quantity, _ := resource.ParseQuantity(request.PgBouncerMemoryRequest)
10471049
spec.PgBouncerResources[v1.ResourceMemory] = quantity
1050+
} else {
1051+
spec.PgBouncerResources[v1.ResourceMemory] = apiserver.Pgo.Cluster.DefaultPgBouncerResourceMemory
10481052
}
10491053

10501054
spec.PrimaryStorage, _ = apiserver.Pgo.GetStorageSpec(apiserver.Pgo.PrimaryStorage)

apiserver/loadservice/loadconfig.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ import (
2424
)
2525

2626
type LoadConfig struct {
27-
PGOImagePrefix string `yaml:"PGOImagePrefix"`
28-
PGOImageTag string `yaml:"PGOImageTag"`
29-
DbDatabase string `yaml:"DbDatabase"`
30-
DbUser string `yaml:"DbUser"`
31-
DbPort string `yaml:"DbPort"`
32-
TableToLoad string `yaml:"TableToLoad"`
33-
FilePath string `yaml:"FilePath"`
34-
FileType string `yaml:"FileType"`
35-
PVCName string `yaml:"PVCName"`
36-
FSGroup string `yaml:"FSGroup"`
37-
SupplementalGroup string `yaml:"SupplementalGroup"`
27+
PGOImagePrefix string
28+
PGOImageTag string
29+
DbDatabase string
30+
DbUser string
31+
DbPort string
32+
TableToLoad string
33+
FilePath string
34+
FileType string
35+
PVCName string
36+
FSGroup string
37+
SupplementalGroup string
3838
}
3939

4040
func (c *LoadConfig) validate() error {

apiserver/pgbouncerservice/pgbouncerimpl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ func CreatePgbouncer(request *msgs.CreatePgbouncerRequest, ns, pgouser string) m
8989
// as this was already validated, we can ignore the error
9090
quantity, _ := resource.ParseQuantity(request.MemoryRequest)
9191
resources[v1.ResourceMemory] = quantity
92+
} else {
93+
resources[v1.ResourceMemory] = apiserver.Pgo.Cluster.DefaultPgBouncerResourceMemory
9294
}
9395

9496
// set this value on the cluster spec, but this is only *temporary* in this

conf/postgres-operator/pgo.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Cluster:
2525
PodAntiAffinityPgBackRest: ""
2626
PodAntiAffinityPgBouncer: ""
2727
SyncReplication: false
28+
DefaultInstanceMemory:
29+
DefaultBackrestMemory:
30+
DefaultPgBouncerMemory:
2831
PrimaryStorage: storageos
2932
BackupStorage: storageos
3033
ReplicaStorage: storageos

config/defaults.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package config
2+
3+
/*
4+
Copyright 2020 Crunchy Data Solutions, Inc.
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import (
19+
"k8s.io/apimachinery/pkg/api/resource"
20+
)
21+
22+
// Default resource values for deploying a PostgreSQL cluster. These values are
23+
// utilized if the user has not provided these values either through
24+
// configuration or from one-off API/CLI calls.
25+
//
26+
// These values were determined by either program defaults (e.g. the PostgreSQL
27+
// one) and/or loose to vigorous experimentation and profiling
28+
var (
29+
// DefaultBackrestRepoResourceMemory is the default value of the resource request
30+
// for memory for a pgBackRest repository
31+
DefaultBackrestResourceMemory = resource.MustParse("48Mi")
32+
// DefaultInstanceResourceMemory is the default value of the resource request
33+
// for memory for a PostgreSQL instance in a cluster
34+
DefaultInstanceResourceMemory = resource.MustParse("512Mi")
35+
// DefaultPgBouncerResourceMemory is the default value of the resource request
36+
// for memory of a pgBouncer instance
37+
DefaultPgBouncerResourceMemory = resource.MustParse("24Mi")
38+
)

config/pgoconfig.go

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -184,69 +184,72 @@ var DeploymentTemplate *template.Template
184184
const deploymentTemplatePath = "cluster-deployment.json"
185185

186186
type ClusterStruct struct {
187-
CCPImagePrefix string `yaml:"CCPImagePrefix"`
188-
CCPImageTag string `yaml:"CCPImageTag"`
189-
PrimaryNodeLabel string `yaml:"PrimaryNodeLabel"`
190-
ReplicaNodeLabel string `yaml:"ReplicaNodeLabel"`
191-
Policies string `yaml:"Policies"`
192-
Metrics bool `yaml:"Metrics"`
193-
Badger bool `yaml:"Badger"`
194-
Port string `yaml:"Port"`
195-
PGBadgerPort string `yaml:"PGBadgerPort"`
196-
ExporterPort string `yaml:"ExporterPort"`
197-
User string `yaml:"User"`
198-
Database string `yaml:"Database"`
199-
PasswordAgeDays string `yaml:"PasswordAgeDays"`
200-
PasswordLength string `yaml:"PasswordLength"`
201-
Replicas string `yaml:"Replicas"`
202-
ServiceType string `yaml:"ServiceType"`
203-
BackrestPort int `yaml:"BackrestPort"`
204-
Backrest bool `yaml:"Backrest"`
205-
BackrestS3Bucket string `yaml:"BackrestS3Bucket"`
206-
BackrestS3Endpoint string `yaml:"BackrestS3Endpoint"`
207-
BackrestS3Region string `yaml:"BackrestS3Region"`
208-
DisableAutofail bool `yaml:"DisableAutofail"`
209-
PgmonitorPassword string `yaml:"PgmonitorPassword"`
210-
EnableCrunchyadm bool `yaml:"EnableCrunchyadm"`
211-
DisableReplicaStartFailReinit bool `yaml:"DisableReplicaStartFailReinit"`
212-
PodAntiAffinity string `yaml:"PodAntiAffinity"`
213-
PodAntiAffinityPgBackRest string `yaml:"PodAntiAffinityPgBackRest"`
214-
PodAntiAffinityPgBouncer string `yaml:"PodAntiAffinityPgBouncer"`
215-
SyncReplication bool `yaml:"SyncReplication"`
187+
CCPImagePrefix string
188+
CCPImageTag string
189+
PrimaryNodeLabel string
190+
ReplicaNodeLabel string
191+
Policies string
192+
Metrics bool
193+
Badger bool
194+
Port string
195+
PGBadgerPort string
196+
ExporterPort string
197+
User string
198+
Database string
199+
PasswordAgeDays string
200+
PasswordLength string
201+
Replicas string
202+
ServiceType string
203+
BackrestPort int
204+
Backrest bool
205+
BackrestS3Bucket string
206+
BackrestS3Endpoint string
207+
BackrestS3Region string
208+
DisableAutofail bool
209+
PgmonitorPassword string
210+
EnableCrunchyadm bool
211+
DisableReplicaStartFailReinit bool
212+
PodAntiAffinity string
213+
PodAntiAffinityPgBackRest string
214+
PodAntiAffinityPgBouncer string
215+
SyncReplication bool
216+
DefaultInstanceResourceMemory resource.Quantity `json:"DefaultInstanceMemory"`
217+
DefaultBackrestResourceMemory resource.Quantity `json:"DefaultBackrestMemory"`
218+
DefaultPgBouncerResourceMemory resource.Quantity `json:"DefaultPgBouncerMemory"`
216219
}
217220

218221
type StorageStruct struct {
219-
AccessMode string `yaml:"AccessMode"`
220-
Size string `yaml:"Size"`
221-
StorageType string `yaml:"StorageType"`
222-
StorageClass string `yaml:"StorageClass"`
223-
SupplementalGroups string `yaml:"SupplementalGroups"`
224-
MatchLabels string `yaml:"MatchLabels"`
222+
AccessMode string
223+
Size string
224+
StorageType string
225+
StorageClass string
226+
SupplementalGroups string
227+
MatchLabels string
225228
}
226229

227230
type ContainerResourcesStruct struct {
228-
RequestsMemory string `yaml:"RequestsMemory"`
229-
RequestsCPU string `yaml:"RequestsCPU"`
230-
LimitsMemory string `yaml:"LimitsMemory"`
231-
LimitsCPU string `yaml:"LimitsCPU"`
231+
RequestsMemory string
232+
RequestsCPU string
233+
LimitsMemory string
234+
LimitsCPU string
232235
}
233236

234237
type PgoStruct struct {
235-
Audit bool `yaml:"Audit"`
236-
PGOImagePrefix string `yaml:"PGOImagePrefix"`
237-
PGOImageTag string `yaml:"PGOImageTag"`
238+
Audit bool
239+
PGOImagePrefix string
240+
PGOImageTag string
238241
}
239242

240243
type PgoConfig struct {
241-
BasicAuth string `yaml:"BasicAuth"`
242-
Cluster ClusterStruct `yaml:"Cluster"`
243-
Pgo PgoStruct `yaml:"Pgo"`
244-
ContainerResources map[string]ContainerResourcesStruct `yaml:"ContainerResources"`
245-
PrimaryStorage string `yaml:"PrimaryStorage"`
246-
BackupStorage string `yaml:"BackupStorage"`
247-
ReplicaStorage string `yaml:"ReplicaStorage"`
248-
BackrestStorage string `yaml:"BackrestStorage"`
249-
Storage map[string]StorageStruct `yaml:"Storage"`
244+
BasicAuth string
245+
Cluster ClusterStruct
246+
Pgo PgoStruct
247+
ContainerResources map[string]ContainerResourcesStruct
248+
PrimaryStorage string
249+
BackupStorage string
250+
ReplicaStorage string
251+
BackrestStorage string
252+
Storage map[string]StorageStruct
250253
}
251254

252255
const DEFAULT_SERVICE_TYPE = "ClusterIP"
@@ -374,6 +377,25 @@ func (c *PgoConfig) Validate() error {
374377
}
375378
return errors.New(errPrefix + msg)
376379
}
380+
381+
// validate any of the resources and if they are unavailable, set defaults
382+
if c.Cluster.DefaultInstanceResourceMemory.IsZero() {
383+
c.Cluster.DefaultInstanceResourceMemory = DefaultInstanceResourceMemory
384+
}
385+
386+
log.Infof("deafult instance memory set to [%s]", c.Cluster.DefaultInstanceResourceMemory.String())
387+
388+
if c.Cluster.DefaultBackrestResourceMemory.IsZero() {
389+
c.Cluster.DefaultBackrestResourceMemory = DefaultBackrestResourceMemory
390+
}
391+
392+
log.Infof("deafult pgbackrest repository memory set to [%s]", c.Cluster.DefaultBackrestResourceMemory.String())
393+
394+
if c.Cluster.DefaultPgBouncerResourceMemory.IsZero() {
395+
c.Cluster.DefaultPgBouncerResourceMemory = DefaultPgBouncerResourceMemory
396+
}
397+
398+
log.Infof("deafult pgbouncer memory set to [%s]", c.Cluster.DefaultPgBouncerResourceMemory.String())
377399
}
378400

379401
// if provided, ensure that the type of pod anti-affinity values are valid
@@ -522,9 +544,8 @@ func (c *PgoConfig) GetConfig(clientset *kubernetes.Clientset, namespace string)
522544
return err
523545
}
524546

525-
//validate the pgo.yaml config file
526-
err = c.Validate()
527-
if err != nil {
547+
// validate the pgo.yaml config file
548+
if err := c.Validate(); err != nil {
528549
log.Error(err)
529550
return err
530551
}

docs/content/Configuration/pgo-yaml-configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ The *pgo.yaml* file is broken into major sections as described below:
3838
|DisableReplicaStartFailReinit | if set to `true` will disable the detection of a "start failed" states in PG replicas, which results in the re-initialization of the replica in an attempt to bring it back online
3939
|PodAntiAffinity | either `preferred`, `required` or `disabled` to either specify the type of affinity that should be utilized for the default pod anti-affinity applied to PG clusters, or to disable default pod anti-affinity all together (default `preferred`)
4040
|SyncReplication | boolean, if set to `true` will automatically enable synchronous replication in new PostgreSQL clusters (default `false`)
41+
|DefaultInstanceMemory | string, matches a Kubernetes resource value. If set, it is used as the default value of the memory request for each instance in a PostgreSQL cluster (default `512Mi`)
42+
|DefaultBackrestMemory | string, matches a Kubernetes resource value. If set, it is used as the default value of the memory request for the pgBackRest repository (default `48Mi`)
43+
|DefaultPgBouncerMemory | string, matches a Kubernetes resource value. If set, it is used as the default value of the memory request for pgBouncer instances (default `24Mi`)
4144

4245
## Storage
4346
| Setting|Definition |

docs/content/Installation/install-with-ansible/prerequisites.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ sets of variables cannot be used at the same time.
166166
| `cleanup` | false | | Set to configure the playbooks to delete all objects when uninstalling the Operator. Note: this will delete all objects related to the Operator (including clusters provisioned). |
167167
| `create_rbac` | true | **Required** | Set to `true` if the installer should create the RBAC resources required to run the PostgreSQL Operator. |
168168
| `crunchy_debug` | false | | Set to configure Operator to use debugging mode. Note: this can cause sensitive data such as passwords to appear in Operator logs. |
169+
| `default_instance_memory` | 512Mi | | The default amount of memory to request for a PostgreSQL instance |
170+
| `default_pgbackrest_memory` | 48Mi | | The default amount of memory to request for a pgBackRest repository |
171+
| `default_pgbouncer_memory` | 24Mi | | The default amount of memory to request for a pgBouncer instance |
169172
| `delete_metrics_namespace` | false | | Set to configure whether or not the metrics namespace (defined using variable `metrics_namespace`) is deleted when uninstalling the metrics infrastructure |
170173
| `delete_operator_namespace` | false | | Set to configure whether or not the PGO operator namespace (defined using variable `pgo_operator_namespace`) is deleted when uninstalling the PGO. |
171174
| `delete_watched_namespaces` | false | | Set to configure whether or not the PGO watched namespaces (defined using variable `namespace`) are deleted when uninstalling the PGO. |
@@ -224,6 +227,7 @@ sets of variables cannot be used at the same time.
224227
| `replica_storage` | storageos | **Required** | Set to configure which storage definition to use when creating volumes used by PostgreSQL replicas on all newly created clusters. |
225228
| `scheduler_timeout` | 3600 | **Required** | Set to a value in seconds to configure the `pgo-scheduler` timeout threshold when waiting for schedules to complete. |
226229
| `service_type` | ClusterIP | | Set to configure the type of Kubernetes service provisioned on all newly created clusters. |
230+
| `sync_replication` | false | | If set to true, defaults the PostgreSQL clusters to be deployed with synchronous replication |
227231
| `pgo_cluster_admin` | false | | Determines whether or not the `cluster-admin` role is assigned to the PGO service account. Must be `true` to enable PGO namespace & role creation when installing in OpenShift. |
228232

229233
{{% notice tip %}}

installers/ansible/inventory

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,25 @@ db_port=5432
232232
db_replicas=0
233233
db_user='testuser'
234234

235+
# ==================
236+
# Default Container Resource Configurations
237+
# ==================
238+
# Define the default container resource configurations that differ from the
239+
# PostgreSQL Operator defaults. As a convenience, the current PostgreSQL
240+
# Operator defaults are listed with each variable
241+
#
242+
# "default_instance_memory" represents the memory request for a PostgreSQL
243+
# instance
244+
# default_instance_memory='512Mi'
245+
#
246+
# "default_pgbackrest_repo_memory" represents the memory request for a
247+
# pgBackRest repository
248+
# default_pgbackrest_memory='48Mi'
249+
#
250+
# "default_pgbouncer_memory" represents the memory request for a pgBouncer
251+
# instance
252+
# default_pgbouncer_memory='24Mi'
253+
235254
# ==================
236255
# Storage Settings
237256
# ==================

installers/ansible/roles/pgo-operator/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ crunchy_debug: "false"
1717
enable_crunchyadm: "false"
1818
disable_replica_start_fail_reinit: "false"
1919

20+
default_instance_memory: ""
21+
default_pgbackrest_memory: ""
22+
default_pgbouncer_memory: ""
23+
2024
pgo_client_install: "true"
2125
pgo_client_container_install: "false"
2226
pgo_cluster_admin: "false"

0 commit comments

Comments
 (0)