Skip to content

Commit

Permalink
disaster mode allow start/stop action.
Browse files Browse the repository at this point in the history
add timer run time to status.timer.
  • Loading branch information
zlianzhuang committed Sep 26, 2023
1 parent c9631fd commit d855071
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion operatorversions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"clusterrolebinding": "radondb-postgres-operator-rolebinding-cluster",
"rolebinding": "radondb-postgres-operator-rolebinding-role",
"name": "radondb-postgres-operator",
"image": "radondb/radondb-postgres-operator:v1.3.1",
"image": "radondb/radondb-postgres-operator:v1.3.2",
"datapath": "/data",
"imageRegistry": "",
"namespaceOverride": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ spec:
priorityClassName: system-cluster-critical
containers:
- name: radondb-postgres-operator
image: radondb/radondb-postgres-operator:v1.3.1
image: radondb/radondb-postgres-operator:v1.3.2
imagePullPolicy: IfNotPresent
resources:
limits:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import kopf
import logging
import copy
import time

from kubernetes import client

Expand All @@ -16,13 +17,20 @@
get_postgresql_config_port, set_cluster_status, to_int, create_ssl_key


def current_time() -> str:
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

def timer_cluster(
meta: kopf.Meta,
spec: kopf.Spec,
patch: kopf.Patch,
status: kopf.Status,
logger: logging.Logger,
) -> None:
# set the timer run time
patch.status[CLUSTER_STATUS_TIMER] = current_time()
#set_cluster_status(meta, CLUSTER_STATUS_TIMER, current_time(), logger)

correct_postgresql_status_lsn(meta, spec, patch, status, logger)

if pgsql_util.in_disaster_backup(meta, spec, patch, status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,15 @@ def update_action(
spec, meta, patch,
pgsql_util.get_field(POSTGRESQL, READWRITEINSTANCE), False,
None, logger, None, status, False)
conns += readwrite_conns.get_conns()
readonly_conns = pgsql_util.connections(
spec, meta, patch,
pgsql_util.get_field(POSTGRESQL, READONLYINSTANCE), False,
None, logger, None, status, False)
conns += readonly_conns.get_conns()
if pgsql_util.in_disaster_backup(meta, spec, patch, status, logger) == True:
conns += [ readwrite_conns.get_conns()[0] ]
else:
conns += readwrite_conns.get_conns()
conns += readonly_conns.get_conns()
if NEW == ACTION_STOP:
start = False
elif NEW == ACTION_START:
Expand All @@ -223,7 +226,7 @@ def update_action(
pgsql_util.postgresql_action(meta, spec, patch, status, logger,
conn, start)

if NEW == ACTION_START:
if NEW == ACTION_START and pgsql_util.in_disaster_backup(meta, spec, patch, status, logger) == False:
pgsql_util.waiting_postgresql_ready(readwrite_conns, logger)
pgsql_util.waiting_postgresql_ready(readonly_conns, logger)
pgsql_util.waiting_cluster_final_status(
Expand Down Expand Up @@ -1821,6 +1824,8 @@ def update_common():

update_disasterBackup(meta, spec, patch, status, logger, AC,
FIELD, OLD, NEW)
update_action(meta, spec, patch, status, logger, AC, FIELD,
OLD, NEW)

if pgsql_util.in_disaster_backup(meta, spec, patch, status,
logger) == True:
Expand All @@ -1840,8 +1845,6 @@ def update_common():
OLD = diff[2]
NEW = diff[3]

update_action(meta, spec, patch, status, logger, AC, FIELD,
OLD, NEW)
update_service(meta, spec, patch, status, logger, AC, FIELD,
OLD, NEW)
trigger_rebuild_postgresql(meta, spec, patch, status, logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
CLUSTER_STATUS_SERVER_CRT = "server_crt"
CLUSTER_STATUS_CRON_NEXT_RUN = "cron_next_run_time"
CLUSTER_STATUS_DISASTER_BACKUP_STATUS = 'disaster_backup_status'
CLUSTER_STATUS_TIMER = 'timer'

# base label
BASE_LABEL_PART_OF = "part-of"
Expand Down

0 comments on commit d855071

Please sign in to comment.