From 2e20c17faf83aa6d9c8f57bedaaf9d591acdb855 Mon Sep 17 00:00:00 2001 From: acekingke Date: Wed, 18 Oct 2023 16:25:20 +0800 Subject: [PATCH] *: add leader to follower choice --- api/v1alpha1/mysqlcluster_types.go | 5 +++++ api/v1beta1/mysqlcluster_types.go | 5 +++++ api/v1beta1/zz_generated.conversion.go | 2 ++ .../templates/mysql.radondb.com_mysqlclusters.yaml | 10 ++++++++++ config/crd/bases/mysql.radondb.com_mysqlclusters.yaml | 10 ++++++++++ mysqlcluster/syncer/follower_service.go | 5 ++++- 6 files changed, 36 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/mysqlcluster_types.go b/api/v1alpha1/mysqlcluster_types.go index 4d7be6c6..50ffb146 100644 --- a/api/v1alpha1/mysqlcluster_types.go +++ b/api/v1alpha1/mysqlcluster_types.go @@ -117,6 +117,11 @@ type MysqlClusterSpec struct { // Bootstraping from remote data source // +optional SourceConfig *corev1.SecretProjection `json:"sourceConfig,omitempty"` + + // Leader as follower represents if make leader use as follower to read + // +optional + // +kubebuilder:default:=false + LeaderAsFollower bool `json:"leaderAsfollower,omitempty"` } // ReadOnly define the ReadOnly pods diff --git a/api/v1beta1/mysqlcluster_types.go b/api/v1beta1/mysqlcluster_types.go index dd4576ef..5b88c887 100644 --- a/api/v1beta1/mysqlcluster_types.go +++ b/api/v1beta1/mysqlcluster_types.go @@ -149,6 +149,11 @@ type MysqlClusterSpec struct { // Specification of the service that exposes the MySQL leader instance. // +optional Service *ServiceSpec `json:"service,omitempty"` + + // Leader as follower represents if make leader use as follower to read + // +optional + // +kubebuilder:default:=false + LeaderAsFollower bool `json:"leaderAsfollower,omitempty"` } // ReadOnly define the ReadOnly pods diff --git a/api/v1beta1/zz_generated.conversion.go b/api/v1beta1/zz_generated.conversion.go index 506979ed..d5f01fcb 100644 --- a/api/v1beta1/zz_generated.conversion.go +++ b/api/v1beta1/zz_generated.conversion.go @@ -432,6 +432,7 @@ func autoConvert_v1beta1_MysqlClusterSpec_To_v1alpha1_MysqlClusterSpec(in *Mysql // WARNING: in.EnableAutoRebuild requires manual conversion: does not exist in peer-type // WARNING: in.Log requires manual conversion: does not exist in peer-type // WARNING: in.Service requires manual conversion: does not exist in peer-type + out.LeaderAsFollower = in.LeaderAsFollower return nil } @@ -455,6 +456,7 @@ func autoConvert_v1alpha1_MysqlClusterSpec_To_v1beta1_MysqlClusterSpec(in *v1alp // WARNING: in.BackupScheduleJobsHistoryLimit requires manual conversion: does not exist in peer-type // WARNING: in.TlsSecretName requires manual conversion: does not exist in peer-type // WARNING: in.SourceConfig requires manual conversion: does not exist in peer-type + out.LeaderAsFollower = in.LeaderAsFollower return nil } diff --git a/charts/mysql-operator/templates/mysql.radondb.com_mysqlclusters.yaml b/charts/mysql-operator/templates/mysql.radondb.com_mysqlclusters.yaml index 4da8fd8e..d33b4f89 100644 --- a/charts/mysql-operator/templates/mysql.radondb.com_mysqlclusters.yaml +++ b/charts/mysql-operator/templates/mysql.radondb.com_mysqlclusters.yaml @@ -101,6 +101,11 @@ spec: description: Lagged format: int32 type: integer + leaderAsfollower: + default: false + description: Leader as follower represents if make leader use as follower + to read + type: boolean metricsOpts: default: enabled: false @@ -3598,6 +3603,11 @@ spec: description: Lagged format: int32 type: integer + leaderAsfollower: + default: false + description: Leader as follower represents if make leader use as follower + to read + type: boolean logOpts: description: LogOpts is the options of log settings. properties: diff --git a/config/crd/bases/mysql.radondb.com_mysqlclusters.yaml b/config/crd/bases/mysql.radondb.com_mysqlclusters.yaml index 40d731dd..fdbbdd2f 100644 --- a/config/crd/bases/mysql.radondb.com_mysqlclusters.yaml +++ b/config/crd/bases/mysql.radondb.com_mysqlclusters.yaml @@ -83,6 +83,11 @@ spec: description: Lagged format: int32 type: integer + leaderAsfollower: + default: false + description: Leader as follower represents if make leader use as follower + to read + type: boolean metricsOpts: default: enabled: false @@ -3580,6 +3585,11 @@ spec: description: Lagged format: int32 type: integer + leaderAsfollower: + default: false + description: Leader as follower represents if make leader use as follower + to read + type: boolean logOpts: description: LogOpts is the options of log settings. properties: diff --git a/mysqlcluster/syncer/follower_service.go b/mysqlcluster/syncer/follower_service.go index b2f9f3d2..7f965456 100644 --- a/mysqlcluster/syncer/follower_service.go +++ b/mysqlcluster/syncer/follower_service.go @@ -48,7 +48,10 @@ func NewFollowerSVCSyncer(cli client.Client, c *mysqlcluster.MysqlCluster) synce service.Spec.Type = "ClusterIP" } service.Spec.Selector = c.GetSelectorLabels() - service.Spec.Selector["role"] = string(utils.Follower) + + if !c.Spec.LeaderAsFollower { + service.Spec.Selector["role"] = string(utils.Follower) + } service.Spec.Selector["healthy"] = "yes" if len(service.Spec.Ports) != 2 {