From 19616c8c57682c061c7162ca4b4888be524ea258 Mon Sep 17 00:00:00 2001 From: Ye Cao Date: Tue, 30 May 2023 13:48:18 +0800 Subject: [PATCH] Replace the limits with the objectIDs in the backup and recover of vineyard cluster. (#1402) As titled. The `objectIDs` is more meaningful for users. Fixes #1322 Signed-off-by: Ye Cao --- .../templates/backup-crd.yaml | 6 ++-- docs/notes/cloud-native/vineyard-operator.rst | 8 ++--- k8s/apis/k8s/v1alpha1/backup_types.go | 5 +-- k8s/cmd/README.md | 34 ++++++++++++------- k8s/cmd/commands/deploy/deploy_backup_job.go | 31 +++++++++++------ k8s/cmd/commands/flags/backup_flags.go | 4 +-- k8s/config/crd/bases/k8s.v6d.io_backups.yaml | 6 ++-- k8s/controllers/k8s/backup_controller.go | 8 +++-- k8s/pkg/templates/backup/job.yaml | 6 ++-- .../deploy-raw-backup-and-recover/e2e.yaml | 2 +- k8s/test/e2e/failover-demo/backup.py | 28 ++++++++++----- k8s/test/e2e/failover-demo/backup.yaml | 1 - k8s/test/e2e/failover/e2e.yaml | 4 +-- 13 files changed, 91 insertions(+), 52 deletions(-) diff --git a/charts/vineyard-operator/templates/backup-crd.yaml b/charts/vineyard-operator/templates/backup-crd.yaml index abe01e7367..bec0c5d2d8 100644 --- a/charts/vineyard-operator/templates/backup-crd.yaml +++ b/charts/vineyard-operator/templates/backup-crd.yaml @@ -45,8 +45,10 @@ spec: properties: backupPath: type: string - limit: - type: integer + objecIDs: + items: + type: string + type: array persistentVolumeClaimSpec: properties: accessModes: diff --git a/docs/notes/cloud-native/vineyard-operator.rst b/docs/notes/cloud-native/vineyard-operator.rst index 3603eb362b..8a73d361b0 100644 --- a/docs/notes/cloud-native/vineyard-operator.rst +++ b/docs/notes/cloud-native/vineyard-operator.rst @@ -1741,9 +1741,10 @@ the vineyard operator. The main fields are described as follows. - The namespace of vineyardd cluster. - nil - * - limit - - int - - The number of objects to be backed up + * - objectIDs + - []string + - The object IDs that need to be backed up. + If it is empty, all objects will be backed up. - nil * - backupPath @@ -1806,7 +1807,6 @@ up the data. The following is the yaml file of the backup: spec: vineyarddName: vineyardd-sample vineyarddNamespace: vineyard-system - limit: 1000 backupPath: /var/vineyard/dump persistentVolumeSpec: storageClassName: manual diff --git a/k8s/apis/k8s/v1alpha1/backup_types.go b/k8s/apis/k8s/v1alpha1/backup_types.go index 2e575322bf..ee6dacbe33 100644 --- a/k8s/apis/k8s/v1alpha1/backup_types.go +++ b/k8s/apis/k8s/v1alpha1/backup_types.go @@ -31,9 +31,10 @@ type BackupSpec struct { // +kubebuilder:validation:Required VineyarddNamespace string `json:"vineyarddNamespace,omitempty"` - // the number of objects to be backed up + // the specific objects to be backed up + // if not specified, all objects will be backed up // +kubebuilder:validation:Required - Limit int `json:"limit,omitempty"` + ObjectIDs []string `json:"objecIDs,omitempty"` // the path of backup data // +kubebuilder:validation:Required diff --git a/k8s/cmd/README.md b/k8s/cmd/README.md index 237275086b..d00d871f07 100644 --- a/k8s/cmd/README.md +++ b/k8s/cmd/README.md @@ -165,7 +165,7 @@ vineyardctl create backup [flags] ``` --backup-name string the name of backup job (default "vineyard-backup") -h, --help help for backup - --limit int the limit of objects to backup (default 1000) + --objectIDs strings the specific objects to be backed up --path string the path of the backup data --pv-pvc-spec string the PersistentVolume and PersistentVolumeClaim of the backup data --vineyardd-name string the name of vineyardd @@ -594,12 +594,12 @@ vineyardctl deploy backup-job [flags] ### Examples ```shell - # deploy a backup job for the vineyard cluster on kubernetes - # you could define the pv and pvc spec from json string as follows + # deploy a backup job for all vineyard objects of the vineyard + # cluster on kubernetes and you could define the pv and pvc + # spec from json string as follows vineyardctl deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 \ --path /var/vineyard/dump \ --pv-pvc-spec '{ "pv-spec": { @@ -632,7 +632,7 @@ vineyardctl deploy backup-job [flags] vineyardctl deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 --path /var/vineyard/dump \ + --path /var/vineyard/dump \ --pv-pvc-spec \ ' pv-spec: @@ -652,21 +652,31 @@ vineyardctl deploy backup-job [flags] storage: 1Gi ' - # deploy a backup job for the vineyard cluster on kubernetes - # you could define the pv and pvc spec from json file as follows - # also you could use yaml file instead of json file + # deploy a backup job for specific vineyard objects of the vineyard + # cluster on kubernetes. cat pv-pvc.json | vineyardctl deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 --path /var/vineyard/dump \ - - + --objectIDs "o000018d29207fd01,o000018d80d264010" \ + --path /var/vineyard/dump # Assume you have already deployed a pvc named "pvc-sample", you # could use them as the backend storage for the backup job as follows vineyardctl deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 --path /var/vineyard/dump \ + --path /var/vineyard/dump \ + --pvc-name pvc-sample + + # The namespace to deploy the backup and recover job must be the same + # as the vineyard cluster namespace. + # Assume the vineyard cluster is deployed in the namespace "test", you + # could deploy the backup job as follows + vineyardctl deploy backup-job \ + --vineyard-deployment-name vineyardd-sample \ + --vineyard-deployment-namespace test \ + --namespace test \ + --path /var/vineyard/dump \ --pvc-name pvc-sample ``` @@ -675,7 +685,7 @@ vineyardctl deploy backup-job [flags] ``` --backup-name string the name of backup job (default "vineyard-backup") -h, --help help for backup-job - --limit int the limit of objects to backup (default 1000) + --objectIDs strings the specific objects to be backed up --path string the path of the backup data --pv-pvc-spec string the PersistentVolume and PersistentVolumeClaim of the backup data --pvc-name string the name of an existing PersistentVolumeClaim diff --git a/k8s/cmd/commands/deploy/deploy_backup_job.go b/k8s/cmd/commands/deploy/deploy_backup_job.go index 58ae771479..3501514cde 100644 --- a/k8s/cmd/commands/deploy/deploy_backup_job.go +++ b/k8s/cmd/commands/deploy/deploy_backup_job.go @@ -41,12 +41,12 @@ var ( Also, you could also specify the existing pv and pvc name to use`) deployBackupJobExample = util.Examples(` - # deploy a backup job for the vineyard cluster on kubernetes - # you could define the pv and pvc spec from json string as follows + # deploy a backup job for all vineyard objects of the vineyard + # cluster on kubernetes and you could define the pv and pvc + # spec from json string as follows vineyardctl deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 \ --path /var/vineyard/dump \ --pv-pvc-spec '{ "pv-spec": { @@ -79,7 +79,7 @@ var ( vineyardctl deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 --path /var/vineyard/dump \ + --path /var/vineyard/dump \ --pv-pvc-spec \ ' pv-spec: @@ -99,23 +99,32 @@ var ( storage: 1Gi ' - # deploy a backup job for the vineyard cluster on kubernetes - # you could define the pv and pvc spec from json file as follows - # also you could use yaml file instead of json file + # deploy a backup job for specific vineyard objects of the vineyard + # cluster on kubernetes. cat pv-pvc.json | vineyardctl deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 --path /var/vineyard/dump \ - - + --objectIDs "o000018d29207fd01,o000018d80d264010" \ + --path /var/vineyard/dump # Assume you have already deployed a pvc named "pvc-sample", you # could use them as the backend storage for the backup job as follows vineyardctl deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 --path /var/vineyard/dump \ + --path /var/vineyard/dump \ --pvc-name pvc-sample - `) + + # The namespace to deploy the backup and recover job must be the same + # as the vineyard cluster namespace. + # Assume the vineyard cluster is deployed in the namespace "test", you + # could deploy the backup job as follows + vineyardctl deploy backup-job \ + --vineyard-deployment-name vineyardd-sample \ + --vineyard-deployment-namespace test \ + --namespace test \ + --path /var/vineyard/dump \ + --pvc-name pvc-sample`) ) // deployBackupJobCmd deploy the backup job of vineyard cluster on kubernetes diff --git a/k8s/cmd/commands/flags/backup_flags.go b/k8s/cmd/commands/flags/backup_flags.go index 3fae9ef7d9..35e3f46249 100644 --- a/k8s/cmd/commands/flags/backup_flags.go +++ b/k8s/cmd/commands/flags/backup_flags.go @@ -50,8 +50,8 @@ func ApplyBackupNameOpts(cmd *cobra.Command) { func ApplyBackupCommonOpts(cmd *cobra.Command) { cmd.Flags(). - IntVarP(&BackupOpts.Limit, "limit", "", 1000, - "the limit of objects to backup") + StringSliceVarP(&BackupOpts.ObjectIDs, "objectIDs", "", []string{}, + "the specific objects to be backed up") cmd.Flags(). StringVarP(&BackupOpts.BackupPath, "path", "", "", "the path of the backup data") diff --git a/k8s/config/crd/bases/k8s.v6d.io_backups.yaml b/k8s/config/crd/bases/k8s.v6d.io_backups.yaml index 32d422bce2..8e5143ae26 100644 --- a/k8s/config/crd/bases/k8s.v6d.io_backups.yaml +++ b/k8s/config/crd/bases/k8s.v6d.io_backups.yaml @@ -33,8 +33,10 @@ spec: properties: backupPath: type: string - limit: - type: integer + objecIDs: + items: + type: string + type: array persistentVolumeClaimSpec: properties: accessModes: diff --git a/k8s/controllers/k8s/backup_controller.go b/k8s/controllers/k8s/backup_controller.go index 25579e954f..807b54d2d9 100644 --- a/k8s/controllers/k8s/backup_controller.go +++ b/k8s/controllers/k8s/backup_controller.go @@ -19,6 +19,7 @@ package k8s import ( "context" "strconv" + "strings" "time" "github.com/pkg/errors" @@ -54,8 +55,8 @@ type FailoverConfig struct { // BackupConfig holds all configuration about backup type BackupConfig struct { - Name string - Limit string + Name string + ObjectIDs string FailoverConfig } @@ -246,7 +247,8 @@ func BuildBackupCfg(c client.Client, name string, backup *k8sv1alpha1.Backup, path string, withScheduler bool) (BackupConfig, error) { backupCfg := BackupConfig{} backupCfg.Name = name - backupCfg.Limit = strconv.Itoa(backup.Spec.Limit) + backupCfg.ObjectIDs = strings.Join(backup.Spec.ObjectIDs, ",") + failoverCfg, err := newFailoverConfig(c, backup, path, withScheduler) if err != nil { return backupCfg, errors.Wrap(err, "unable to build failover config") diff --git a/k8s/pkg/templates/backup/job.yaml b/k8s/pkg/templates/backup/job.yaml index 9d224f6dd4..aa2d536bf9 100644 --- a/k8s/pkg/templates/backup/job.yaml +++ b/k8s/pkg/templates/backup/job.yaml @@ -41,8 +41,10 @@ spec: image: ghcr.io/v6d-io/v6d/backup-job imagePullPolicy: IfNotPresent env: - - name: LIMIT - value: "{{ $backupConfig.Limit }}" + {{- if $backupConfig.ObjectIDs }} + - name: ObjectIDs + value: "{{ $backupConfig.ObjectIDs }}" + {{- end }} - name: BACKUP_PATH value: {{ $failoverConfig.Path }} - name: ENDPOINT diff --git a/k8s/test/e2e/deploy-raw-backup-and-recover/e2e.yaml b/k8s/test/e2e/deploy-raw-backup-and-recover/e2e.yaml index 7f22129f09..824a9408cb 100644 --- a/k8s/test/e2e/deploy-raw-backup-and-recover/e2e.yaml +++ b/k8s/test/e2e/deploy-raw-backup-and-recover/e2e.yaml @@ -77,7 +77,7 @@ setup: go run k8s/cmd/main.go deploy backup-job \ --vineyard-deployment-name vineyardd-sample \ --vineyard-deployment-namespace vineyard-system \ - --limit 1000 \ + --objectIDs "$localobjectid,$distributedobjectid" \ --path /var/vineyard/dump \ --pv-pvc-spec '{ "pv-spec": { diff --git a/k8s/test/e2e/failover-demo/backup.py b/k8s/test/e2e/failover-demo/backup.py index 461e285623..4c69c46e05 100644 --- a/k8s/test/e2e/failover-demo/backup.py +++ b/k8s/test/e2e/failover-demo/backup.py @@ -24,7 +24,9 @@ env_dist = os.environ -limits = int(env_dist['LIMIT']) +objectids = None +if "ObjectIDs" in env_dist: + objectids = env_dist["ObjectIDs"] path = env_dist['BACKUP_PATH'] socket = '/var/run/vineyard.sock' endpoint = env_dist['ENDPOINT'] @@ -59,13 +61,23 @@ # get instance id instance = vineyard_client.instance_id -objs = vineyard_client.list_objects(pattern='*',limit=limits) +objIDs = [] +if objectids is not None: + objs = objectids.split(',') + for _,o in enumerate(objs): + objIDs.append(vineyard.ObjectID(o)) +else: + objs = vineyard_client.list_objects(pattern='*') + for _,o in enumerate(objs): + objIDs.append(o.id) + + # serialize all persistent objects -for i,o in enumerate(objs): +for _,o in enumerate(objIDs): try: - meta = vineyard_client.get_meta(o.id, sync_remote=True) + meta = vineyard_client.get_meta(o, sync_remote=True) if not meta['transient'] and meta['typename'] not in ['vineyard::ParallelStream','vineyard::StreamCollection']: - objname = str(o.id).split("\"")[1] + objname = str(o).split("\"")[1] objpath = path + '/' + objname # for local objects if not meta['global'] and meta['instance_id']==instance: @@ -74,7 +86,7 @@ os.makedirs(objpath) vineyard.io.serialize( objpath, - o.id, + o, vineyard_ipc_socket=socket, vineyard_endpoint=service, ) @@ -85,7 +97,7 @@ os.makedirs(objpath) vineyard.io.serialize( objpath, - o.id, + o, type="global", vineyard_ipc_socket=socket, vineyard_endpoint=service, @@ -93,7 +105,7 @@ hosts=hosts, ) except vineyard.ObjectNotExistsException: - print(o.id,' trigger ObjectNotExistsException') + print(o,' trigger ObjectNotExistsException') # wait other backup process ready print('Succeed',flush=True) diff --git a/k8s/test/e2e/failover-demo/backup.yaml b/k8s/test/e2e/failover-demo/backup.yaml index a7fe07985c..1ef05c041f 100644 --- a/k8s/test/e2e/failover-demo/backup.yaml +++ b/k8s/test/e2e/failover-demo/backup.yaml @@ -6,7 +6,6 @@ metadata: spec: vineyarddName: vineyardd-sample vineyarddNamespace: vineyard-system - limit: 1000 backupPath: /var/vineyard/dump persistentVolumeSpec: storageClassName: manual diff --git a/k8s/test/e2e/failover/e2e.yaml b/k8s/test/e2e/failover/e2e.yaml index 8015a0844a..bc51ed1a34 100644 --- a/k8s/test/e2e/failover/e2e.yaml +++ b/k8s/test/e2e/failover/e2e.yaml @@ -65,12 +65,12 @@ setup: - namespace: vineyard-job resource: deployment/build-distributed-object-step2 for: condition=Available - - name: install backup + - name: install backup with the specific objects command: | go run k8s/cmd/main.go create backup \ --vineyardd-name vineyardd-sample \ --vineyardd-namespace vineyard-system \ - --limit 1000 \ + --objectIDs $localobjectid,$distributedobjectid \ --path /var/vineyard/dump \ --pv-pvc-spec '{ "pv-spec": {