From 8330be201f33a1366b097243ad33276ab33f9f7e Mon Sep 17 00:00:00 2001 From: Daniel Hobley Date: Thu, 11 Apr 2024 11:15:46 +0200 Subject: [PATCH] feat: copy labels from Disk to Snapshot It can be very useful to be able to track your snapshots using the same labels are you have on your original disks, this PR copies over all of the labels of the disk and adds a new permission requirement of `compute.snapshots.setLabels` to allow for that. Signed-off-by: Daniel Hobley --- README.md | 1 + velero-plugin-for-gcp/volume_snapshotter.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 99f0bfb..5e68e0a 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ These permissions are required by Velero to manage snapshot resources in the GCP compute.snapshots.create compute.snapshots.useReadOnly compute.snapshots.delete + compute.snapshots.setLabels compute.zones.get storage.objects.create storage.objects.delete diff --git a/velero-plugin-for-gcp/volume_snapshotter.go b/velero-plugin-for-gcp/volume_snapshotter.go index 974259e..c7c03a0 100644 --- a/velero-plugin-for-gcp/volume_snapshotter.go +++ b/velero-plugin-for-gcp/volume_snapshotter.go @@ -210,6 +210,7 @@ func (b *VolumeSnapshotter) CreateVolumeFromSnapshot(snapshotID, volumeType, vol SourceSnapshot: res.SelfLink, Type: volumeType, Description: res.Description, + Labels: res.Labels, } if isMultiZone(volumeAZ) { @@ -318,6 +319,7 @@ func (b *VolumeSnapshotter) createSnapshot(snapshotName, volumeID, volumeAZ stri Description: getSnapshotTags(tags, disk.Description, b.log), SourceDisk: disk.SelfLink, SnapshotType: b.snapshotType, + Labels: disk.Labels, } if b.snapshotLocation != "" { @@ -343,6 +345,7 @@ func (b *VolumeSnapshotter) createRegionSnapshot(snapshotName, volumeID, volumeR Description: getSnapshotTags(tags, disk.Description, b.log), SourceDisk: disk.SelfLink, SnapshotType: b.snapshotType, + Labels: disk.Labels, } if b.snapshotLocation != "" {