Skip to content

Commit 4a46a41

Browse files
authored
Merge pull request #144 from 0x113/SGLAB-CLOUDCASA-snapshot-limit
Do not attempt to create snapshots if the quota is reached
2 parents 4b89346 + e69488e commit 4a46a41

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ These permissions are required by Velero to manage snapshot resources in the GCP
110110
compute.disks.get
111111
compute.disks.create
112112
compute.disks.createSnapshot
113+
compute.projects.get
113114
compute.snapshots.get
114115
compute.snapshots.create
115116
compute.snapshots.useReadOnly

changelogs/unreleased/144-0x113

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Check the "SNAPSHOTS" quota on Google Cloud Platform and do not attempt to create snapshots if the quota is reached.
2+

velero-plugin-for-gcp/volume_snapshotter.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,24 @@ func (b *VolumeSnapshotter) CreateSnapshot(volumeID, volumeAZ string, tags map[s
249249
}
250250
suffix := "-" + uid.String()
251251

252+
// List all project quotas and check the "SNAPSHOTS" quota.
253+
// If the limit is reached, return an error, so that snapshot
254+
// won't get created.
255+
p, err := b.gce.Projects.Get(b.volumeProject).Do()
256+
if err != nil {
257+
return "", errors.WithStack(err)
258+
}
259+
260+
for _, quota := range p.Quotas {
261+
if quota.Metric == "SNAPSHOTS" {
262+
if quota.Usage == quota.Limit {
263+
err := fmt.Errorf("snapshots quota on Google Cloud Platform has been reached")
264+
return "", errors.WithStack(err)
265+
}
266+
break
267+
}
268+
}
269+
252270
if len(volumeID) <= (63 - len(suffix)) {
253271
snapshotName = volumeID + suffix
254272
} else {

0 commit comments

Comments
 (0)