Skip to content

Commit

Permalink
Replace the limits with the objectIDs in the backup and recover of vi…
Browse files Browse the repository at this point in the history
…neyard cluster. (#1402)

As titled. The `objectIDs` is more meaningful for users.

Fixes #1322

Signed-off-by: Ye Cao <[email protected]>
  • Loading branch information
dashanji authored May 30, 2023
1 parent 2c0957b commit 19616c8
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 52 deletions.
6 changes: 4 additions & 2 deletions charts/vineyard-operator/templates/backup-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ spec:
properties:
backupPath:
type: string
limit:
type: integer
objecIDs:
items:
type: string
type: array
persistentVolumeClaimSpec:
properties:
accessModes:
Expand Down
8 changes: 4 additions & 4 deletions docs/notes/cloud-native/vineyard-operator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions k8s/apis/k8s/v1alpha1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 22 additions & 12 deletions k8s/cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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:
Expand All @@ -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
```

Expand All @@ -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
Expand Down
31 changes: 20 additions & 11 deletions k8s/cmd/commands/deploy/deploy_backup_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions k8s/cmd/commands/flags/backup_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions k8s/config/crd/bases/k8s.v6d.io_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ spec:
properties:
backupPath:
type: string
limit:
type: integer
objecIDs:
items:
type: string
type: array
persistentVolumeClaimSpec:
properties:
accessModes:
Expand Down
8 changes: 5 additions & 3 deletions k8s/controllers/k8s/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package k8s
import (
"context"
"strconv"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions k8s/pkg/templates/backup/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion k8s/test/e2e/deploy-raw-backup-and-recover/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
28 changes: 20 additions & 8 deletions k8s/test/e2e/failover-demo/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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:
Expand All @@ -74,7 +86,7 @@
os.makedirs(objpath)
vineyard.io.serialize(
objpath,
o.id,
o,
vineyard_ipc_socket=socket,
vineyard_endpoint=service,
)
Expand All @@ -85,15 +97,15 @@
os.makedirs(objpath)
vineyard.io.serialize(
objpath,
o.id,
o,
type="global",
vineyard_ipc_socket=socket,
vineyard_endpoint=service,
deployment='kubernetes',
hosts=hosts,
)
except vineyard.ObjectNotExistsException:
print(o.id,' trigger ObjectNotExistsException')
print(o,' trigger ObjectNotExistsException')

# wait other backup process ready
print('Succeed',flush=True)
Expand Down
1 change: 0 additions & 1 deletion k8s/test/e2e/failover-demo/backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ metadata:
spec:
vineyarddName: vineyardd-sample
vineyarddNamespace: vineyard-system
limit: 1000
backupPath: /var/vineyard/dump
persistentVolumeSpec:
storageClassName: manual
Expand Down
4 changes: 2 additions & 2 deletions k8s/test/e2e/failover/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 19616c8

Please sign in to comment.