|
139 | 139 | HOURS,
|
140 | 140 | DAYS,
|
141 | 141 | UPDATE_TOLERATION,
|
| 142 | + SPEC_POD_PRIORITY_CLASS, |
| 143 | + SPEC_POD_PRIORITY_CLASS_SCOPE_NODE, |
| 144 | + SPEC_POD_PRIORITY_CLASS_SCOPE_CLUSTER, |
142 | 145 | )
|
143 | 146 |
|
144 | 147 | PGLOG_DIR = "log"
|
@@ -680,6 +683,8 @@ def create_statefulset(
|
680 | 683 | "serviceName"] = statefulset_name_get_service_name(name)
|
681 | 684 | podspec = podspec_need_copy.copy()
|
682 | 685 | podspec["restartPolicy"] = "Always"
|
| 686 | + podspec.setdefault(SPEC_POD_PRIORITY_CLASS, |
| 687 | + SPEC_POD_PRIORITY_CLASS_SCOPE_CLUSTER) |
683 | 688 | antiaffinity = antiaffinity_need_copy.copy()
|
684 | 689 | is_required = antiaffinity[
|
685 | 690 | SPEC_ANTIAFFINITY_POLICY] == SPEC_ANTIAFFINITY_REQUIRED
|
@@ -3011,6 +3016,37 @@ def update_number_sync_standbys(
|
3011 | 3016 | break
|
3012 | 3017 | autofailover_conns.free_conns()
|
3013 | 3018 |
|
| 3019 | +def update_number_sync_standbys( |
| 3020 | + meta: kopf.Meta, |
| 3021 | + spec: kopf.Spec, |
| 3022 | + patch: kopf.Patch, |
| 3023 | + status: kopf.Status, |
| 3024 | + logger: logging.Logger, |
| 3025 | +) -> None: |
| 3026 | + mode, autofailover_replicas, readwrite_replicas, readonly_replicas = get_replicas( |
| 3027 | + spec) |
| 3028 | + |
| 3029 | + pg_nodes = readwrite_replicas + readonly_replicas |
| 3030 | + number_sync = readwrite_replicas + readonly_replicas if spec[POSTGRESQL][READONLYINSTANCE][STREAMING] == STREAMING_SYNC else readwrite_replicas |
| 3031 | + expect_number = number_sync - 2 |
| 3032 | + if expect_number < 0: |
| 3033 | + expect_number = 0 |
| 3034 | + |
| 3035 | + if pg_nodes >= 2: |
| 3036 | + autofailover_conns = connections(spec, meta, patch, |
| 3037 | + get_field(AUTOFAILOVER), False, |
| 3038 | + None, logger, None, status, False) |
| 3039 | + cmd = [ |
| 3040 | + "pgtools", "-S", |
| 3041 | + "' formation number-sync-standbys " + str(expect_number) + PRIMARY_FORMATION + "'" |
| 3042 | + ] |
| 3043 | + logger.info(f"set number-sync-standbys with cmd {cmd}") |
| 3044 | + output = exec_command(autofailover_conns.get_conns()[0], cmd, logger, interrupt=False) |
| 3045 | + if output.find(SUCCESS) == -1: |
| 3046 | + logger.error( |
| 3047 | + f"set number-sync-standbys failed {cmd} {output}") |
| 3048 | + autofailover_conns.free_conns() |
| 3049 | + |
3014 | 3050 |
|
3015 | 3051 | def update_streaming(
|
3016 | 3052 | meta: kopf.Meta,
|
|
0 commit comments