Skip to content

Commit 3e352f6

Browse files
mayastor-borsdsharma-dc
andcommitted
chore(bors): merge pull request #967
967: feat: allow setting encryption property on volume spec r=dsharma-dc a=dsharma-dc This way of setting encryption property should be used with caution when the user knows what they are doing, e.g. planned manual migration of pools from non-encrypted to encrypted. Co-authored-by: Diwakar Sharma <[email protected]>
2 parents 11017a0 + 7ce258d commit 3e352f6

File tree

8 files changed

+53
-23
lines changed

8 files changed

+53
-23
lines changed

control-plane/grpc/proto/v1/volume/volume.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ message SetVolumePropertyRequest {
391391
message VolumeProperty {
392392
oneof attr {
393393
MaxSnapshotValue max_snapshots = 1;
394+
bool encrypted = 2;
394395
}
395396
}
396397
// Max snapshots limit per volume.

control-plane/grpc/src/operations/volume/traits.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,7 @@ impl From<SetVolumePropertyRequest> for Option<VolumeProperty> {
18291829
volume::volume_property::Attr::MaxSnapshots(volume::MaxSnapshotValue { value }) => {
18301830
VolumeProperty::MaxSnapshots(value)
18311831
}
1832+
volume::volume_property::Attr::Encrypted(value) => VolumeProperty::Encrypted(value),
18321833
})
18331834
})
18341835
}
@@ -1842,6 +1843,9 @@ impl From<VolumeProperty> for volume::VolumeProperty {
18421843
volume::MaxSnapshotValue { value },
18431844
)),
18441845
},
1846+
VolumeProperty::Encrypted(value) => volume::VolumeProperty {
1847+
attr: Some(volume::volume_property::Attr::Encrypted(value)),
1848+
},
18451849
}
18461850
}
18471851
}

control-plane/plugin/src/resources/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ pub enum SetPropertyResources {
9191
pub enum SetVolumeProperties {
9292
/// Max snapshot limit per volume.
9393
MaxSnapshots { max_snapshots: u32 },
94+
#[clap(
95+
about = "Encryption required for volume.\n\x1b[31m\x1b[1mCAUTION:\x1b[0m Use carefully during for example non-encrypted to encrypted pool migration. Refer to documentation for more details."
96+
)]
97+
Encryption {
98+
#[clap(action = clap::ArgAction::Set)]
99+
enabled: bool,
100+
},
94101
}
95102

96103
/// The types of resources that support cordoning.

control-plane/plugin/src/resources/volume.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -277,33 +277,38 @@ impl SetProperty for Volume {
277277
property: &Self::Property,
278278
output: &utils::OutputFormat,
279279
) -> PluginResult {
280-
match property {
280+
let property_body = match property {
281281
SetVolumeProperties::MaxSnapshots { max_snapshots } => {
282-
let property_body = SetVolumePropertyBody::max_snapshots(*max_snapshots);
283-
match RestClient::client()
284-
.volumes_api()
285-
.put_volume_property(id, property_body.clone())
286-
.await
287-
{
288-
Ok(volume) => match output {
289-
OutputFormat::Yaml | OutputFormat::Json => {
290-
// Print json or yaml based on output format.
291-
utils::print_table(output, volume.into_body());
292-
}
293-
OutputFormat::None => {
294-
// In case the output format is not specified, show a success message.
295-
println!("Volume {id} property {:?} set successfully", property_body);
296-
}
297-
},
298-
Err(e) => {
299-
return Err(Error::SetVolumePropertyError {
300-
id: id.to_string(),
301-
source: e,
302-
});
303-
}
282+
SetVolumePropertyBody::max_snapshots(*max_snapshots)
283+
}
284+
SetVolumeProperties::Encryption { enabled } => {
285+
SetVolumePropertyBody::encrypted(*enabled)
286+
}
287+
};
288+
289+
match RestClient::client()
290+
.volumes_api()
291+
.put_volume_property(id, property_body.clone())
292+
.await
293+
{
294+
Ok(volume) => match output {
295+
OutputFormat::Yaml | OutputFormat::Json => {
296+
// Print json or yaml based on output format.
297+
utils::print_table(output, volume.into_body());
298+
}
299+
OutputFormat::None => {
300+
// In case the output format is not specified, show a success message.
301+
println!("Volume {id} property {:?} set successfully", property_body);
304302
}
303+
},
304+
Err(e) => {
305+
return Err(Error::SetVolumePropertyError {
306+
id: id.to_string(),
307+
source: e,
308+
});
305309
}
306310
}
311+
307312
Ok(())
308313
}
309314
}

control-plane/rest/openapi-specs/v0_api_spec.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,12 +2726,17 @@ components:
27262726
oneOf:
27272727
- required:
27282728
- max_snapshots
2729+
- required:
2730+
- encrypted
27292731
properties:
27302732
max_snapshots:
27312733
description: Max Snapshots limit per volume.
27322734
type: integer
27332735
format: int32
27342736
minimum: 0
2737+
encrypted:
2738+
description: Volume is required to be encrypted.
2739+
type: boolean
27352740
AffinityGroup:
27362741
example:
27372742
id: "ag"

control-plane/rest/src/versions/v0.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ impl From<models::SetVolumePropertyBody> for SetVolumePropertyBody {
286286
models::SetVolumePropertyBody::max_snapshots(x) => Self {
287287
property: VolumeProperty::MaxSnapshots(x),
288288
},
289+
models::SetVolumePropertyBody::encrypted(b) => Self {
290+
property: VolumeProperty::Encrypted(b),
291+
},
289292
}
290293
}
291294
}

control-plane/stor-port/src/types/v0/store/volume.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ impl SpecTransaction<VolumeOperation> for VolumeSpec {
529529
VolumeProperty::MaxSnapshots(max_snapshots) => {
530530
self.max_snapshots = Some(max_snapshots);
531531
}
532+
VolumeProperty::Encrypted(encrypted) => {
533+
self.encrypted = encrypted;
534+
}
532535
},
533536
}
534537
}

control-plane/stor-port/src/types/v0/transport/volume.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ impl From<VolumeHealth> for models::VolumeHealth {
110110
pub enum VolumeProperty {
111111
/// Max number of snapshots allowed per volume.
112112
MaxSnapshots(u32),
113+
/// Volume is required to be encrypted.
114+
Encrypted(bool),
113115
}
114116

115117
#[derive(Default, Debug, Clone, Eq, PartialEq)]

0 commit comments

Comments
 (0)