Skip to content

Commit

Permalink
define availability zone for snapshot backup
Browse files Browse the repository at this point in the history
  • Loading branch information
zetaab committed Apr 9, 2024
1 parent 290e7c7 commit 45a1fba
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/csi/cinder/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func (cs *controllerServer) createBackup(name string, volumeID string, snap *sna
}
}

backup, err := cs.Cloud.CreateBackup(name, volumeID, snap.ID, properties)
backup, err := cs.Cloud.CreateBackup(name, volumeID, snap.ID, parameters[openstack.SnapshotAvailabilityZone], properties)
if err != nil {
klog.Errorf("Failed to Create backup: %v", err)
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateBackup failed with error %v", err))
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi/cinder/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type IOpenStack interface {
DeleteSnapshot(snapID string) error
GetSnapshotByID(snapshotID string) (*snapshots.Snapshot, error)
WaitSnapshotReady(snapshotID string) (string, error)
CreateBackup(name, volID string, snapshotID string, tags map[string]string) (*backups.Backup, error)
CreateBackup(name, volID, snapshotID, availabilityZone string, tags map[string]string) (*backups.Backup, error)
ListBackups(filters map[string]string) ([]backups.Backup, error)
DeleteBackup(backupID string) error
GetBackupByID(backupID string) (*backups.Backup, error)
Expand Down
8 changes: 7 additions & 1 deletion pkg/csi/cinder/openstack/openstack_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (

// CreateBackup issues a request to create a Backup from the specified Snapshot with the corresponding ID and
// returns the resultant gophercloud Backup Item upon success.
func (os *OpenStack) CreateBackup(name, volID string, snapshotID string, tags map[string]string) (*backups.Backup, error) {
func (os *OpenStack) CreateBackup(name, volID, snapshotID, availabilityZone string, tags map[string]string) (*backups.Backup, error) {
blockstorageServiceClient, err := openstack.NewBlockStorageV3(os.blockstorage.ProviderClient, os.epOpts)
if err != nil {
return &backups.Backup{}, err
Expand Down Expand Up @@ -76,6 +76,12 @@ func (os *OpenStack) CreateBackup(name, volID string, snapshotID string, tags ma
opts.Metadata = tags
}

if availabilityZone != "" {
// 3.51 is minimum if az is defined for the request
blockstorageServiceClient.Microversion = "3.51"
opts.AvailabilityZone = availabilityZone
}

// TODO: Do some check before really call openstack API on the input
mc := metrics.NewMetricContext("backup", "create")
backup, err := backups.Create(blockstorageServiceClient, opts).Extract()
Expand Down
12 changes: 6 additions & 6 deletions pkg/csi/cinder/openstack/openstack_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,21 @@ func (_m *OpenStackMock) ListBackups(filters map[string]string) ([]backups.Backu
return r0, r1
}

func (_m *OpenStackMock) CreateBackup(name, volID string, snapshotID string, tags map[string]string) (*backups.Backup, error) {
ret := _m.Called(name, volID, snapshotID, tags)
func (_m *OpenStackMock) CreateBackup(name, volID, snapshotID, availabilityZone string, tags map[string]string) (*backups.Backup, error) {
ret := _m.Called(name, volID, snapshotID, availabilityZone, tags)

var r0 *backups.Backup
if rf, ok := ret.Get(0).(func(string, string, string, map[string]string) *backups.Backup); ok {
r0 = rf(name, volID, snapshotID, tags)
if rf, ok := ret.Get(0).(func(string, string, string, string, map[string]string) *backups.Backup); ok {
r0 = rf(name, volID, snapshotID, availabilityZone, tags)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*backups.Backup)
}
}

var r1 error
if rf, ok := ret.Get(1).(func(string, string, string, map[string]string) error); ok {
r1 = rf(name, volID, snapshotID, tags)
if rf, ok := ret.Get(1).(func(string, string, string, string, map[string]string) error); ok {
r1 = rf(name, volID, snapshotID, availabilityZone, tags)
} else {
r1 = ret.Error(1)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/csi/cinder/openstack/openstack_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ const (
snapReadyFactor = 1.2
snapReadySteps = 10

snapshotDescription = "Created by OpenStack Cinder CSI driver"
SnapshotForceCreate = "force-create"
SnapshotType = "type"
snapshotDescription = "Created by OpenStack Cinder CSI driver"
SnapshotForceCreate = "force-create"
SnapshotType = "type"
SnapshotAvailabilityZone = "availability"
)

// CreateSnapshot issues a request to take a Snapshot of the specified Volume with the corresponding ID and
Expand Down
15 changes: 8 additions & 7 deletions tests/sanity/cinder/fakecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,16 @@ func (cloud *cloud) WaitSnapshotReady(snapshotID string) (string, error) {
return "available", nil
}

func (cloud *cloud) CreateBackup(name, volID string, snapshotID string, tags map[string]string) (*backups.Backup, error) {
func (cloud *cloud) CreateBackup(name, volID, snapshotID, availabilityZone string, tags map[string]string) (*backups.Backup, error) {

backup := &backups.Backup{
ID: randString(10),
Name: name,
Status: "available",
VolumeID: volID,
SnapshotID: snapshotID,
CreatedAt: time.Now(),
ID: randString(10),
Name: name,
Status: "available",
VolumeID: volID,
SnapshotID: snapshotID,
AvailabilityZone: &availabilityZone,
CreatedAt: time.Now(),
}

cloud.backups[backup.ID] = backup
Expand Down

0 comments on commit 45a1fba

Please sign in to comment.