Skip to content

Commit ffdba04

Browse files
authored
BR: Support encryption for restored ebs volumes (#48900) (#48938)
close #48899
1 parent 523a313 commit ffdba04

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

br/pkg/aws/ebs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func (e *EC2Session) DeleteSnapshots(snapIDMap map[string]string) {
284284
// CreateVolumes create volumes from snapshots
285285
// if err happens in the middle, return half-done result
286286
// returned map: store id -> old volume id -> new volume id
287-
func (e *EC2Session) CreateVolumes(meta *config.EBSBasedBRMeta, volumeType string, iops, throughput int64, targetAZ string) (map[string]string, error) {
287+
func (e *EC2Session) CreateVolumes(meta *config.EBSBasedBRMeta, volumeType string, iops, throughput int64, encrypted bool, targetAZ string) (map[string]string, error) {
288288
template := ec2.CreateVolumeInput{
289289
VolumeType: &volumeType,
290290
}
@@ -294,6 +294,7 @@ func (e *EC2Session) CreateVolumes(meta *config.EBSBasedBRMeta, volumeType strin
294294
if throughput > 0 {
295295
template.SetThroughput(throughput)
296296
}
297+
template.Encrypted = &encrypted
297298

298299
newVolumeIDMap := make(map[string]string)
299300
var mutex sync.Mutex

br/pkg/task/restore.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ type RestoreConfig struct {
216216
VolumeType pconfig.EBSVolumeType `json:"volume-type" toml:"volume-type"`
217217
VolumeIOPS int64 `json:"volume-iops" toml:"volume-iops"`
218218
VolumeThroughput int64 `json:"volume-throughput" toml:"volume-throughput"`
219+
VolumeEncrypted bool `json:"volume-encrypted" toml:"volume-encrypted"`
219220
ProgressFile string `json:"progress-file" toml:"progress-file"`
220221
TargetAZ string `json:"target-az" toml:"target-az"`
221222
}
@@ -380,6 +381,9 @@ func (cfg *RestoreConfig) ParseFromFlags(flags *pflag.FlagSet) error {
380381
if cfg.VolumeThroughput, err = flags.GetInt64(flagVolumeThroughput); err != nil {
381382
return errors.Trace(err)
382383
}
384+
if cfg.VolumeEncrypted, err = flags.GetBool(flagVolumeEncrypted); err != nil {
385+
return errors.Trace(err)
386+
}
383387

384388
cfg.ProgressFile, err = flags.GetString(flagProgressFile)
385389
if err != nil {

br/pkg/task/restore_ebs_meta.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const (
4141
flagVolumeType = "volume-type"
4242
flagVolumeIOPS = "volume-iops"
4343
flagVolumeThroughput = "volume-throughput"
44+
flagVolumeEncrypted = "volume-encrypted"
4445
flagTargetAZ = "target-az"
4546
)
4647

@@ -54,6 +55,7 @@ func DefineRestoreSnapshotFlags(command *cobra.Command) {
5455
command.Flags().String(flagVolumeType, string(config.GP3Volume), "volume type: gp3, io1, io2")
5556
command.Flags().Int64(flagVolumeIOPS, 0, "volume iops(0 means default for that volume type)")
5657
command.Flags().Int64(flagVolumeThroughput, 0, "volume throughout in MiB/s(0 means default for that volume type)")
58+
command.Flags().Bool(flagVolumeEncrypted, false, "whether encryption is enabled for the volume")
5759
command.Flags().String(flagProgressFile, "progress.txt", "the file name of progress file")
5860
command.Flags().String(flagTargetAZ, "", "the target AZ for restored volumes")
5961

@@ -65,6 +67,7 @@ func DefineRestoreSnapshotFlags(command *cobra.Command) {
6567
_ = command.Flags().MarkHidden(flagVolumeType)
6668
_ = command.Flags().MarkHidden(flagVolumeIOPS)
6769
_ = command.Flags().MarkHidden(flagVolumeThroughput)
70+
_ = command.Flags().MarkHidden(flagVolumeEncrypted)
6871
_ = command.Flags().MarkHidden(flagProgressFile)
6972
_ = command.Flags().MarkHidden(flagTargetAZ)
7073
}
@@ -238,7 +241,7 @@ func (h *restoreEBSMetaHelper) restoreVolumes(progress glue.Progress) (map[strin
238241
}
239242
}()
240243
volumeIDMap, err = ec2Session.CreateVolumes(h.metaInfo,
241-
string(h.cfg.VolumeType), h.cfg.VolumeIOPS, h.cfg.VolumeThroughput, h.cfg.TargetAZ)
244+
string(h.cfg.VolumeType), h.cfg.VolumeIOPS, h.cfg.VolumeThroughput, h.cfg.VolumeEncrypted, h.cfg.TargetAZ)
242245
if err != nil {
243246
return nil, 0, errors.Trace(err)
244247
}

0 commit comments

Comments
 (0)