From 0afe5ca6842640da3e8ee64be229f8bce6e44573 Mon Sep 17 00:00:00 2001 From: Sebastian Glab Date: Wed, 5 Jul 2023 12:19:32 +0200 Subject: [PATCH 1/3] Do not attempt to create snapshots if the quota is reached Signed-off-by: Sebastian Glab --- velero-plugin-for-gcp/volume_snapshotter.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/velero-plugin-for-gcp/volume_snapshotter.go b/velero-plugin-for-gcp/volume_snapshotter.go index e186d6f8..cbe89c18 100644 --- a/velero-plugin-for-gcp/volume_snapshotter.go +++ b/velero-plugin-for-gcp/volume_snapshotter.go @@ -249,6 +249,24 @@ func (b *VolumeSnapshotter) CreateSnapshot(volumeID, volumeAZ string, tags map[s } suffix := "-" + uid.String() + // List all project quotas and check the "SNAPSHOTS" quota. + // If the limit is reached, return an error, so that snapshot + // won't get created. + p, err := b.gce.Projects.Get(b.volumeProject).Do() + if err != nil { + return "", errors.WithStack(err) + } + + for _, quota := range p.Quotas { + if quota.Metric == "SNAPSHOTS" { + if quota.Usage == quota.Limit { + err := fmt.Errorf("snapshots quota on Google Cloud Platform has been reached") + return "", errors.WithStack(err) + } + break + } + } + if len(volumeID) <= (63 - len(suffix)) { snapshotName = volumeID + suffix } else { From ed2948b7c63ba26112e5f34906d51fbdf5abf8d5 Mon Sep 17 00:00:00 2001 From: Sebastian Glab Date: Wed, 5 Jul 2023 12:30:07 +0200 Subject: [PATCH 2/3] Add changelogs/unreleased/144-0x113 Signed-off-by: Sebastian Glab --- changelogs/unreleased/144-0x113 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/unreleased/144-0x113 diff --git a/changelogs/unreleased/144-0x113 b/changelogs/unreleased/144-0x113 new file mode 100644 index 00000000..75252795 --- /dev/null +++ b/changelogs/unreleased/144-0x113 @@ -0,0 +1,2 @@ +Check the "SNAPSHOTS" quota on Google Cloud Platform and do not attempt to create snapshots if the quota is reached. + From e69488e1155fc21f2ec55d4297ea33b1d3345e09 Mon Sep 17 00:00:00 2001 From: Sebastian Glab Date: Wed, 5 Jul 2023 12:40:02 +0200 Subject: [PATCH 3/3] Update required Custom Role Permissions Signed-off-by: Sebastian Glab --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6c794400..c84e0bc0 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ These permissions are required by Velero to manage snapshot resources in the GCP compute.disks.get compute.disks.create compute.disks.createSnapshot + compute.projects.get compute.snapshots.get compute.snapshots.create compute.snapshots.useReadOnly