Skip to content

Commit

Permalink
Merge pull request #143 from Savostov-Arseny/cross-project-snapshots
Browse files Browse the repository at this point in the history
feat: Add cross-project backup and restore support
  • Loading branch information
blackpiglet authored Jul 21, 2023
2 parents b8f6436 + 3ad94c5 commit 817c494
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelogs/unreleased/143-Savostov-Arseny
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 5 additions & 6 deletions velero-plugin-for-gcp/volume_snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,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
Expand Down Expand Up @@ -300,13 +297,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)
}
Expand All @@ -323,13 +321,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)
}
Expand Down

0 comments on commit 817c494

Please sign in to comment.