Skip to content

Commit

Permalink
*: add leader to follower choice
Browse files Browse the repository at this point in the history
  • Loading branch information
acekingke committed Oct 26, 2023
1 parent 62a7e0f commit 2e20c17
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/mysql.radondb.com_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion mysqlcluster/syncer/follower_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2e20c17

Please sign in to comment.