From 90dd367e0d38626dea0ae8a40111e5161eec8744 Mon Sep 17 00:00:00 2001 From: Ashraful Haque Tani <48568933+AshrafulHaqueToni@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:24:42 +0600 Subject: [PATCH] add remote to group replication ops request (#1359) Signed-off-by: Ashraful Haque Tani --- apis/ops/v1alpha1/constant.go | 6 +- apis/ops/v1alpha1/mysql_ops_types.go | 23 ++++- apis/ops/v1alpha1/mysql_ops_types_enum.go | 21 ++-- apis/ops/v1alpha1/openapi_generated.go | 58 ++++++++++- apis/ops/v1alpha1/zz_generated.deepcopy.go | 33 ++++++ crds/ops.kubedb.com_mysqlopsrequests.yaml | 112 +++++++++++++++++++++ openapi/swagger.json | 32 ++++++ 7 files changed, 273 insertions(+), 12 deletions(-) diff --git a/apis/ops/v1alpha1/constant.go b/apis/ops/v1alpha1/constant.go index a4111852c9..5294fbc0df 100644 --- a/apis/ops/v1alpha1/constant.go +++ b/apis/ops/v1alpha1/constant.go @@ -284,7 +284,11 @@ const ( // MySQL/MariaDB Constants const ( - TempIniFilesPath = "/tmp/kubedb-custom-ini-files" + TempIniFilesPath = "/tmp/kubedb-custom-ini-files" + StopRemoteReplica = "StopRemoteReplica" + DBPatch = "DBPatch" + StopRemoteReplicaSucceeded = "StopRemoteReplicaSucceeded" + DBPatchSucceeded = "DBPatchSucceeded" ) // Postgres Constants diff --git a/apis/ops/v1alpha1/mysql_ops_types.go b/apis/ops/v1alpha1/mysql_ops_types.go index ddc4d0815a..30c4d322fe 100644 --- a/apis/ops/v1alpha1/mysql_ops_types.go +++ b/apis/ops/v1alpha1/mysql_ops_types.go @@ -18,9 +18,12 @@ limitations under the License. package v1alpha1 import ( + dbapi "kubedb.dev/apimachinery/apis/kubedb/v1" + core "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmapi "kmodules.xyz/client-go/api/v1" ) const ( @@ -69,6 +72,8 @@ type MySQLOpsRequestSpec struct { TLS *MySQLTLSSpec `json:"tls,omitempty"` // Specifies information necessary for configuring authSecret of the database Authentication *AuthSpec `json:"authentication,omitempty"` + // Specifies information transform Remote Replica to GroupReplication + ReplicationModeTransformation *MySQLReplicationModeTransformSpec `json:"replicationModeTransformation,omitempty"` // Specifies information necessary for restarting database Restart *RestartSpec `json:"restart,omitempty"` // Timeout for each step of the ops request in second. If a step doesn't finish within the specified timeout, the ops request will result in failure. @@ -78,8 +83,8 @@ type MySQLOpsRequestSpec struct { Apply ApplyOption `json:"apply,omitempty"` } -// +kubebuilder:validation:Enum=Upgrade;UpdateVersion;HorizontalScaling;VerticalScaling;VolumeExpansion;Restart;Reconfigure;ReconfigureTLS;RotateAuth -// ENUM(UpdateVersion, HorizontalScaling, VerticalScaling, VolumeExpansion, Restart, Reconfigure, ReconfigureTLS, RotateAuth) +// +kubebuilder:validation:Enum=Upgrade;UpdateVersion;HorizontalScaling;VerticalScaling;VolumeExpansion;Restart;Reconfigure;ReconfigureTLS;RotateAuth;ReplicationModeTransformation +// ENUM(UpdateVersion, HorizontalScaling, VerticalScaling, VolumeExpansion, Restart, Reconfigure, ReconfigureTLS, RotateAuth, ReplicationModeTransformation) type MySQLOpsRequestType string // MySQLReplicaReadinessCriteria is the criteria for checking readiness of a MySQL pod @@ -97,6 +102,20 @@ type MySQLHorizontalScalingSpec struct { Member *int32 `json:"member,omitempty"` } +type MySQLReplicationModeTransformSpec struct { + // Group Replication can be deployed in either "Single-Primary" or "Multi-Primary" mode + // +kubebuilder:default=Single-Primary + Mode *dbapi.MySQLGroupMode `json:"mode"` + + // TLSConfig contains updated tls configurations for client and server. + // +optional + kmapi.TLSConfig `json:",inline,omitempty"` + + // Indicates that the database server need to be encrypted connections(ssl) + // +optional + RequireSSL *bool `json:"requireSSL,omitempty"` +} + type MySQLVerticalScalingSpec struct { MySQL *PodResources `json:"mysql,omitempty"` Exporter *ContainerResources `json:"exporter,omitempty"` diff --git a/apis/ops/v1alpha1/mysql_ops_types_enum.go b/apis/ops/v1alpha1/mysql_ops_types_enum.go index 3e48bdf231..48ff879476 100644 --- a/apis/ops/v1alpha1/mysql_ops_types_enum.go +++ b/apis/ops/v1alpha1/mysql_ops_types_enum.go @@ -28,6 +28,8 @@ const ( MySQLOpsRequestTypeReconfigureTLS MySQLOpsRequestType = "ReconfigureTLS" // MySQLOpsRequestTypeRotateAuth is a MySQLOpsRequestType of type RotateAuth. MySQLOpsRequestTypeRotateAuth MySQLOpsRequestType = "RotateAuth" + // MySQLOpsRequestTypeReplicationModeTransformation is a MySQLOpsRequestType of type ReplicationModeTransformation. + MySQLOpsRequestTypeReplicationModeTransformation MySQLOpsRequestType = "ReplicationModeTransformation" ) var ErrInvalidMySQLOpsRequestType = fmt.Errorf("not a valid MySQLOpsRequestType, try [%s]", strings.Join(_MySQLOpsRequestTypeNames, ", ")) @@ -41,6 +43,7 @@ var _MySQLOpsRequestTypeNames = []string{ string(MySQLOpsRequestTypeReconfigure), string(MySQLOpsRequestTypeReconfigureTLS), string(MySQLOpsRequestTypeRotateAuth), + string(MySQLOpsRequestTypeReplicationModeTransformation), } // MySQLOpsRequestTypeNames returns a list of possible string values of MySQLOpsRequestType. @@ -61,6 +64,7 @@ func MySQLOpsRequestTypeValues() []MySQLOpsRequestType { MySQLOpsRequestTypeReconfigure, MySQLOpsRequestTypeReconfigureTLS, MySQLOpsRequestTypeRotateAuth, + MySQLOpsRequestTypeReplicationModeTransformation, } } @@ -77,14 +81,15 @@ func (x MySQLOpsRequestType) IsValid() bool { } var _MySQLOpsRequestTypeValue = map[string]MySQLOpsRequestType{ - "UpdateVersion": MySQLOpsRequestTypeUpdateVersion, - "HorizontalScaling": MySQLOpsRequestTypeHorizontalScaling, - "VerticalScaling": MySQLOpsRequestTypeVerticalScaling, - "VolumeExpansion": MySQLOpsRequestTypeVolumeExpansion, - "Restart": MySQLOpsRequestTypeRestart, - "Reconfigure": MySQLOpsRequestTypeReconfigure, - "ReconfigureTLS": MySQLOpsRequestTypeReconfigureTLS, - "RotateAuth": MySQLOpsRequestTypeRotateAuth, + "UpdateVersion": MySQLOpsRequestTypeUpdateVersion, + "HorizontalScaling": MySQLOpsRequestTypeHorizontalScaling, + "VerticalScaling": MySQLOpsRequestTypeVerticalScaling, + "VolumeExpansion": MySQLOpsRequestTypeVolumeExpansion, + "Restart": MySQLOpsRequestTypeRestart, + "Reconfigure": MySQLOpsRequestTypeReconfigure, + "ReconfigureTLS": MySQLOpsRequestTypeReconfigureTLS, + "RotateAuth": MySQLOpsRequestTypeRotateAuth, + "ReplicationModeTransformation": MySQLOpsRequestTypeReplicationModeTransformation, } // ParseMySQLOpsRequestType attempts to convert a string to a MySQLOpsRequestType. diff --git a/apis/ops/v1alpha1/openapi_generated.go b/apis/ops/v1alpha1/openapi_generated.go index 3a93065fc5..4416bbab55 100644 --- a/apis/ops/v1alpha1/openapi_generated.go +++ b/apis/ops/v1alpha1/openapi_generated.go @@ -598,6 +598,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLOpsRequestSpec": schema_apimachinery_apis_ops_v1alpha1_MySQLOpsRequestSpec(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLQueryRules": schema_apimachinery_apis_ops_v1alpha1_MySQLQueryRules(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLReplicaReadinessCriteria": schema_apimachinery_apis_ops_v1alpha1_MySQLReplicaReadinessCriteria(ref), + "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLReplicationModeTransformSpec": schema_apimachinery_apis_ops_v1alpha1_MySQLReplicationModeTransformSpec(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLTLSSpec": schema_apimachinery_apis_ops_v1alpha1_MySQLTLSSpec(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLUpdateVersionSpec": schema_apimachinery_apis_ops_v1alpha1_MySQLUpdateVersionSpec(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLUsers": schema_apimachinery_apis_ops_v1alpha1_MySQLUsers(ref), @@ -29803,6 +29804,12 @@ func schema_apimachinery_apis_ops_v1alpha1_MySQLOpsRequestSpec(ref common.Refere Ref: ref("kubedb.dev/apimachinery/apis/ops/v1alpha1.AuthSpec"), }, }, + "replicationModeTransformation": { + SchemaProps: spec.SchemaProps{ + Description: "Specifies information transform Remote Replica to GroupReplication", + Ref: ref("kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLReplicationModeTransformSpec"), + }, + }, "restart": { SchemaProps: spec.SchemaProps{ Description: "Specifies information necessary for restarting database", @@ -29827,7 +29834,7 @@ func schema_apimachinery_apis_ops_v1alpha1_MySQLOpsRequestSpec(ref common.Refere }, }, Dependencies: []string{ - "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration", "kubedb.dev/apimachinery/apis/ops/v1alpha1.AuthSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLCustomConfigurationSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLHorizontalScalingSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLTLSSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLUpdateVersionSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLVerticalScalingSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLVolumeExpansionSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.RestartSpec"}, + "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration", "kubedb.dev/apimachinery/apis/ops/v1alpha1.AuthSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLCustomConfigurationSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLHorizontalScalingSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLReplicationModeTransformSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLTLSSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLUpdateVersionSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLVerticalScalingSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.MySQLVolumeExpansionSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.RestartSpec"}, } } @@ -29876,6 +29883,55 @@ func schema_apimachinery_apis_ops_v1alpha1_MySQLReplicaReadinessCriteria(ref com } } +func schema_apimachinery_apis_ops_v1alpha1_MySQLReplicationModeTransformSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "mode": { + SchemaProps: spec.SchemaProps{ + Description: "Group Replication can be deployed in either \"Single-Primary\" or \"Multi-Primary\" mode", + Type: []string{"string"}, + Format: "", + }, + }, + "issuerRef": { + SchemaProps: spec.SchemaProps{ + Description: "IssuerRef is a reference to a Certificate Issuer.", + Ref: ref("k8s.io/api/core/v1.TypedLocalObjectReference"), + }, + }, + "certificates": { + SchemaProps: spec.SchemaProps{ + Description: "Certificate provides server and/or client certificate options used by application pods. These options are passed to a cert-manager Certificate object. xref: https://github.com/jetstack/cert-manager/blob/v0.16.0/pkg/apis/certmanager/v1beta1/types_certificate.go#L82-L162", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("kmodules.xyz/client-go/api/v1.CertificateSpec"), + }, + }, + }, + }, + }, + "requireSSL": { + SchemaProps: spec.SchemaProps{ + Description: "Indicates that the database server need to be encrypted connections(ssl)", + Type: []string{"boolean"}, + Format: "", + }, + }, + }, + Required: []string{"mode"}, + }, + }, + Dependencies: []string{ + "k8s.io/api/core/v1.TypedLocalObjectReference", "kmodules.xyz/client-go/api/v1.CertificateSpec"}, + } +} + func schema_apimachinery_apis_ops_v1alpha1_MySQLTLSSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/apis/ops/v1alpha1/zz_generated.deepcopy.go b/apis/ops/v1alpha1/zz_generated.deepcopy.go index 61a5000d8c..3e720bf224 100644 --- a/apis/ops/v1alpha1/zz_generated.deepcopy.go +++ b/apis/ops/v1alpha1/zz_generated.deepcopy.go @@ -22,6 +22,7 @@ limitations under the License. package v1alpha1 import ( + kubedbv1 "kubedb.dev/apimachinery/apis/kubedb/v1" v1alpha2 "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" v1 "k8s.io/api/core/v1" @@ -3159,6 +3160,11 @@ func (in *MySQLOpsRequestSpec) DeepCopyInto(out *MySQLOpsRequestSpec) { *out = new(AuthSpec) (*in).DeepCopyInto(*out) } + if in.ReplicationModeTransformation != nil { + in, out := &in.ReplicationModeTransformation, &out.ReplicationModeTransformation + *out = new(MySQLReplicationModeTransformSpec) + (*in).DeepCopyInto(*out) + } if in.Restart != nil { in, out := &in.Restart, &out.Restart *out = new(RestartSpec) @@ -3225,6 +3231,33 @@ func (in *MySQLReplicaReadinessCriteria) DeepCopy() *MySQLReplicaReadinessCriter return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MySQLReplicationModeTransformSpec) DeepCopyInto(out *MySQLReplicationModeTransformSpec) { + *out = *in + if in.Mode != nil { + in, out := &in.Mode, &out.Mode + *out = new(kubedbv1.MySQLGroupMode) + **out = **in + } + in.TLSConfig.DeepCopyInto(&out.TLSConfig) + if in.RequireSSL != nil { + in, out := &in.RequireSSL, &out.RequireSSL + *out = new(bool) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MySQLReplicationModeTransformSpec. +func (in *MySQLReplicationModeTransformSpec) DeepCopy() *MySQLReplicationModeTransformSpec { + if in == nil { + return nil + } + out := new(MySQLReplicationModeTransformSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MySQLTLSSpec) DeepCopyInto(out *MySQLTLSSpec) { *out = *in diff --git a/crds/ops.kubedb.com_mysqlopsrequests.yaml b/crds/ops.kubedb.com_mysqlopsrequests.yaml index e9a7207ca9..d2e463c3d4 100644 --- a/crds/ops.kubedb.com_mysqlopsrequests.yaml +++ b/crds/ops.kubedb.com_mysqlopsrequests.yaml @@ -87,6 +87,117 @@ spec: format: int32 type: integer type: object + replicationModeTransformation: + properties: + certificates: + items: + properties: + alias: + type: string + dnsNames: + items: + type: string + type: array + duration: + type: string + emailAddresses: + items: + type: string + type: array + ipAddresses: + items: + type: string + type: array + issuerRef: + properties: + apiGroup: + type: string + kind: + type: string + name: + type: string + required: + - kind + - name + type: object + x-kubernetes-map-type: atomic + privateKey: + properties: + encoding: + enum: + - PKCS1 + - PKCS8 + type: string + type: object + renewBefore: + type: string + secretName: + type: string + subject: + properties: + countries: + items: + type: string + type: array + localities: + items: + type: string + type: array + organizationalUnits: + items: + type: string + type: array + organizations: + items: + type: string + type: array + postalCodes: + items: + type: string + type: array + provinces: + items: + type: string + type: array + serialNumber: + type: string + streetAddresses: + items: + type: string + type: array + type: object + uris: + items: + type: string + type: array + required: + - alias + type: object + type: array + issuerRef: + properties: + apiGroup: + type: string + kind: + type: string + name: + type: string + required: + - kind + - name + type: object + x-kubernetes-map-type: atomic + mode: + default: Single-Primary + enum: + - Single-Primary + - Multi-Primary + type: string + requireSSL: + type: boolean + required: + - mode + type: object restart: type: object timeout: @@ -209,6 +320,7 @@ spec: - Reconfigure - ReconfigureTLS - RotateAuth + - ReplicationModeTransformation type: string updateVersion: properties: diff --git a/openapi/swagger.json b/openapi/swagger.json index 28d445336f..635c169c76 100644 --- a/openapi/swagger.json +++ b/openapi/swagger.json @@ -27337,6 +27337,10 @@ "description": "Specifies information necessary for horizontal scaling", "$ref": "#/definitions/dev.kubedb.apimachinery.apis.ops.v1alpha1.MySQLHorizontalScalingSpec" }, + "replicationModeTransformation": { + "description": "Specifies information transform Remote Replica to GroupReplication", + "$ref": "#/definitions/dev.kubedb.apimachinery.apis.ops.v1alpha1.MySQLReplicationModeTransformSpec" + }, "restart": { "description": "Specifies information necessary for restarting database", "$ref": "#/definitions/dev.kubedb.apimachinery.apis.ops.v1alpha1.RestartSpec" @@ -27391,6 +27395,34 @@ "description": "MySQLReplicaReadinessCriteria is the criteria for checking readiness of a MySQL pod after updating, horizontal scaling etc.", "type": "object" }, + "dev.kubedb.apimachinery.apis.ops.v1alpha1.MySQLReplicationModeTransformSpec": { + "type": "object", + "required": [ + "mode" + ], + "properties": { + "certificates": { + "description": "Certificate provides server and/or client certificate options used by application pods. These options are passed to a cert-manager Certificate object. xref: https://github.com/jetstack/cert-manager/blob/v0.16.0/pkg/apis/certmanager/v1beta1/types_certificate.go#L82-L162", + "type": "array", + "items": { + "default": {}, + "$ref": "#/definitions/xyz.kmodules.client-go.api.v1.CertificateSpec" + } + }, + "issuerRef": { + "description": "IssuerRef is a reference to a Certificate Issuer.", + "$ref": "#/definitions/io.k8s.api.core.v1.TypedLocalObjectReference" + }, + "mode": { + "description": "Group Replication can be deployed in either \"Single-Primary\" or \"Multi-Primary\" mode", + "type": "string" + }, + "requireSSL": { + "description": "Indicates that the database server need to be encrypted connections(ssl)", + "type": "boolean" + } + } + }, "dev.kubedb.apimachinery.apis.ops.v1alpha1.MySQLTLSSpec": { "type": "object", "properties": {