diff --git a/docs/api-types/volumesnapshotlocation.md b/docs/api-types/volumesnapshotlocation.md index 734297f3d..7d287dc73 100644 --- a/docs/api-types/volumesnapshotlocation.md +++ b/docs/api-types/volumesnapshotlocation.md @@ -52,9 +52,15 @@ The configurable parameters are as follows: #### GCP -No parameters required. +##### config + +| Key | Type | Default | Meaning | +| --- | --- | --- | --- | +| `snapshotLocation` | string | Empty | *Example*: "us-central1"

See [GCP documentation][4] for the full list.

If not specified the snapshots are stored in the [default location][5]. | [0]: #aws [1]: #gcp [2]: #azure [3]: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions +[4]: https://cloud.google.com/storage/docs/locations#available_locations +[5]: https://cloud.google.com/compute/docs/disks/create-snapshots#default_location diff --git a/docs/gcp-config.md b/docs/gcp-config.md index 79b6220a5..25939a784 100644 --- a/docs/gcp-config.md +++ b/docs/gcp-config.md @@ -140,6 +140,10 @@ Specify the following values in the example files: * Uncomment the `--default-volume-snapshot-locations` and replace provider locations with the values for your environment. +* (Optional) In file `config/gcp/06-volumesnapshotlocation.yaml`: + + * Add `snapshotLocation: ` to the config. See the [VolumeSnapshotLocation definition][8] for details. + ## Start the server In the root of your Velero directory, run: @@ -152,6 +156,7 @@ In the root of your Velero directory, run: [0]: namespace.md [7]: api-types/backupstoragelocation.md#gcp + [8]: api-types/volumesnapshotlocation.md#gcp [15]: https://cloud.google.com/compute/docs/access/service-accounts [16]: https://cloud.google.com/sdk/docs/ [20]: faq.md diff --git a/examples/gcp/06-volumesnapshotlocation.yaml b/examples/gcp/06-volumesnapshotlocation.yaml index 46443eee0..728aa938f 100644 --- a/examples/gcp/06-volumesnapshotlocation.yaml +++ b/examples/gcp/06-volumesnapshotlocation.yaml @@ -20,3 +20,4 @@ metadata: namespace: velero spec: provider: gcp + config: {} diff --git a/pkg/cloudprovider/gcp/volume_snapshotter.go b/pkg/cloudprovider/gcp/volume_snapshotter.go index b7af2e82e..8a1c5dc63 100644 --- a/pkg/cloudprovider/gcp/volume_snapshotter.go +++ b/pkg/cloudprovider/gcp/volume_snapshotter.go @@ -38,14 +38,16 @@ import ( ) const ( - projectKey = "project" - zoneSeparator = "__" + projectKey = "project" + zoneSeparator = "__" + snapshotLocationKey = "snapshotLocation" ) type VolumeSnapshotter struct { - gce *compute.Service - project string - log logrus.FieldLogger + gce *compute.Service + project string + log logrus.FieldLogger + snapshotLocation string } func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter { @@ -53,10 +55,12 @@ func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter { } func (b *VolumeSnapshotter) Init(config map[string]string) error { - if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config); err != nil { + if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config, snapshotLocationKey); err != nil { return err } + b.snapshotLocation = config[snapshotLocationKey] + project, err := extractProjectFromCreds() if err != nil { return err @@ -249,6 +253,10 @@ func (b *VolumeSnapshotter) createSnapshot(snapshotName, volumeID, volumeAZ stri Description: getSnapshotTags(tags, disk.Description, b.log), } + if b.snapshotLocation != "" { + gceSnap.StorageLocations = []string{b.snapshotLocation} + } + _, err = b.gce.Disks.CreateSnapshot(b.project, volumeAZ, volumeID, &gceSnap).Do() if err != nil { return "", errors.WithStack(err) @@ -268,6 +276,10 @@ func (b *VolumeSnapshotter) createRegionSnapshot(snapshotName, volumeID, volumeR Description: getSnapshotTags(tags, disk.Description, b.log), } + if b.snapshotLocation != "" { + gceSnap.StorageLocations = []string{b.snapshotLocation} + } + _, err = b.gce.RegionDisks.CreateSnapshot(b.project, volumeRegion, volumeID, &gceSnap).Do() if err != nil { return "", errors.WithStack(err)