From ea1cfd256a2a4549dfff53c7d3aaf6ea02db07eb Mon Sep 17 00:00:00 2001 From: Leon Date: Thu, 28 Mar 2024 12:25:26 +0800 Subject: [PATCH] chore: refine data dump/load actions (#6820) --- .../v1alpha1/componentdefinition_types.go | 10 +-- apis/apps/v1alpha1/zz_generated.deepcopy.go | 8 +- ...ps.kubeblocks.io_componentdefinitions.yaml | 27 +++--- .../apps/componentdefinition_controller.go | 4 +- ...ps.kubeblocks.io_componentdefinitions.yaml | 27 +++--- docs/developer_docs/api-reference/cluster.md | 10 +-- pkg/constant/lorry.go | 2 + .../component_definition_convertor.go | 4 +- pkg/controller/component/lorry_utils.go | 10 +-- pkg/lorry/client/client.go | 10 +++ pkg/lorry/client/client_mock.go | 28 +++++++ pkg/lorry/client/interface.go | 3 + pkg/lorry/operations/replica/data_dump.go | 83 +++++++++++++++++++ pkg/lorry/operations/replica/data_load.go | 71 ++++++++++++++++ pkg/lorry/util/types.go | 3 + pkg/testutil/apps/constant.go | 4 +- 16 files changed, 251 insertions(+), 53 deletions(-) create mode 100644 pkg/lorry/operations/replica/data_dump.go create mode 100644 pkg/lorry/operations/replica/data_load.go diff --git a/apis/apps/v1alpha1/componentdefinition_types.go b/apis/apps/v1alpha1/componentdefinition_types.go index b9276612468..14416c1b3b3 100644 --- a/apis/apps/v1alpha1/componentdefinition_types.go +++ b/apis/apps/v1alpha1/componentdefinition_types.go @@ -789,7 +789,7 @@ type ComponentLifecycleActions struct { // +optional Readwrite *LifecycleActionHandler `json:"readwrite,omitempty"` - // Defines the method to populate the data to create new replicas. + // Defines the method to dump the data from a replica. // This action is typically used when a new replica needs to be constructed, such as: // // - scale-out @@ -800,21 +800,21 @@ type ComponentLifecycleActions struct { // This field cannot be updated. // // +optional - DataPopulate *LifecycleActionHandler `json:"dataPopulate,omitempty"` + DataDump *LifecycleActionHandler `json:"dataDump,omitempty"` - // Defines the method to assemble data synchronized from external before starting the service for a new replica. + // Defines the method to load data into a replica. // This action is typically used when creating a new replica, such as: // // - scale-out // - rebuild // - clone // - // The data will be streamed in via stdin. If any error occurs during the assembly process, + // The data will be streamed in via stdin. If any error occurs during the process, // the action must be able to guarantee idempotence to allow for retries from the beginning. // This field cannot be updated. // // +optional - DataAssemble *LifecycleActionHandler `json:"dataAssemble,omitempty"` + DataLoad *LifecycleActionHandler `json:"dataLoad,omitempty"` // Defines the method to notify the replica service that there is a configuration update. // This field cannot be updated. diff --git a/apis/apps/v1alpha1/zz_generated.deepcopy.go b/apis/apps/v1alpha1/zz_generated.deepcopy.go index fe11146171f..cfa4336bccf 100644 --- a/apis/apps/v1alpha1/zz_generated.deepcopy.go +++ b/apis/apps/v1alpha1/zz_generated.deepcopy.go @@ -1975,13 +1975,13 @@ func (in *ComponentLifecycleActions) DeepCopyInto(out *ComponentLifecycleActions *out = new(LifecycleActionHandler) (*in).DeepCopyInto(*out) } - if in.DataPopulate != nil { - in, out := &in.DataPopulate, &out.DataPopulate + if in.DataDump != nil { + in, out := &in.DataDump, &out.DataDump *out = new(LifecycleActionHandler) (*in).DeepCopyInto(*out) } - if in.DataAssemble != nil { - in, out := &in.DataAssemble, &out.DataAssemble + if in.DataLoad != nil { + in, out := &in.DataLoad, &out.DataLoad *out = new(LifecycleActionHandler) (*in).DeepCopyInto(*out) } diff --git a/config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml b/config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml index 031ad6a1718..2635d683d10 100644 --- a/config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml +++ b/config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml @@ -524,14 +524,12 @@ spec: type: integer type: object type: object - dataAssemble: - description: "Defines the method to assemble data synchronized - from external before starting the service for a new replica. - This action is typically used when creating a new replica, such - as: \n - scale-out - rebuild - clone \n The data will be streamed - in via stdin. If any error occurs during the assembly process, - the action must be able to guarantee idempotence to allow for - retries from the beginning. This field cannot be updated." + dataDump: + description: "Defines the method to dump the data from a replica. + This action is typically used when a new replica needs to be + constructed, such as: \n - scale-out - rebuild - clone \n It + should write the valid data to stdout without including any + extraneous information. This field cannot be updated." properties: builtinHandler: description: BuiltinHandler specifies the builtin action handler @@ -819,12 +817,13 @@ spec: type: integer type: object type: object - dataPopulate: - description: "Defines the method to populate the data to create - new replicas. This action is typically used when a new replica - needs to be constructed, such as: \n - scale-out - rebuild - - clone \n It should write the valid data to stdout without including - any extraneous information. This field cannot be updated." + dataLoad: + description: "Defines the method to load data into a replica. + This action is typically used when creating a new replica, such + as: \n - scale-out - rebuild - clone \n The data will be streamed + in via stdin. If any error occurs during the process, the action + must be able to guarantee idempotence to allow for retries from + the beginning. This field cannot be updated." properties: builtinHandler: description: BuiltinHandler specifies the builtin action handler diff --git a/controllers/apps/componentdefinition_controller.go b/controllers/apps/componentdefinition_controller.go index 8e87d861a48..cc286ff0a5b 100644 --- a/controllers/apps/componentdefinition_controller.go +++ b/controllers/apps/componentdefinition_controller.go @@ -357,8 +357,8 @@ func (r *ComponentDefinitionReconciler) validateLifecycleActionBuiltInHandlers(l {lifecycleActions.MemberLeave}, {lifecycleActions.Readonly}, {lifecycleActions.Readwrite}, - {lifecycleActions.DataPopulate}, - {lifecycleActions.DataAssemble}, + {lifecycleActions.DataDump}, + {lifecycleActions.DataLoad}, {lifecycleActions.Reconfigure}, {lifecycleActions.AccountProvision}, } diff --git a/deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml b/deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml index 031ad6a1718..2635d683d10 100644 --- a/deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml +++ b/deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml @@ -524,14 +524,12 @@ spec: type: integer type: object type: object - dataAssemble: - description: "Defines the method to assemble data synchronized - from external before starting the service for a new replica. - This action is typically used when creating a new replica, such - as: \n - scale-out - rebuild - clone \n The data will be streamed - in via stdin. If any error occurs during the assembly process, - the action must be able to guarantee idempotence to allow for - retries from the beginning. This field cannot be updated." + dataDump: + description: "Defines the method to dump the data from a replica. + This action is typically used when a new replica needs to be + constructed, such as: \n - scale-out - rebuild - clone \n It + should write the valid data to stdout without including any + extraneous information. This field cannot be updated." properties: builtinHandler: description: BuiltinHandler specifies the builtin action handler @@ -819,12 +817,13 @@ spec: type: integer type: object type: object - dataPopulate: - description: "Defines the method to populate the data to create - new replicas. This action is typically used when a new replica - needs to be constructed, such as: \n - scale-out - rebuild - - clone \n It should write the valid data to stdout without including - any extraneous information. This field cannot be updated." + dataLoad: + description: "Defines the method to load data into a replica. + This action is typically used when creating a new replica, such + as: \n - scale-out - rebuild - clone \n The data will be streamed + in via stdin. If any error occurs during the process, the action + must be able to guarantee idempotence to allow for retries from + the beginning. This field cannot be updated." properties: builtinHandler: description: BuiltinHandler specifies the builtin action handler diff --git a/docs/developer_docs/api-reference/cluster.md b/docs/developer_docs/api-reference/cluster.md index c32558e684c..83df35d6bc5 100644 --- a/docs/developer_docs/api-reference/cluster.md +++ b/docs/developer_docs/api-reference/cluster.md @@ -7724,7 +7724,7 @@ LifecycleActionHandler -dataPopulate
+dataDump
LifecycleActionHandler @@ -7733,7 +7733,7 @@ LifecycleActionHandler (Optional) -

Defines the method to populate the data to create new replicas. +

Defines the method to dump the data from a replica. This action is typically used when a new replica needs to be constructed, such as: