From f5f7cd0f99c558439f638cf201c24a5fa3747f43 Mon Sep 17 00:00:00 2001
From: cjc7373 <niuchangcun@gmail.com>
Date: Wed, 22 Jan 2025 17:15:26 +0800
Subject: [PATCH] chore: refactor roles (#1428)

(cherry picked from commit 1145cd8724078bfc80920deeea39d61588a54d55)
---
 addons/apecloud-mysql/templates/_helpers.tpl     | 15 ++++++---------
 .../apecloud-postgresql/templates/_helpers.tpl   | 15 ++++++---------
 addons/etcd/templates/cmpd.yaml                  | 10 ++++------
 addons/minio/templates/cmpd.yaml                 |  5 ++---
 addons/mogdb/templates/cmpd.yaml                 |  8 ++++----
 .../mongodb/templates/componentdefinition.yaml   | 10 ++++------
 addons/mysql/templates/_helpers.tpl              | 16 ++++++++--------
 addons/orchestrator/templates/cmpd-raft.yaml     | 10 ++++------
 addons/polardbx/templates/cmpd-dn.yaml           | 10 ++++------
 addons/polardbx/templates/cmpd-gms.yaml          | 10 ++++------
 .../templates/componentdefinition-12.yaml        |  8 ++++----
 .../templates/componentdefinition-14.yaml        |  8 ++++----
 .../templates/componentdefinition-15.yaml        |  8 ++++----
 .../templates/componentdefinition-16.yaml        |  8 ++++----
 addons/redis/templates/cmpd-redis-7.yaml         |  8 ++++----
 addons/redis/templates/cmpd-redis-cluster-7.yaml |  8 ++++----
 .../tidb/templates/componentdefinition-pd.yaml   | 10 ++++------
 addons/vanilla-postgresql/templates/_helpers.tpl |  8 ++++----
 addons/zookeeper/templates/cmpd.yaml             | 15 ++++++---------
 19 files changed, 84 insertions(+), 106 deletions(-)

diff --git a/addons/apecloud-mysql/templates/_helpers.tpl b/addons/apecloud-mysql/templates/_helpers.tpl
index d1f11814f..fd4f913b4 100644
--- a/addons/apecloud-mysql/templates/_helpers.tpl
+++ b/addons/apecloud-mysql/templates/_helpers.tpl
@@ -133,17 +133,14 @@ tls:
   keyFile: key.pem
 roles:
   - name: leader
-    serviceable: true
-    writable: true
-    votable: true
+    updatePriority: 3
+    participatesInQuorum: true
   - name: follower
-    serviceable: true
-    writable: false
-    votable: true
+    updatePriority: 2
+    participatesInQuorum: true
   - name: learner
-    serviceable: false
-    writable: false
-    votable: false
+    updatePriority: 1
+    participatesInQuorum: false
 lifecycleActions:
   roleProbe:
     periodSeconds: {{ .Values.roleProbe.periodSeconds }}
diff --git a/addons/apecloud-postgresql/templates/_helpers.tpl b/addons/apecloud-postgresql/templates/_helpers.tpl
index 93160a4c6..9eff7cda2 100644
--- a/addons/apecloud-postgresql/templates/_helpers.tpl
+++ b/addons/apecloud-postgresql/templates/_helpers.tpl
@@ -149,17 +149,14 @@ volumes:
     needSnapshot: false
 roles:
   - name: leader
-    serviceable: true
-    writable: true
-    votable: true
+    updatePriority: 3
+    participatesInQuorum: true
   - name: follower
-    serviceable: true
-    writable: false
-    votable: true
+    updatePriority: 2
+    participatesInQuorum: true
   - name: learner
-    serviceable: false
-    writable: false
-    votable: false
+    updatePriority: 1
+    participatesInQuorum: false
 vars:
   ## the postgres leader pod name which is dynamically selected, caution to use it
   - name: POSTGRES_LEADER_POD_NAME
diff --git a/addons/etcd/templates/cmpd.yaml b/addons/etcd/templates/cmpd.yaml
index e7347122a..039a09a31 100644
--- a/addons/etcd/templates/cmpd.yaml
+++ b/addons/etcd/templates/cmpd.yaml
@@ -126,13 +126,11 @@ spec:
   updateStrategy: Serial
   roles:
     - name: leader
-      serviceable: true
-      writable: true
-      votable: true
+      updatePriority: 2
+      participatesInQuorum: true
     - name: follower
-      serviceable: true
-      writable: false
-      votable: true
+      updatePriority: 1
+      participatesInQuorum: true
   lifecycleActions:
     roleProbe:
       exec:
diff --git a/addons/minio/templates/cmpd.yaml b/addons/minio/templates/cmpd.yaml
index ba6a4be3a..64cb93ae2 100644
--- a/addons/minio/templates/cmpd.yaml
+++ b/addons/minio/templates/cmpd.yaml
@@ -85,9 +85,8 @@ spec:
 
   roles:
     - name: readwrite
-      serviceable: true
-      votable: false
-      writable: true
+      updatePriority: 1
+      participatesInQuorum: false
 
   lifecycleActions:
     roleProbe:
diff --git a/addons/mogdb/templates/cmpd.yaml b/addons/mogdb/templates/cmpd.yaml
index b07dc8c9c..e34c01e15 100644
--- a/addons/mogdb/templates/cmpd.yaml
+++ b/addons/mogdb/templates/cmpd.yaml
@@ -46,11 +46,11 @@ spec:
     {{- end }}
   roles:
     - name: primary
-      serviceable: true
-      writable: true
+      updatePriority: 2
+      participatesInQuorum: false
     - name: secondary
-      serviceable: false
-      writable: false
+      updatePriority: 1
+      participatesInQuorum: false
   systemAccounts:
     - name: root
       initAccount: true
diff --git a/addons/mongodb/templates/componentdefinition.yaml b/addons/mongodb/templates/componentdefinition.yaml
index 21023adf0..76c37717e 100644
--- a/addons/mongodb/templates/componentdefinition.yaml
+++ b/addons/mongodb/templates/componentdefinition.yaml
@@ -64,13 +64,11 @@ spec:
         letterCase: MixedCases
   roles:
     - name: primary
-      serviceable: true
-      writable: true
-      votable: true
+      updatePriority: 2
+      participatesInQuorum: true
     - name: secondary
-      serviceable: true
-      writable: false
-      votable: true
+      updatePriority: 1
+      participatesInQuorum: true
   lifecycleActions:
     roleProbe:
       periodSeconds: {{ .Values.roleProbe.periodSeconds }}
diff --git a/addons/mysql/templates/_helpers.tpl b/addons/mysql/templates/_helpers.tpl
index 4550babc7..e68b3e370 100644
--- a/addons/mysql/templates/_helpers.tpl
+++ b/addons/mysql/templates/_helpers.tpl
@@ -213,11 +213,11 @@ lifecycleActions:
           /tools/syncerctl switchover --primary "$KB_LEADER_POD_NAME" ${KB_SWITCHOVER_CANDIDATE_NAME:+--candidate "$KB_SWITCHOVER_CANDIDATE_NAME"}
 roles:
   - name: primary
-    serviceable: true
-    writable: true
+    updatePriority: 2
+    participatesInQuorum: false
   - name: secondary
-    serviceable: true
-    writable: false
+    updatePriority: 1
+    participatesInQuorum: false
 {{- end }}
 
 {{- define "mysql.spec.runtime.common" -}}
@@ -281,11 +281,11 @@ systemAccounts:
     statement: CREATE USER IF NOT EXISTS '${KB_ACCOUNT_NAME}' IDENTIFIED BY '${KB_ACCOUNT_PASSWORD}'; GRANT SELECT ON performance_schema.* TO '${KB_ACCOUNT_NAME}'; GRANT SELECT ON sys.* TO '${KB_ACCOUNT_NAME}';
 roles:
   - name: primary
-    serviceable: true
-    writable: true
+    updatePriority: 2
+    participatesInQuorum: false
   - name: secondary
-    serviceable: true
-    writable: false
+    updatePriority: 1
+    participatesInQuorum: false
 vars:
   - name: ORC_TOPOLOGY_USER
     valueFrom:
diff --git a/addons/orchestrator/templates/cmpd-raft.yaml b/addons/orchestrator/templates/cmpd-raft.yaml
index 3525f0887..dc2d95577 100644
--- a/addons/orchestrator/templates/cmpd-raft.yaml
+++ b/addons/orchestrator/templates/cmpd-raft.yaml
@@ -10,13 +10,11 @@ spec:
   {{- include "orchestrator.cmpd.spec.common" . | nindent 2 }}
   roles:
     - name: primary
-      serviceable: true
-      writable: true
-      votable: true
+      updatePriority: 2
+      participatesInQuorum: true
     - name: secondary
-      serviceable: true
-      writable: false
-      votable: true
+      updatePriority: 1
+      participatesInQuorum: true
   vars:
     - name: ORC_META_DATABASE
       value: orchestrator
diff --git a/addons/polardbx/templates/cmpd-dn.yaml b/addons/polardbx/templates/cmpd-dn.yaml
index 405376fca..d96f43138 100644
--- a/addons/polardbx/templates/cmpd-dn.yaml
+++ b/addons/polardbx/templates/cmpd-dn.yaml
@@ -27,13 +27,11 @@ spec:
   updateStrategy: Serial
   roles:
     - name: leader
-      serviceable: true
-      writable: true
-      votable: true
+      updatePriority: 2
+      participatesInQuorum: true
     - name: follower
-      serviceable: true
-      writable: false
-      votable: true
+      updatePriority: 1
+      participatesInQuorum: true
   volumes:
     - name: data
   vars:
diff --git a/addons/polardbx/templates/cmpd-gms.yaml b/addons/polardbx/templates/cmpd-gms.yaml
index 0a793c46f..7defb25f0 100644
--- a/addons/polardbx/templates/cmpd-gms.yaml
+++ b/addons/polardbx/templates/cmpd-gms.yaml
@@ -38,13 +38,11 @@ spec:
   updateStrategy: Serial
   roles:
     - name: leader
-      serviceable: true
-      writable: true
-      votable: true
+      updatePriority: 2
+      participatesInQuorum: true
     - name: follower
-      serviceable: true
-      writable: false
-      votable: true
+      updatePriority: 1
+      participatesInQuorum: true
   volumes:
     - name: data
   vars:
diff --git a/addons/postgresql/templates/componentdefinition-12.yaml b/addons/postgresql/templates/componentdefinition-12.yaml
index 043bbc6b1..4493baaba 100644
--- a/addons/postgresql/templates/componentdefinition-12.yaml
+++ b/addons/postgresql/templates/componentdefinition-12.yaml
@@ -35,11 +35,11 @@ spec:
       needSnapshot: true
   roles:
     - name: primary
-      serviceable: true
-      writable: true
+      updatePriority: 2
+      participatesInQuorum: false
     - name: secondary
-      serviceable: false
-      writable: false
+      updatePriority: 1
+      participatesInQuorum: false
   logConfigs:
     {{- range $name,$pattern := .Values.logConfigs }}
     - name: {{ $name }}
diff --git a/addons/postgresql/templates/componentdefinition-14.yaml b/addons/postgresql/templates/componentdefinition-14.yaml
index 5c8841ed0..ede42ee40 100644
--- a/addons/postgresql/templates/componentdefinition-14.yaml
+++ b/addons/postgresql/templates/componentdefinition-14.yaml
@@ -35,11 +35,11 @@ spec:
       needSnapshot: true
   roles:
     - name: primary
-      serviceable: true
-      writable: true
+      updatePriority: 2
+      participatesInQuorum: false
     - name: secondary
-      serviceable: false
-      writable: false
+      updatePriority: 1
+      participatesInQuorum: false
   logConfigs:
     {{- range $name,$pattern := .Values.logConfigs }}
     - name: {{ $name }}
diff --git a/addons/postgresql/templates/componentdefinition-15.yaml b/addons/postgresql/templates/componentdefinition-15.yaml
index 882953809..287761828 100644
--- a/addons/postgresql/templates/componentdefinition-15.yaml
+++ b/addons/postgresql/templates/componentdefinition-15.yaml
@@ -35,11 +35,11 @@ spec:
       needSnapshot: true
   roles:
     - name: primary
-      serviceable: true
-      writable: true
+      updatePriority: 2
+      participatesInQuorum: false
     - name: secondary
-      serviceable: false
-      writable: false
+      updatePriority: 1
+      participatesInQuorum: false
   logConfigs:
     {{- range $name,$pattern := .Values.logConfigs }}
     - name: {{ $name }}
diff --git a/addons/postgresql/templates/componentdefinition-16.yaml b/addons/postgresql/templates/componentdefinition-16.yaml
index 9a9a15d97..96148b3f3 100644
--- a/addons/postgresql/templates/componentdefinition-16.yaml
+++ b/addons/postgresql/templates/componentdefinition-16.yaml
@@ -35,11 +35,11 @@ spec:
       needSnapshot: true
   roles:
     - name: primary
-      serviceable: true
-      writable: true
+      updatePriority: 2
+      participatesInQuorum: false
     - name: secondary
-      serviceable: false
-      writable: false
+      updatePriority: 1
+      participatesInQuorum: false
   logConfigs:
     {{- range $name,$pattern := .Values.logConfigs }}
     - name: {{ $name }}
diff --git a/addons/redis/templates/cmpd-redis-7.yaml b/addons/redis/templates/cmpd-redis-7.yaml
index 446c1e104..6e020ed52 100644
--- a/addons/redis/templates/cmpd-redis-7.yaml
+++ b/addons/redis/templates/cmpd-redis-7.yaml
@@ -37,11 +37,11 @@ spec:
       needSnapshot: true
   roles:
     - name: primary
-      serviceable: true
-      writable: true
+      updatePriority: 2
+      participatesInQuorum: false
     - name: secondary
-      serviceable: false
-      writable: false
+      updatePriority: 1
+      participatesInQuorum: false
   logConfigs:
     {{- range $name,$pattern := .Values.logConfigs }}
     - name: {{ $name }}
diff --git a/addons/redis/templates/cmpd-redis-cluster-7.yaml b/addons/redis/templates/cmpd-redis-cluster-7.yaml
index 5001f70d4..3500ab8cb 100644
--- a/addons/redis/templates/cmpd-redis-cluster-7.yaml
+++ b/addons/redis/templates/cmpd-redis-cluster-7.yaml
@@ -33,11 +33,11 @@ spec:
       needSnapshot: true
   roles:
     - name: primary
-      serviceable: true
-      writable: true
+      updatePriority: 2
+      participatesInQuorum: false
     - name: secondary
-      serviceable: false
-      writable: false
+      updatePriority: 1
+      participatesInQuorum: false
   logConfigs:
     {{- range $name,$pattern := .Values.logConfigs }}
     - name: {{ $name }}
diff --git a/addons/tidb/templates/componentdefinition-pd.yaml b/addons/tidb/templates/componentdefinition-pd.yaml
index cdcf11fd4..959f09702 100644
--- a/addons/tidb/templates/componentdefinition-pd.yaml
+++ b/addons/tidb/templates/componentdefinition-pd.yaml
@@ -64,13 +64,11 @@ spec:
       volumeName: config
   roles:
     - name: leader
-      serviceable: true
-      votable: true
-      writable: true
+      updatePriority: 2
+      participatesInQuorum: true
     - name: follower
-      serviceable: true
-      votable: true
-      writable: false
+      updatePriority: 1
+      participatesInQuorum: true
   lifecycleActions:
     roleProbe:
       exec:
diff --git a/addons/vanilla-postgresql/templates/_helpers.tpl b/addons/vanilla-postgresql/templates/_helpers.tpl
index 78c90b56c..3059b28d3 100644
--- a/addons/vanilla-postgresql/templates/_helpers.tpl
+++ b/addons/vanilla-postgresql/templates/_helpers.tpl
@@ -254,11 +254,11 @@ services:
     roleSelector: primary
 roles:
   - name: primary
-    serviceable: true
-    writable: true
+    updatePriority: 2
+    participatesInQuorum: false
   - name: secondary
-    serviceable: true
-    writable: false
+    updatePriority: 1
+    participatesInQuorum: false
 volumes:
   - name: data
     needSnapshot: true
diff --git a/addons/zookeeper/templates/cmpd.yaml b/addons/zookeeper/templates/cmpd.yaml
index 6d7d4ed42..2d7f2adf4 100644
--- a/addons/zookeeper/templates/cmpd.yaml
+++ b/addons/zookeeper/templates/cmpd.yaml
@@ -33,17 +33,14 @@ spec:
             port: 8080
   roles:
     - name: leader
-      serviceable: true
-      writable: true
-      votable: true
+      updatePriority: 3
+      participatesInQuorum: true
     - name: follower
-      serviceable: true
-      writable: false
-      votable: true
+      updatePriority: 2
+      participatesInQuorum: true
     - name: observer
-      serviceable: false
-      writable: false
-      votable: false
+      updatePriority: 1
+      participatesInQuorum: false
   updateStrategy: BestEffortParallel
   vars:
     - name: ZOOKEEPER_POD_FQDN_LIST