Skip to content

Commit

Permalink
Add remote replica api (#1056)
Browse files Browse the repository at this point in the history
Signed-off-by: Mehedi Hasan <[email protected]>
  • Loading branch information
heheh13 authored Sep 29, 2023
1 parent a4ea74a commit a42d651
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 77 deletions.
4 changes: 2 additions & 2 deletions apis/kubedb/v1alpha2/mysql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ func (m *MySQL) IsInnoDBCluster() bool {
*m.Spec.Topology.Mode == MySQLModeInnoDBCluster
}

func (m *MySQL) IsReadReplica() bool {
func (m *MySQL) IsRemoteReplica() bool {
return m.Spec.Topology != nil &&
m.Spec.Topology.Mode != nil &&
*m.Spec.Topology.Mode == MySQLModeReadReplica
*m.Spec.Topology.Mode == MySQLModeRemoteReplica
}

func (m *MySQL) IsSemiSync() bool {
Expand Down
13 changes: 4 additions & 9 deletions apis/kubedb/v1alpha2/mysql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ const (
ResourcePluralMySQL = "mysqls"
)

// +kubebuilder:validation:Enum=GroupReplication;InnoDBCluster;ReadReplica;SemiSync
// +kubebuilder:validation:Enum=GroupReplication;InnoDBCluster;RemoteReplica;SemiSync
type MySQLMode string

const (
MySQLModeGroupReplication MySQLMode = "GroupReplication"
MySQLModeInnoDBCluster MySQLMode = "InnoDBCluster"
MySQLModeReadReplica MySQLMode = "ReadReplica"
MySQLModeRemoteReplica MySQLMode = "RemoteReplica"
MySQLModeSemiSync MySQLMode = "SemiSync"
)

Expand Down Expand Up @@ -187,10 +187,10 @@ type MySQLTopology struct {
// +optional
InnoDBCluster *MySQLInnoDBClusterSpec `json:"innoDBCluster,omitempty"`

// ReadReplica implies that the instance will be a MySQL Read Only Replica
// RemoteReplica implies that the instance will be a MySQL Read Only Replica
// and it will take reference of appbinding of the source
// +optional
ReadReplica *MySQLReadReplicaSpec `json:"readReplica,omitempty"`
RemoteReplica *RemoteReplicaSpec `json:"remoteReplica,omitempty"`
// +optional
SemiSync *SemiSyncSpec `json:"semiSync,omitempty"`
}
Expand Down Expand Up @@ -246,11 +246,6 @@ type MySQLRouterSpec struct {
PodTemplate *ofst.PodTemplateSpec `json:"podTemplate,omitempty"`
}

type MySQLReadReplicaSpec struct {
// SourceRef specifies the source object
SourceRef core.ObjectReference `json:"sourceRef" protobuf:"bytes,1,opt,name=sourceRef"`
}

type MySQLStatus struct {
// Specifies the current phase of the database
// +optional
Expand Down
68 changes: 40 additions & 28 deletions apis/kubedb/v1alpha2/openapi_generated.go

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

4 changes: 4 additions & 0 deletions apis/kubedb/v1alpha2/postgres_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,7 @@ func (m *Postgres) SetHealthCheckerDefaults() {
m.Spec.HealthChecker.FailureThreshold = pointer.Int32P(1)
}
}

func (m *Postgres) IsRemoteReplica() bool {
return m.Spec.RemoteReplica != nil
}
14 changes: 14 additions & 0 deletions apis/kubedb/v1alpha2/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ type Postgres struct {
Spec PostgresSpec `json:"spec,omitempty"`
Status PostgresStatus `json:"status,omitempty"`
}
type PostgreSQLMode string

const (
PostgreSQLModeStandAlone PostgreSQLMode = "Standalone"
PostgreSQLModeRemoteReplica PostgreSQLMode = "RemoteReplica"
PostgreSQLModeCluster PostgreSQLMode = "Cluster"
)

type PostgresSpec struct {
// AutoOps contains configuration of automatic ops-request-recommendation generation
Expand All @@ -67,6 +74,13 @@ type PostgresSpec struct {
// Streaming mode
StreamingMode *PostgresStreamingMode `json:"streamingMode,omitempty"`

// + optional
Mode *PostgreSQLMode `json:"mode,omitempty"`
// RemoteReplica implies that the instance will be a MySQL Read Only Replica,
// and it will take reference of appbinding of the source
// +optional
RemoteReplica *RemoteReplicaSpec `json:"remoteReplica,omitempty"`

// Leader election configuration
// +optional
LeaderElection *PostgreLeaderElectionConfig `json:"leaderElection,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions apis/kubedb/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ type GitRepo struct {
AuthSecret *core.LocalObjectReference `json:"authSecret,omitempty"`
}

type RemoteReplicaSpec struct {
// SourceRef specifies the source object
SourceRef core.ObjectReference `json:"sourceRef" protobuf:"bytes,1,opt,name=sourceRef"`
}

// +kubebuilder:validation:Enum=Provisioning;DataRestoring;Ready;Critical;NotReady;Halted;Unknown
type DatabasePhase string

Expand Down
50 changes: 30 additions & 20 deletions apis/kubedb/v1alpha2/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions crds/kubedb.com_mysqls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6322,10 +6322,10 @@ spec:
enum:
- GroupReplication
- InnoDBCluster
- ReadReplica
- RemoteReplica
- SemiSync
type: string
readReplica:
remoteReplica:
properties:
sourceRef:
properties:
Expand Down
25 changes: 25 additions & 0 deletions crds/kubedb.com_postgreses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,8 @@ spec:
default: 60s
type: string
type: object
mode:
type: string
monitor:
properties:
agent:
Expand Down Expand Up @@ -3662,6 +3664,29 @@ spec:
type: array
type: object
type: object
remoteReplica:
properties:
sourceRef:
properties:
apiVersion:
type: string
fieldPath:
type: string
kind:
type: string
name:
type: string
namespace:
type: string
resourceVersion:
type: string
uid:
type: string
type: object
x-kubernetes-map-type: atomic
required:
- sourceRef
type: object
replicas:
format: int32
type: integer
Expand Down
Loading

0 comments on commit a42d651

Please sign in to comment.