From 6e15faf3cbf84ba1b242e752d2a8d9215ed53bf9 Mon Sep 17 00:00:00 2001 From: Arseny Savostov Date: Thu, 29 Jun 2023 18:39:55 -0600 Subject: [PATCH 1/2] feat: Add cross-project backup and restore support This commit introduces cross-project backup and restore functionality in the Velero GCP Plugin. The main changes include: - Replaced `compute.Disks.CreateSnapshot` with `compute.Snapshots.insert` to enable cross-project snapshots. - Configured the `volumeProject` to use the project from the provided GCP credentials and `snapshotProject` to use the project from the plugin configuration. Signed-off-by: Arseny Savostov --- velero-plugin-for-gcp/volume_snapshotter.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/velero-plugin-for-gcp/volume_snapshotter.go b/velero-plugin-for-gcp/volume_snapshotter.go index e186d6f8..9a1d507f 100644 --- a/velero-plugin-for-gcp/volume_snapshotter.go +++ b/velero-plugin-for-gcp/volume_snapshotter.go @@ -98,10 +98,7 @@ func (b *VolumeSnapshotter) Init(config map[string]string) error { b.snapshotLocation = config[snapshotLocationKey] - b.volumeProject = config[projectKey] - if b.volumeProject == "" { - b.volumeProject = creds.ProjectID - } + b.volumeProject = creds.ProjectID // get snapshot project from 'project' config key if specified, // otherwise from the credentials file @@ -275,13 +272,14 @@ func (b *VolumeSnapshotter) createSnapshot(snapshotName, volumeID, volumeAZ stri gceSnap := compute.Snapshot{ Name: snapshotName, Description: getSnapshotTags(tags, disk.Description, b.log), + SourceDisk: disk.SelfLink, } if b.snapshotLocation != "" { gceSnap.StorageLocations = []string{b.snapshotLocation} } - _, err = b.gce.Disks.CreateSnapshot(b.snapshotProject, volumeAZ, volumeID, &gceSnap).Do() + _, err = b.gce.Snapshots.Insert(b.snapshotProject, &gceSnap).Do() if err != nil { return "", errors.WithStack(err) } @@ -298,13 +296,14 @@ func (b *VolumeSnapshotter) createRegionSnapshot(snapshotName, volumeID, volumeR gceSnap := compute.Snapshot{ Name: snapshotName, Description: getSnapshotTags(tags, disk.Description, b.log), + SourceDisk: disk.SelfLink, } if b.snapshotLocation != "" { gceSnap.StorageLocations = []string{b.snapshotLocation} } - _, err = b.gce.RegionDisks.CreateSnapshot(b.snapshotProject, volumeRegion, volumeID, &gceSnap).Do() + _, err = b.gce.Snapshots.Insert(b.snapshotProject, &gceSnap).Do() if err != nil { return "", errors.WithStack(err) } From 3ad94c54bee32f9eb1466ae685f0cedad32f3b2f Mon Sep 17 00:00:00 2001 From: Arseny Savostov Date: Thu, 29 Jun 2023 19:09:31 -0600 Subject: [PATCH 2/2] Add changelogs/unreleased/143-Savostov-Arseny Signed-off-by: Arseny Savostov --- changelogs/unreleased/143-Savostov-Arseny | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/143-Savostov-Arseny diff --git a/changelogs/unreleased/143-Savostov-Arseny b/changelogs/unreleased/143-Savostov-Arseny new file mode 100644 index 00000000..1c15ab09 --- /dev/null +++ b/changelogs/unreleased/143-Savostov-Arseny @@ -0,0 +1,5 @@ +Add cross-project backup and restore functionality in the Velero GCP Plugin. + +The main changes include: +Replaced compute.Disks.CreateSnapshot with compute.Snapshots.insert to enable cross-project snapshots. +Configured the volumeProject to use the project from the provided GCP credentials and snapshotProject to use the project from the plugin configuration. \ No newline at end of file