Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for archive snapshot type #173

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions velero-plugin-for-gcp/volume_snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
zoneSeparator = "__"
projectKey = "project"
snapshotLocationKey = "snapshotLocation"
snapshotTypeKey = "snapshotType"
volumeProjectKey = "volumeProject"
)

Expand All @@ -59,6 +60,7 @@ type VolumeSnapshotter struct {
snapshotLocation string
volumeProject string
snapshotProject string
snapshotType string
}

func newVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
Expand All @@ -67,7 +69,7 @@ func newVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {

func (b *VolumeSnapshotter) Init(config map[string]string) error {
if err := veleroplugin.ValidateVolumeSnapshotterConfigKeys(config,
snapshotLocationKey, projectKey, credentialsFileConfigKey, volumeProjectKey); err != nil {
snapshotLocationKey, snapshotTypeKey, projectKey, credentialsFileConfigKey, volumeProjectKey); err != nil {
return err
}

Expand Down Expand Up @@ -116,6 +118,18 @@ func (b *VolumeSnapshotter) Init(config map[string]string) error {
b.snapshotProject = b.volumeProject
}

// get snapshot type from 'snapshotType' config key if specified,
// otherwise default to "STANDARD"
snapshotType := strings.ToUpper(config[snapshotTypeKey])
switch snapshotType {
case "":
b.snapshotType = "STANDARD"
case "STANDARD", "ARCHIVE":
b.snapshotType = snapshotType
default:
return errors.Errorf("unsupported snapshot type: %q", snapshotType)
}

gce, err := compute.NewService(context.TODO(), clientOptions...)
if err != nil {
return errors.WithStack(err)
Expand Down Expand Up @@ -300,9 +314,10 @@ func (b *VolumeSnapshotter) createSnapshot(snapshotName, volumeID, volumeAZ stri
}

gceSnap := compute.Snapshot{
Name: snapshotName,
Description: getSnapshotTags(tags, disk.Description, b.log),
SourceDisk: disk.SelfLink,
Name: snapshotName,
Description: getSnapshotTags(tags, disk.Description, b.log),
SourceDisk: disk.SelfLink,
SnapshotType: b.snapshotType,
}

if b.snapshotLocation != "" {
Expand All @@ -324,9 +339,10 @@ func (b *VolumeSnapshotter) createRegionSnapshot(snapshotName, volumeID, volumeR
}

gceSnap := compute.Snapshot{
Name: snapshotName,
Description: getSnapshotTags(tags, disk.Description, b.log),
SourceDisk: disk.SelfLink,
Name: snapshotName,
Description: getSnapshotTags(tags, disk.Description, b.log),
SourceDisk: disk.SelfLink,
SnapshotType: b.snapshotType,
}

if b.snapshotLocation != "" {
Expand Down
19 changes: 19 additions & 0 deletions velero-plugin-for-gcp/volume_snapshotter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,37 @@ func TestInit(t *testing.T) {
snapshotLocation: "default",
volumeProject: "project-b",
snapshotProject: "project-a",
snapshotType: "STANDARD",
},
},
{
name: "Init without Credential files.",
config: map[string]string{
"project": "project-a",
"snapshotLocation": "default",
"snapshotType": "standard",
"volumeProject": "project-b",
},
expectedVolumeSnapshotter: VolumeSnapshotter{
snapshotLocation: "default",
volumeProject: "project-b",
snapshotProject: "project-a",
snapshotType: "STANDARD",
},
},
{
name: "Init with archive snapshot type.",
config: map[string]string{
"project": "project-a",
"snapshotLocation": "default",
"snapshotType": "archive",
"volumeProject": "project-b",
},
expectedVolumeSnapshotter: VolumeSnapshotter{
snapshotLocation: "default",
volumeProject: "project-b",
snapshotProject: "project-a",
snapshotType: "ARCHIVE",
},
},
}
Expand All @@ -476,6 +494,7 @@ func TestInit(t *testing.T) {
require.Equal(t, test.expectedVolumeSnapshotter.snapshotLocation, volumeSnapshotter.snapshotLocation)
require.Equal(t, test.expectedVolumeSnapshotter.volumeProject, volumeSnapshotter.volumeProject)
require.Equal(t, test.expectedVolumeSnapshotter.snapshotProject, volumeSnapshotter.snapshotProject)
require.Equal(t, test.expectedVolumeSnapshotter.snapshotType, volumeSnapshotter.snapshotType)
})
}

Expand Down
Loading