Skip to content

Commit

Permalink
Merge pull request #144 from 0x113/SGLAB-CLOUDCASA-snapshot-limit
Browse files Browse the repository at this point in the history
Do not attempt to create snapshots if the quota is reached
  • Loading branch information
sseago authored Jul 18, 2023
2 parents 4b89346 + e69488e commit 4a46a41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions changelogs/unreleased/144-0x113
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Check the "SNAPSHOTS" quota on Google Cloud Platform and do not attempt to create snapshots if the quota is reached.

18 changes: 18 additions & 0 deletions velero-plugin-for-gcp/volume_snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4a46a41

Please sign in to comment.