Skip to content

Commit 1cf15e7

Browse files
committed
some adjust
1 parent 73b9da8 commit 1cf15e7

File tree

5 files changed

+123
-117
lines changed

5 files changed

+123
-117
lines changed

platforms/kubernetes/postgres-operator/deploy/postgres-operator.yaml.template

+41-40
Original file line numberDiff line numberDiff line change
@@ -357,50 +357,51 @@ spec:
357357
type: object
358358
x-kubernetes-preserve-unknown-fields: true
359359
properties:
360-
backups3:
360+
backupToS3:
361361
type: object
362+
x-kubernetes-preserve-unknown-fields: true
362363
properties:
363364
name:
364365
type: string
365-
manual:
366-
type: object
367-
properties:
368-
trigger-id:
369-
type: integer
370-
cron:
371-
type: object
372-
properties:
373-
enable:
374-
type: boolean
375-
schedule:
376-
type: string
377-
policy:
378-
type: object
379-
properties:
380-
archive:
381-
type: string
382-
enum:
383-
- 'on'
384-
- 'off'
385-
default: 'off'
386-
compression:
387-
type: string
388-
enum:
389-
- 'gzip'
390-
- 'bzip2'
391-
- 'snappy'
392-
- 'none'
393-
default: 'none'
394-
encryption:
395-
type: string
396-
enum:
397-
- 'AES256'
398-
- 'aws:kms'
399-
- 'none'
400-
default: 'none'
401-
retention:
402-
type: string
403-
default: 'none'
366+
manual:
367+
type: object
368+
properties:
369+
trigger-id:
370+
type: integer
371+
cron:
372+
type: object
373+
properties:
374+
enable:
375+
type: boolean
376+
schedule:
377+
type: string
378+
policy:
379+
type: object
380+
properties:
381+
archive:
382+
type: string
383+
enum:
384+
- 'on'
385+
- 'off'
386+
default: 'off'
387+
compression:
388+
type: string
389+
enum:
390+
- 'gzip'
391+
- 'bzip2'
392+
- 'snappy'
393+
- 'none'
394+
default: 'none'
395+
encryption:
396+
type: string
397+
enum:
398+
- 'AES256'
399+
- 'aws:kms'
400+
- 'none'
401+
default: 'none'
402+
retention:
403+
type: string
404+
default: 'none'
404405
restore:
405406
type: object
406407
x-kubernetes-preserve-unknown-fields: true

platforms/kubernetes/postgres-operator/deploy/postgresql.yaml

+20-20
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,27 @@ spec:
165165
BUCKET: "postgresql"
166166
PATH: "test/backup"
167167
# backupCluster:
168-
## backups3:
168+
# backupToS3:
169169
## name: postgresql-backup
170-
# manual:
171-
# trigger-id: 2
172-
# cron:
173-
# enable: true # whether to enable scheduled backup
174-
# schedule: "0 1 * * wed,sat" # cron expression: minute(0-59) hour(0-23) day(1-31) month(1-12) day_of_week(0-6, mon,tue,wed,thu,fri,sat,sun)
175-
# execute once a day at 23:00: 0 23 * * *
176-
# 1:00 every weekend: 0 1 * * sun
177-
# executed at 1:00 AM on the first day of each month : 0 1 1 * *
178-
# execute once every day at 0:00, 13:00: 0 0,13 * * *
179-
# executed at 1:00 AM every Wednesday and Saturday: 0 1 * * wed,sat
180-
# For more information see https://apscheduler.readthedocs.io/en/3.x/modules/triggers/cron.html?highlight=cron
181-
# policy: # take effect on next backup
182-
# archive: 'on' # whether to archive WAL. on/off
183-
# compression: gzip # backup compression. none/gzip/bzip2/snappy
184-
# encryption: AES256 # backup encryption. none/AES256/aws:kms
185-
# retention: REDUNDANCY 10 # backup retention policy. none/REDUNDANCY value/RECOVERY WINDOW OF value {DAYS | WEEKS | MONTHS}
186-
# none: backup does not expire
187-
# REDUNDANCY value: keep the number of backups. eg: REDUNDANCY 10.
188-
# RECOVERY WINDOW OF value {DAYS | WEEKS | MONTHS}: keep backup time. eg: RECOVERY WINDOW OF 60 DAYS
170+
# manual:
171+
# trigger-id: 1
172+
# cron:
173+
# enable: true # whether to enable scheduled backup
174+
# schedule: "0 1 * * wed,sat" # cron expression: minute(0-59) hour(0-23) day(1-31) month(1-12) day_of_week(0-6, mon,tue,wed,thu,fri,sat,sun)
175+
## execute once a day at 23:00: 0 23 * * *
176+
## 1:00 every weekend: 0 1 * * sun
177+
## executed at 1:00 AM on the first day of each month : 0 1 1 * *
178+
## execute once every day at 0:00, 13:00: 0 0,13 * * *
179+
## executed at 1:00 AM every Wednesday and Saturday: 0 1 * * wed,sat
180+
## For more information see https://apscheduler.readthedocs.io/en/3.x/modules/triggers/cron.html?highlight=cron
181+
# policy: # take effect on next backup
182+
# archive: 'on' # whether to archive WAL. on/off
183+
# compression: gzip # backup compression. none/gzip/bzip2/snappy
184+
# encryption: AES256 # backup encryption. none/AES256/aws:kms
185+
# retention: REDUNDANCY 10 # backup retention policy. none/REDUNDANCY value/RECOVERY WINDOW OF value {DAYS | WEEKS | MONTHS}
186+
# none: backup does not expire
187+
# REDUNDANCY value: keep the number of backups. eg: REDUNDANCY 10.
188+
# RECOVERY WINDOW OF value {DAYS | WEEKS | MONTHS}: keep backup time. eg: RECOVERY WINDOW OF 60 DAYS
189189
# restore:
190190
# froms3:
191191
## name: postgresql-backup

platforms/kubernetes/postgres-operator/postgres/constants.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@
4949
SPEC_POSTGRESQL_USERS_NORMAL = "normal"
5050
SPEC_POSTGRESQL_USERS_USER_PASSWORD = "password"
5151
SPEC_POSTGRESQL_USERS_USER_NAME = "name"
52-
SPEC_BACKUP = "backupCluster"
53-
SPEC_BACKUP_BACKUPS3 = "backups3"
54-
SPEC_BACKUP_BACKUPS3_NAME = "name"
55-
SPEC_BACKUP_MANUAL = "manual"
56-
SPEC_BACKUP_TRIGGER_ID = "trigger-id"
57-
SPEC_BACKUP_CRON = "cron"
58-
SPEC_BACKUP_CRON_ENABLE = "enable"
59-
SPEC_BACKUP_CRON_SCHEDULE = "schedule"
60-
SPEC_BACKUP_POLICY = "policy"
61-
SPEC_BACKUP_POLICY_ARCHIVE = "archive"
62-
SPEC_BACKUP_POLICY_ARCHIVE_DEFAULT_VALUE = "off"
63-
SPEC_BACKUP_POLICY_COMPRESSION = "compression"
64-
SPEC_BACKUP_POLICY_COMPRESSION_DEFAULT_VALUE = "none"
65-
SPEC_BACKUP_POLICY_ENCRYPTION = "encryption"
66-
SPEC_BACKUP_POLICY_ENCRYPTION_DEFAULT_VALUE = "none"
67-
SPEC_BACKUP_POLICY_RETENTION = "retention"
68-
SPEC_BACKUP_POLICY_RETENTION_DEFAULT_VALUE = "none"
52+
SPEC_BACKUPCLUSTER = "backupCluster"
53+
SPEC_BACKUPTOS3 = "backupToS3"
54+
SPEC_BACKUPTOS3_NAME = "name"
55+
SPEC_BACKUPTOS3_MANUAL = "manual"
56+
SPEC_BACKUPTOS3_MANUAL_TRIGGER_ID = "trigger-id"
57+
SPEC_BACKUPTOS3_CRON = "cron"
58+
SPEC_BACKUPTOS3_CRON_ENABLE = "enable"
59+
SPEC_BACKUPTOS3_CRON_SCHEDULE = "schedule"
60+
SPEC_BACKUPTOS3_POLICY = "policy"
61+
SPEC_BACKUPTOS3_POLICY_ARCHIVE = "archive"
62+
SPEC_BACKUPTOS3_POLICY_ARCHIVE_DEFAULT_VALUE = "off"
63+
SPEC_BACKUPTOS3_POLICY_COMPRESSION = "compression"
64+
SPEC_BACKUPTOS3_POLICY_COMPRESSION_DEFAULT_VALUE = "none"
65+
SPEC_BACKUPTOS3_POLICY_ENCRYPTION = "encryption"
66+
SPEC_BACKUPTOS3_POLICY_ENCRYPTION_DEFAULT_VALUE = "none"
67+
SPEC_BACKUPTOS3_POLICY_RETENTION = "retention"
68+
SPEC_BACKUPTOS3_POLICY_RETENTION_DEFAULT_VALUE = "none"
6969
RESTORE = "restore"
7070
RESTORE_FROMSSH = "fromssh"
7171
RESTORE_FROMSSH_PATH = "path"

platforms/kubernetes/postgres-operator/postgres/handle.py

+40-36
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,23 @@
152152
SPEC_S3_ENDPOINT,
153153
SPEC_S3_BUCKET,
154154
SPEC_S3_PATH,
155-
SPEC_BACKUP,
156-
SPEC_BACKUP_BACKUPS3,
157-
SPEC_BACKUP_BACKUPS3_NAME,
158-
SPEC_BACKUP_MANUAL,
159-
SPEC_BACKUP_TRIGGER_ID,
160-
SPEC_BACKUP_CRON,
161-
SPEC_BACKUP_CRON_ENABLE,
162-
SPEC_BACKUP_CRON_SCHEDULE,
163-
SPEC_BACKUP_POLICY,
164-
SPEC_BACKUP_POLICY_ARCHIVE,
165-
SPEC_BACKUP_POLICY_ARCHIVE_DEFAULT_VALUE,
166-
SPEC_BACKUP_POLICY_COMPRESSION,
167-
SPEC_BACKUP_POLICY_COMPRESSION_DEFAULT_VALUE,
168-
SPEC_BACKUP_POLICY_ENCRYPTION,
169-
SPEC_BACKUP_POLICY_ENCRYPTION_DEFAULT_VALUE,
170-
SPEC_BACKUP_POLICY_RETENTION,
171-
SPEC_BACKUP_POLICY_RETENTION_DEFAULT_VALUE,
155+
SPEC_BACKUPCLUSTER,
156+
SPEC_BACKUPTOS3,
157+
SPEC_BACKUPTOS3_NAME,
158+
SPEC_BACKUPTOS3_MANUAL,
159+
SPEC_BACKUPTOS3_MANUAL_TRIGGER_ID,
160+
SPEC_BACKUPTOS3_CRON,
161+
SPEC_BACKUPTOS3_CRON_ENABLE,
162+
SPEC_BACKUPTOS3_CRON_SCHEDULE,
163+
SPEC_BACKUPTOS3_POLICY,
164+
SPEC_BACKUPTOS3_POLICY_ARCHIVE,
165+
SPEC_BACKUPTOS3_POLICY_ARCHIVE_DEFAULT_VALUE,
166+
SPEC_BACKUPTOS3_POLICY_COMPRESSION,
167+
SPEC_BACKUPTOS3_POLICY_COMPRESSION_DEFAULT_VALUE,
168+
SPEC_BACKUPTOS3_POLICY_ENCRYPTION,
169+
SPEC_BACKUPTOS3_POLICY_ENCRYPTION_DEFAULT_VALUE,
170+
SPEC_BACKUPTOS3_POLICY_RETENTION,
171+
SPEC_BACKUPTOS3_POLICY_RETENTION_DEFAULT_VALUE,
172172
RESTORE_FROMS3,
173173
RESTORE_FROMS3_NAME,
174174
RESTORE_FROMS3_RECOVERY,
@@ -224,8 +224,8 @@
224224
VOLUMECLAIMTEMPLATES)
225225
DIFF_FIELD_SPEC_ANTIAFFINITY = (SPEC, SPEC_ANTIAFFINITY)
226226
DIFF_FIELD_SPEC_S3 = (SPEC, SPEC_S3)
227-
DIFF_FIELD_SPEC_BACKUP = (SPEC, SPEC_BACKUP)
228-
DIFF_FIELD_SPEC_BACKUP_MANUAL = (SPEC, SPEC_BACKUP, SPEC_BACKUP_MANUAL)
227+
DIFF_FIELD_SPEC_BACKUPS3 = (SPEC, SPEC_BACKUPCLUSTER, SPEC_BACKUPTOS3)
228+
DIFF_FIELD_SPEC_BACKUPS3_MANUAL = (SPEC, SPEC_BACKUPCLUSTER, SPEC_BACKUPTOS3, SPEC_BACKUPTOS3_MANUAL)
229229
STATEFULSET_REPLICAS = 1
230230
PG_CONFIG_MASTER_LARGE_THAN_SLAVE = ("max_connections", "max_worker_processes", "max_wal_senders", "max_prepared_transactions", "max_locks_per_transaction")
231231
PG_CONFIG_IGNORE = ("block_size", "data_checksums", "data_directory_mode",
@@ -1648,10 +1648,10 @@ def get_policy_env(policy: TypedDict) -> List:
16481648
res = list()
16491649

16501650
default_policy = {
1651-
SPEC_BACKUP_POLICY_ARCHIVE: SPEC_BACKUP_POLICY_ARCHIVE_DEFAULT_VALUE,
1652-
SPEC_BACKUP_POLICY_COMPRESSION: SPEC_BACKUP_POLICY_COMPRESSION_DEFAULT_VALUE,
1653-
SPEC_BACKUP_POLICY_ENCRYPTION: SPEC_BACKUP_POLICY_ENCRYPTION_DEFAULT_VALUE,
1654-
SPEC_BACKUP_POLICY_RETENTION: SPEC_BACKUP_POLICY_RETENTION_DEFAULT_VALUE
1651+
SPEC_BACKUPTOS3_POLICY_ARCHIVE: SPEC_BACKUPTOS3_POLICY_ARCHIVE_DEFAULT_VALUE,
1652+
SPEC_BACKUPTOS3_POLICY_COMPRESSION: SPEC_BACKUPTOS3_POLICY_COMPRESSION_DEFAULT_VALUE,
1653+
SPEC_BACKUPTOS3_POLICY_ENCRYPTION: SPEC_BACKUPTOS3_POLICY_ENCRYPTION_DEFAULT_VALUE,
1654+
SPEC_BACKUPTOS3_POLICY_RETENTION: SPEC_BACKUPTOS3_POLICY_RETENTION_DEFAULT_VALUE
16551655
}
16561656

16571657
for k, v in policy.items():
@@ -1845,7 +1845,10 @@ def is_backup_mode(
18451845
status: kopf.Status,
18461846
logger: logging.Logger,
18471847
) -> bool:
1848-
if spec.get(SPEC_BACKUP) == None:
1848+
if spec.get(SPEC_BACKUPCLUSTER) == None:
1849+
return False
1850+
1851+
if spec[SPEC_BACKUPCLUSTER].get(SPEC_BACKUPTOS3) == None:
18491852
return False
18501853

18511854
return True
@@ -1865,7 +1868,7 @@ def is_s3_manual_backup_mode(
18651868
logger.warning("s3 related information is not set.")
18661869
return False
18671870

1868-
if spec[SPEC_BACKUP].get(SPEC_BACKUP_MANUAL) != None:
1871+
if spec[SPEC_BACKUPCLUSTER].get(SPEC_BACKUPTOS3, {}).get(SPEC_BACKUPTOS3_MANUAL) != None:
18691872
return True
18701873

18711874
return False
@@ -1885,7 +1888,7 @@ def is_s3_cron_backup_mode(
18851888
logger.warning("s3 related information is not set.")
18861889
return False
18871890

1888-
if spec[SPEC_BACKUP].get(SPEC_BACKUP_CRON) != None:
1891+
if spec[SPEC_BACKUPCLUSTER].get(SPEC_BACKUPTOS3, {}).get(SPEC_BACKUPTOS3_CRON) != None:
18891892
return True
18901893

18911894
return False
@@ -1923,10 +1926,10 @@ def backup_postgresql_to_s3(
19231926
s3 = spec[SPEC_S3].copy()
19241927
s3_list = get_s3_env(s3)
19251928

1926-
backup_policy = spec.get(SPEC_BACKUP, {}).get(SPEC_BACKUP_POLICY, {})
1929+
backup_policy = spec[SPEC_BACKUPCLUSTER][SPEC_BACKUPTOS3].get(SPEC_BACKUPTOS3_POLICY, {})
19271930
policy_list = get_policy_env(backup_policy)
19281931

1929-
name = spec[SPEC_BACKUP].get(SPEC_BACKUP_BACKUPS3, {}).get(SPEC_BACKUP_BACKUPS3_NAME, None)
1932+
name = spec[SPEC_BACKUPCLUSTER][SPEC_BACKUPTOS3].get(SPEC_BACKUPTOS3_NAME, None)
19301933
name_list = get_backup_name_env(meta, name)
19311934

19321935
s3_info = [*s3_list, *policy_list, *name_list]
@@ -3575,7 +3578,7 @@ def correct_backup_status(
35753578
logger: logging.Logger,
35763579
) -> None:
35773580
if is_s3_manual_backup_mode(meta, spec, patch, status, logger) or is_s3_cron_backup_mode(meta, spec, patch, status, logger):
3578-
if spec.get(SPEC_BACKUP, {}).get(SPEC_BACKUP_POLICY, {}).get(SPEC_BACKUP_POLICY_ARCHIVE, "") == "on":
3581+
if spec[SPEC_BACKUPCLUSTER][SPEC_BACKUPTOS3].get(SPEC_BACKUPTOS3_POLICY, {}).get(SPEC_BACKUPTOS3_POLICY_ARCHIVE, "") == "on":
35793582
readwrite_conns = connections(spec, meta, patch,
35803583
get_field(POSTGRESQL, READWRITEINSTANCE),
35813584
False, None, logger, None, status, False)
@@ -4856,11 +4859,11 @@ def update_cluster(
48564859
update_configs(meta, spec, patch, status, logger, AC, FIELD, OLD,
48574860
NEW)
48584861

4859-
if FIELD[0:len(DIFF_FIELD_SPEC_BACKUP_MANUAL
4860-
)] == DIFF_FIELD_SPEC_BACKUP_MANUAL or (
4861-
FIELD[0:len(DIFF_FIELD_SPEC_BACKUP)]
4862-
== DIFF_FIELD_SPEC_BACKUP and AC == "add"
4863-
and OLD is None and SPEC_BACKUP_MANUAL in NEW):
4862+
if FIELD[0:len(DIFF_FIELD_SPEC_BACKUPS3_MANUAL
4863+
)] == DIFF_FIELD_SPEC_BACKUPS3_MANUAL or (
4864+
FIELD[0:len(DIFF_FIELD_SPEC_BACKUPS3)]
4865+
== DIFF_FIELD_SPEC_BACKUPS3 and AC == "add"
4866+
and OLD is None and SPEC_BACKUPTOS3_MANUAL in NEW):
48644867
need_backup_cluster = True
48654868

48664869

@@ -4922,8 +4925,9 @@ def cron_cluster(
49224925
scheduler: BackgroundScheduler,
49234926
) -> None:
49244927

4925-
new_cron_expression = spec.get(SPEC_BACKUP, {}).get(SPEC_BACKUP_CRON, {}).get(SPEC_BACKUP_CRON_SCHEDULE, None)
4926-
cron_enable = spec.get(SPEC_BACKUP, {}).get(SPEC_BACKUP_CRON, {}).get(SPEC_BACKUP_CRON_ENABLE, None)
4928+
cron = spec.get(SPEC_BACKUPCLUSTER, {}).get(SPEC_BACKUPTOS3, {}).get(SPEC_BACKUPTOS3_CRON, {})
4929+
new_cron_expression = cron.get(SPEC_BACKUPTOS3_CRON_SCHEDULE, None)
4930+
cron_enable = cron.get(SPEC_BACKUPTOS3_CRON_ENABLE, None)
49274931
jobs = scheduler.get_jobs()
49284932

49294933
if cron_enable:

platforms/kubernetes/postgres-operator/postgres/postgres.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
from kubernetes import client, config
1414

1515
from constants import (
16-
SPEC_BACKUP,
17-
SPEC_BACKUP_CRON,
18-
SPEC_BACKUP_CRON_ENABLE,
16+
SPEC_BACKUPCLUSTER,
17+
SPEC_BACKUPTOS3,
18+
SPEC_BACKUPTOS3_CRON,
19+
SPEC_BACKUPTOS3_CRON_ENABLE,
1920
)
2021

2122

@@ -126,7 +127,7 @@ def cluster_timer(
126127
RESOURCE_POSTGRESQL,
127128
backoff=operator_config.BOOTSTRAP_RETRY_DELAY,
128129
initial_delay=30,
129-
when=lambda spec, **_: spec.get(SPEC_BACKUP, {}).get(SPEC_BACKUP_CRON, {}).get(SPEC_BACKUP_CRON_ENABLE, False) is True,
130+
when=lambda spec, **_: spec.get(SPEC_BACKUPCLUSTER, {}).get(SPEC_BACKUPTOS3, {}).get(SPEC_BACKUPTOS3_CRON, {}).get(SPEC_BACKUPTOS3_CRON_ENABLE, False) is True,
130131
)
131132
def cluster_daemon(
132133
meta: kopf.Meta,

0 commit comments

Comments
 (0)