Skip to content

Commit 4dfa6b4

Browse files
authored
Merge pull request #5 from radondb/develop-volume-adapt
volume adapt
2 parents 379befb + fbb2a31 commit 4dfa6b4

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ spec:
9999
enum:
100100
- true
101101
- false
102+
volume_type:
103+
type: string
104+
enum:
105+
- 'local'
106+
- 'cloud'
102107
antiaffinity:
103108
type: object
104109
x-kubernetes-preserve-unknown-fields: true

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ metadata:
66
spec:
77
action: start #stop start
88
deletepvc: true
9+
volume_type: local # local/cloud
910
antiaffinity:
1011
policy: preferred # preferred/required
1112
podAntiAffinityTerm: autofailover-readwrite # none/autofailover-readwrite/autofailover-readwrite-readonly

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
RESTORE_FROMSSH_PATH = "path"
5252
RESTORE_FROMSSH_ADDRESS = "address"
5353
RESTORE_FROMSSH_LOCAL = "local"
54+
SPEC_VOLUME_TYPE = "volume_type"
55+
SPEC_VOLUME_LOCAL = "local"
56+
SPEC_VOLUME_CLOUD = "cloud"
5457

5558
# api
5659
API_GROUP = "postgres.radondb.io"
@@ -116,6 +119,12 @@
116119
SPEC_ANTIAFFINITY_PODANTIAFFINITYTERM = "podAntiAffinityTerm"
117120
SPEC_ANTIAFFINITY_TOPOLOGYKEY = "topologyKey"
118121

122+
# time
123+
SECONDS = 1
124+
MINUTES = SECONDS * 60
125+
HOURS = MINUTES * 60
126+
DAYS = HOURS * 24
127+
119128
# docker-compose
120129
DOCKER_COMPOSE_FILE = "docker-compose.yaml"
121130
DOCKER_COMPOSE_FILE_DATA = '''

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@
127127
SPEC_ANTIAFFINITY_POLICY_PREFERRED,
128128
SPEC_ANTIAFFINITY_PODANTIAFFINITYTERM,
129129
SPEC_ANTIAFFINITY_TOPOLOGYKEY,
130+
SPEC_VOLUME_TYPE,
131+
SPEC_VOLUME_LOCAL,
132+
SPEC_VOLUME_CLOUD,
133+
SECONDS,
134+
MINUTES,
135+
HOURS,
136+
DAYS,
130137
)
131138

132139
FIELD_DELIMITER = "-"
@@ -499,7 +506,7 @@ def waiting_cluster_correct_status(
499506
def waiting_postgresql_ready(
500507
conns: InstanceConnections,
501508
logger: logging.Logger,
502-
timeout: int = 300,
509+
timeout: int = MINUTES * 5,
503510
connect_start: int = None,
504511
connect_end: int = None,
505512
) -> bool:
@@ -539,7 +546,7 @@ def waiting_target_postgresql_ready(meta: kopf.Meta,
539546
connect_start: int = None,
540547
connect_end: int = None,
541548
exit: bool = False,
542-
timeout: int = 300) -> None:
549+
timeout: int = MINUTES * 5) -> None:
543550
conns: InstanceConnections = connections(spec, meta, patch, field, False,
544551
None, logger, None, status, False,
545552
None)
@@ -2758,11 +2765,13 @@ def rolling_update(
27582765
logger: logging.Logger,
27592766
target_roles: List,
27602767
exit: bool = False,
2768+
delete_disk: bool = False,
2769+
timeout: int = MINUTES * 5,
27612770
) -> None:
27622771
if target_roles is None:
27632772
return
27642773

2765-
# rolling update autofailover
2774+
# rolling update autofailover, not allow autofailover delete disk when update cluster
27662775
if get_field(AUTOFAILOVER) in target_roles:
27672776
autofailover_machines = spec.get(AUTOFAILOVER).get(MACHINES)
27682777
if autofailover_machines != None:
@@ -2775,7 +2784,7 @@ def rolling_update(
27752784
create_autofailover(meta, spec, patch, status, logger,
27762785
get_autofailover_labels(meta))
27772786
waiting_target_postgresql_ready(meta, spec, patch, get_field(AUTOFAILOVER),
2778-
status, logger, 0, 1, exit)
2787+
status, logger, 0, 1, exit, timeout)
27792788

27802789
# rolling update readwrite
27812790
if get_field(POSTGRESQL, READWRITEINSTANCE) in target_roles:
@@ -2786,27 +2795,27 @@ def rolling_update(
27862795
delete_postgresql_readwrite(
27872796
meta, spec, patch, status, logger,
27882797
get_field(POSTGRESQL, READWRITEINSTANCE),
2789-
readwrite_machines[replica:replica + 1], None, False)
2798+
readwrite_machines[replica:replica + 1], None, delete_disk)
27902799
create_postgresql_readwrite(meta, spec, patch, status, logger,
27912800
get_readwrite_labels(meta),
27922801
replica, False, replica + 1)
27932802
waiting_target_postgresql_ready(
27942803
meta, spec, patch, get_field(POSTGRESQL,
27952804
READWRITEINSTANCE), status,
2796-
logger, replica, replica + 1, exit)
2805+
logger, replica, replica + 1, exit, timeout)
27972806
else:
27982807
for replica in range(0, spec[POSTGRESQL][READWRITEINSTANCE][REPLICAS]):
27992808
delete_postgresql_readwrite(
28002809
meta, spec, patch, status, logger,
28012810
get_field(POSTGRESQL, READWRITEINSTANCE), None,
2802-
[replica, replica + 1], False)
2811+
[replica, replica + 1], delete_disk)
28032812
create_postgresql_readwrite(meta, spec, patch, status, logger,
28042813
get_readwrite_labels(meta), replica,
28052814
False, replica + 1)
28062815
waiting_target_postgresql_ready(meta, spec, patch,
28072816
get_field(POSTGRESQL,
28082817
READWRITEINSTANCE), status,
2809-
logger, replica, replica + 1, exit)
2818+
logger, replica, replica + 1, exit, timeout)
28102819

28112820
# rolling update readonly
28122821
if get_field(POSTGRESQL, READONLYINSTANCE) in target_roles:
@@ -2817,25 +2826,25 @@ def rolling_update(
28172826
delete_postgresql_readonly(
28182827
meta, spec, patch, status, logger,
28192828
get_field(POSTGRESQL, READONLYINSTANCE),
2820-
readonly_machines[replica:replica + 1], None, False)
2829+
readonly_machines[replica:replica + 1], None, delete_disk)
28212830
create_postgresql_readonly(meta, spec, patch, status, logger,
28222831
get_readonly_labels(meta), replica,
28232832
replica + 1)
28242833
waiting_target_postgresql_ready(
28252834
meta, spec, patch, get_field(POSTGRESQL, READONLYINSTANCE),
2826-
status, logger, replica, replica + 1, exit)
2835+
status, logger, replica, replica + 1, exit, timeout)
28272836
else:
28282837
for replica in range(0, spec[POSTGRESQL][READONLYINSTANCE][REPLICAS]):
28292838
delete_postgresql_readonly(meta, spec, patch, status, logger,
28302839
get_field(POSTGRESQL, READONLYINSTANCE),
2831-
None, [replica, replica + 1], False)
2840+
None, [replica, replica + 1], delete_disk)
28322841
create_postgresql_readonly(meta, spec, patch, status, logger,
28332842
get_readonly_labels(meta), replica,
28342843
replica + 1)
28352844
waiting_target_postgresql_ready(meta, spec, patch,
28362845
get_field(POSTGRESQL,
28372846
READONLYINSTANCE), status,
2838-
logger, replica, replica + 1, exit)
2847+
logger, replica, replica + 1, exit, timeout)
28392848

28402849

28412850
def update_podspec_volume(
@@ -2875,8 +2884,15 @@ def update_antiaffinity(
28752884
logger: logging.Logger,
28762885
target_roles: List,
28772886
exit: bool = False,
2887+
delete_disk: bool = False,
2888+
timeout: int = MINUTES * 5,
28782889
) -> None:
2879-
rolling_update(meta, spec, patch, status, logger, target_roles, exit)
2890+
# local volume
2891+
if spec.get(SPEC_VOLUME_TYPE) == SPEC_VOLUME_LOCAL:
2892+
delete_disk = True
2893+
timeout = HOURS * 1
2894+
rolling_update(meta, spec, patch, status, logger, target_roles, exit,
2895+
delete_disk, timeout)
28802896

28812897

28822898
def update_replicas(

0 commit comments

Comments
 (0)