Add config parameter for gcp to customize the snapshot location

Signed-off-by: Cyrill Troxler <cyrill@nine.ch>
This commit is contained in:
Cyrill Troxler
2019-04-17 18:34:09 +02:00
parent ff642d739d
commit 6020823aaf
4 changed files with 31 additions and 7 deletions
+7 -1
View File
@@ -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"<br><br>See [GCP documentation][4] for the full list.<br><br>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
+5
View File
@@ -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: <YOUR_LOCATION>` 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
@@ -20,3 +20,4 @@ metadata:
namespace: velero
spec:
provider: gcp
config: {}
+18 -6
View File
@@ -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)