Skip to content

Commit 29cec0c

Browse files
authored
configurable resources for logical backup pod template (zalando#710)
* new config options to specify resources for logical backup jobs * bug in logical backup script for s3 dumps * define enum for logical_backup_provider * changed order of logical backup azure options * fix unit test for stream comparison
1 parent bbc0de3 commit 29cec0c

File tree

15 files changed

+305
-55
lines changed

15 files changed

+305
-55
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,18 @@ spec:
469469
logical_backup:
470470
type: object
471471
properties:
472+
logical_backup_azure_storage_account_name:
473+
type: string
474+
logical_backup_azure_storage_container:
475+
type: string
476+
logical_backup_azure_storage_account_key:
477+
type: string
478+
logical_backup_cpu_limit:
479+
type: string
480+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
481+
logical_backup_cpu_request:
482+
type: string
483+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
472484
logical_backup_docker_image:
473485
type: string
474486
default: "registry.opensource.zalan.do/acid/logical-backup:v1.8.2"
@@ -477,8 +489,18 @@ spec:
477489
logical_backup_job_prefix:
478490
type: string
479491
default: "logical-backup-"
492+
logical_backup_memory_limit:
493+
type: string
494+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
495+
logical_backup_memory_request:
496+
type: string
497+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
480498
logical_backup_provider:
481499
type: string
500+
enum:
501+
- "az"
502+
- "gcs"
503+
- "s3"
482504
default: "s3"
483505
logical_backup_s3_access_key_id:
484506
type: string
@@ -498,12 +520,6 @@ spec:
498520
type: string
499521
pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
500522
default: "30 00 * * *"
501-
logical_backup_azure_storage_account_name:
502-
type: string
503-
logical_backup_azure_storage_container:
504-
type: string
505-
logical_backup_azure_storage_account_key:
506-
type: string
507523
debug:
508524
type: object
509525
properties:

charts/postgres-operator/values.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,25 @@ configAwsOrGcp:
332332

333333
# configure K8s cron job managed by the operator
334334
configLogicalBackup:
335+
# Azure Storage Account specs to store backup results
336+
# logical_backup_azure_storage_account_name: ""
337+
# logical_backup_azure_storage_container: ""
338+
# logical_backup_azure_storage_account_key: ""
339+
340+
# resources for logical backup pod, if empty configPostgresPodResources will be used
341+
# logical_backup_cpu_limit: ""
342+
# logical_backup_cpu_request: ""
343+
# logical_backup_memory_limit: ""
344+
# logical_backup_memory_request: ""
345+
335346
# image for pods of the logical backup job (example runs pg_dumpall)
336347
logical_backup_docker_image: "registry.opensource.zalan.do/acid/logical-backup:v1.8.0"
337348
# path of google cloud service account json file
338349
# logical_backup_google_application_credentials: ""
339350

340351
# prefix for the backup job name
341352
logical_backup_job_prefix: "logical-backup-"
342-
# storage provider - either "s3" or "gcs"
353+
# storage provider - either "s3", "gcs" or "az"
343354
logical_backup_provider: "s3"
344355
# S3 Access Key ID
345356
logical_backup_s3_access_key_id: ""

docker/logical-backup/dump.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function upload {
126126
"gcs")
127127
gcs_upload
128128
;;
129-
"aws")
129+
"s3")
130130
aws_upload $(($(estimate_size) / DUMP_SIZE_COEFF))
131131
aws_delete_outdated
132132
;;

docs/administrator.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,10 @@ of the backup cron job.
12011201
`cronjobs` resource from the `batch` API group for the operator service account.
12021202
See [example RBAC](https://github.com/zalando/postgres-operator/blob/master/manifests/operator-service-account-rbac.yaml)
12031203

1204+
7. Resources of the pod template in the cron job can be configured. When left
1205+
empty [default values of spilo pods](reference/operator_parameters.md#kubernetes-resource-requests)
1206+
will be used.
1207+
12041208
## Sidecars for Postgres clusters
12051209

12061210
A list of sidecars is added to each cluster created by the operator. The default

docs/reference/operator_parameters.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,13 @@ These parameters configure a K8s cron job managed by the operator to produce
718718
Postgres logical backups. In the CRD-based configuration those parameters are
719719
grouped under the `logical_backup` key.
720720

721+
* **logical_backup_cpu_limit**
722+
**logical_backup_cpu_request**
723+
**logical_backup_memory_limit**
724+
**logical_backup_memory_request**
725+
Resource configuration for pod template in logical backup cron job. If empty
726+
default values from `postgres_pod_resources` will be used.
727+
721728
* **logical_backup_docker_image**
722729
An image for pods of the logical backup job. The [example image](https://github.com/zalando/postgres-operator/blob/master/docker/logical-backup/Dockerfile)
723730
runs `pg_dumpall` on a replica if possible and uploads compressed results to
@@ -732,8 +739,17 @@ grouped under the `logical_backup` key.
732739
The prefix to be prepended to the name of a k8s CronJob running the backups. Beware the prefix counts towards the name length restrictions imposed by k8s. Empty string is a legitimate value. Operator does not do the actual renaming: It simply creates the job with the new prefix. You will have to delete the old cron job manually. Default: "logical-backup-".
733740

734741
* **logical_backup_provider**
735-
Specifies the storage provider to which the backup should be uploaded (`s3` or `gcs`).
736-
Default: "s3"
742+
Specifies the storage provider to which the backup should be uploaded
743+
(`s3`, `gcs` or `az`). Default: "s3"
744+
745+
* **logical_backup_azure_storage_account_name**
746+
Storage account name used to upload logical backups to when using Azure. Default: ""
747+
748+
* **logical_backup_azure_storage_container**
749+
Storage container used to upload logical backups to when using Azure. Default: ""
750+
751+
* **logical_backup_azure_storage_account_key**
752+
Storage account key used to authenticate with Azure when uploading logical backups. Default: ""
737753

738754
* **logical_backup_s3_access_key_id**
739755
When set, value will be in AWS_ACCESS_KEY_ID env variable. The Default is empty.
@@ -765,15 +781,6 @@ grouped under the `logical_backup` key.
765781
[reference schedule format](https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#schedule)
766782
into account. Default: "30 00 \* \* \*"
767783

768-
* **logical_backup_azure_storage_account_name**
769-
Storage account name used to upload logical backups to when using Azure. Default: ""
770-
771-
* **logical_backup_azure_storage_container**
772-
Storage container used to upload logical backups to when using Azure. Default: ""
773-
774-
* **logical_backup_azure_storage_account_key**
775-
Storage account key used to authenticate with Azure when uploading logical backups. Default: ""
776-
777784
## Debugging the operator
778785

779786
Options to aid debugging of the operator itself. Grouped under the `debug` key.

manifests/configmap.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,16 @@ data:
7575
# kube_iam_role: ""
7676
# kubernetes_use_configmaps: "false"
7777
# log_s3_bucket: ""
78+
# logical_backup_azure_storage_account_name: ""
79+
# logical_backup_azure_storage_container: ""
80+
# logical_backup_azure_storage_account_key: ""
81+
# logical_backup_cpu_limit: ""
82+
# logical_backup_cpu_request: ""
7883
logical_backup_docker_image: "registry.opensource.zalan.do/acid/logical-backup:v1.8.2"
7984
# logical_backup_google_application_credentials: ""
8085
logical_backup_job_prefix: "logical-backup-"
86+
# logical_backup_memory_limit: ""
87+
# logical_backup_memory_request: ""
8188
logical_backup_provider: "s3"
8289
# logical_backup_s3_access_key_id: ""
8390
logical_backup_s3_bucket: "my-bucket-url"
@@ -87,9 +94,6 @@ data:
8794
logical_backup_s3_sse: "AES256"
8895
# logical_backup_s3_retention_time: ""
8996
logical_backup_schedule: "30 00 * * *"
90-
# logical_backup_azure_storage_account_name: ""
91-
# logical_backup_azure_storage_container: ""
92-
# logical_backup_azure_storage_account_key: ""
9397
major_version_upgrade_mode: "manual"
9498
# major_version_upgrade_team_allow_list: ""
9599
master_dns_name_format: "{cluster}.{namespace}.{hostedzone}"

manifests/operatorconfiguration.crd.yaml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,18 @@ spec:
467467
logical_backup:
468468
type: object
469469
properties:
470+
logical_backup_azure_storage_account_name:
471+
type: string
472+
logical_backup_azure_storage_container:
473+
type: string
474+
logical_backup_azure_storage_account_key:
475+
type: string
476+
logical_backup_cpu_limit:
477+
type: string
478+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
479+
logical_backup_cpu_request:
480+
type: string
481+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
470482
logical_backup_docker_image:
471483
type: string
472484
default: "registry.opensource.zalan.do/acid/logical-backup:v1.8.2"
@@ -475,8 +487,18 @@ spec:
475487
logical_backup_job_prefix:
476488
type: string
477489
default: "logical-backup-"
490+
logical_backup_memory_limit:
491+
type: string
492+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
493+
logical_backup_memory_request:
494+
type: string
495+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
478496
logical_backup_provider:
479497
type: string
498+
enum:
499+
- "az"
500+
- "gcs"
501+
- "s3"
480502
default: "s3"
481503
logical_backup_s3_access_key_id:
482504
type: string
@@ -496,12 +518,6 @@ spec:
496518
type: string
497519
pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
498520
default: "30 00 * * *"
499-
logical_backup_azure_storage_account_name:
500-
type: string
501-
logical_backup_azure_storage_container:
502-
type: string
503-
logical_backup_azure_storage_account_key:
504-
type: string
505521
debug:
506522
type: object
507523
properties:

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ configuration:
151151
# wal_gs_bucket: ""
152152
# wal_s3_bucket: ""
153153
logical_backup:
154+
# logical_backup_azure_storage_account_name: ""
155+
# logical_backup_azure_storage_container: ""
156+
# logical_backup_azure_storage_account_key: ""
157+
# logical_backup_cpu_limit: ""
158+
# logical_backup_cpu_request: ""
159+
# logical_backup_memory_limit: ""
160+
# logical_backup_memory_request: ""
154161
logical_backup_docker_image: "registry.opensource.zalan.do/acid/logical-backup:v1.8.2"
155162
# logical_backup_google_application_credentials: ""
156163
logical_backup_job_prefix: "logical-backup-"
@@ -163,9 +170,6 @@ configuration:
163170
logical_backup_s3_sse: "AES256"
164171
# logical_backup_s3_retention_time: ""
165172
logical_backup_schedule: "30 00 * * *"
166-
# logical_backup_azure_storage_account_name: ""
167-
# logical_backup_azure_storage_container: ""
168-
# logical_backup_azure_storage_account_key: ""
169173
debug:
170174
debug_logging: true
171175
enable_database_access: true

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,23 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
16181618
"logical_backup": {
16191619
Type: "object",
16201620
Properties: map[string]apiextv1.JSONSchemaProps{
1621+
"logical_backup_azure_storage_account_name": {
1622+
Type: "string",
1623+
},
1624+
"logical_backup_azure_storage_container": {
1625+
Type: "string",
1626+
},
1627+
"logical_backup_azure_storage_account_key": {
1628+
Type: "string",
1629+
},
1630+
"logical_backup_cpu_limit": {
1631+
Type: "string",
1632+
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$",
1633+
},
1634+
"logical_backup_cpu_request": {
1635+
Type: "string",
1636+
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$",
1637+
},
16211638
"logical_backup_docker_image": {
16221639
Type: "string",
16231640
},
@@ -1627,8 +1644,27 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
16271644
"logical_backup_job_prefix": {
16281645
Type: "string",
16291646
},
1647+
"logical_backup_memory_limit": {
1648+
Type: "string",
1649+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
1650+
},
1651+
"logical_backup_memory_request": {
1652+
Type: "string",
1653+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
1654+
},
16301655
"logical_backup_provider": {
16311656
Type: "string",
1657+
Enum: []apiextv1.JSON{
1658+
{
1659+
Raw: []byte(`"az"`),
1660+
},
1661+
{
1662+
Raw: []byte(`"gcs"`),
1663+
},
1664+
{
1665+
Raw: []byte(`"s3"`),
1666+
},
1667+
},
16321668
},
16331669
"logical_backup_s3_access_key_id": {
16341670
Type: "string",
@@ -1655,15 +1691,6 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
16551691
Type: "string",
16561692
Pattern: "^(\\d+|\\*)(/\\d+)?(\\s+(\\d+|\\*)(/\\d+)?){4}$",
16571693
},
1658-
"logical_backup_azure_storage_account_name": {
1659-
Type: "string",
1660-
},
1661-
"logical_backup_azure_storage_container": {
1662-
Type: "string",
1663-
},
1664-
"logical_backup_azure_storage_account_key": {
1665-
Type: "string",
1666-
},
16671694
},
16681695
},
16691696
"debug": {

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ type OperatorLogicalBackupConfiguration struct {
218218
Schedule string `json:"logical_backup_schedule,omitempty"`
219219
DockerImage string `json:"logical_backup_docker_image,omitempty"`
220220
BackupProvider string `json:"logical_backup_provider,omitempty"`
221+
AzureStorageAccountName string `json:"logical_backup_azure_storage_account_name,omitempty"`
222+
AzureStorageContainer string `json:"logical_backup_azure_storage_container,omitempty"`
223+
AzureStorageAccountKey string `json:"logical_backup_azure_storage_account_key,omitempty"`
221224
S3Bucket string `json:"logical_backup_s3_bucket,omitempty"`
222225
S3Region string `json:"logical_backup_s3_region,omitempty"`
223226
S3Endpoint string `json:"logical_backup_s3_endpoint,omitempty"`
@@ -227,9 +230,10 @@ type OperatorLogicalBackupConfiguration struct {
227230
RetentionTime string `json:"logical_backup_s3_retention_time,omitempty"`
228231
GoogleApplicationCredentials string `json:"logical_backup_google_application_credentials,omitempty"`
229232
JobPrefix string `json:"logical_backup_job_prefix,omitempty"`
230-
AzureStorageAccountName string `json:"logical_backup_azure_storage_account_name,omitempty"`
231-
AzureStorageContainer string `json:"logical_backup_azure_storage_container,omitempty"`
232-
AzureStorageAccountKey string `json:"logical_backup_azure_storage_account_key,omitempty"`
233+
CPURequest string `json:"logical_backup_cpu_request,omitempty"`
234+
MemoryRequest string `json:"logical_backup_memory_request,omitempty"`
235+
CPULimit string `json:"logical_backup_cpu_limit,omitempty"`
236+
MemoryLimit string `json:"logical_backup_memory_limit,omitempty"`
233237
}
234238

235239
// PatroniConfiguration defines configuration for Patroni

pkg/cluster/k8sres.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ func makeDefaultResources(config *config.Config) acidv1.Resources {
139139
}
140140
}
141141

142+
func makeLogicalBackupResources(config *config.Config) acidv1.Resources {
143+
144+
logicalBackupResourceRequests := acidv1.ResourceDescription{
145+
CPU: config.LogicalBackup.LogicalBackupCPURequest,
146+
Memory: config.LogicalBackup.LogicalBackupMemoryRequest,
147+
}
148+
logicalBackupResourceLimits := acidv1.ResourceDescription{
149+
CPU: config.LogicalBackup.LogicalBackupCPULimit,
150+
Memory: config.LogicalBackup.LogicalBackupMemoryLimit,
151+
}
152+
153+
return acidv1.Resources{
154+
ResourceRequests: logicalBackupResourceRequests,
155+
ResourceLimits: logicalBackupResourceLimits,
156+
}
157+
}
158+
142159
func (c *Cluster) enforceMinResourceLimits(resources *v1.ResourceRequirements) error {
143160
var (
144161
isSmaller bool
@@ -2107,9 +2124,12 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1.CronJob, error) {
21072124

21082125
c.logger.Debug("Generating logical backup pod template")
21092126

2110-
// allocate for the backup pod the same amount of resources as for normal DB pods
2127+
// allocate configured resources for logical backup pod
2128+
logicalBackupResources := makeLogicalBackupResources(&c.OpConfig)
2129+
// if not defined only default resources from spilo pods are used
21112130
resourceRequirements, err = c.generateResourceRequirements(
2112-
c.Spec.Resources, makeDefaultResources(&c.OpConfig), logicalBackupContainerName)
2131+
&logicalBackupResources, makeDefaultResources(&c.OpConfig), logicalBackupContainerName)
2132+
21132133
if err != nil {
21142134
return nil, fmt.Errorf("could not generate resource requirements for logical backup pods: %v", err)
21152135
}

0 commit comments

Comments
 (0)