Skip to content

Commit 7cc812a

Browse files
committed
feat(topology): restrict from deleting create-by label on pools
Signed-off-by: sinhaashish <[email protected]>
1 parent 848bcd5 commit 7cc812a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

control-plane/agents/src/bin/core/pool/pool_operations.rs

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use stor_port::{
1616
transport::{CreatePool, CtrlPoolState, DestroyPool, Pool},
1717
},
1818
};
19+
use utils::dsp_created_by_key;
1920

2021
#[async_trait::async_trait]
2122
impl ResourceLifecycle for OperationGuardArc<PoolSpec> {
@@ -169,6 +170,13 @@ impl ResourceLabel for OperationGuardArc<PoolSpec> {
169170
registry: &Registry,
170171
label_key: String,
171172
) -> Result<Self::UnlabelOutput, SvcError> {
173+
if label_key == dsp_created_by_key() {
174+
return Err(SvcError::InvalidLabelCreatedBy {
175+
labels: label_key,
176+
resource_kind: ResourceKind::Pool,
177+
}
178+
.into());
179+
}
172180
let cloned_pool_spec = self.lock().clone();
173181
let spec_clone = self
174182
.start_update(

control-plane/agents/src/bin/core/pool/service.rs

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl PoolOperations for Service {
9898
}
9999
.into());
100100
}
101+
101102
let pool = Context::spawn(async move { service.unlabel(&req).await }).await??;
102103
Ok(pool)
103104
}

control-plane/agents/src/common/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ pub enum SvcError {
208208
labels: String,
209209
resource_kind: ResourceKind,
210210
},
211+
#[snafu(display("Invalid {}, labels: {} . Cannot delete `created-by` label as it is used for identifying mayastor pools", resource_kind, labels))]
212+
InvalidLabelCreatedBy {
213+
labels: String,
214+
resource_kind: ResourceKind,
215+
},
211216
#[snafu(display("Multiple nexuses not supported"))]
212217
MultipleNexuses {},
213218
#[snafu(display("Storage Error: {}", source))]
@@ -801,6 +806,12 @@ impl From<SvcError> for ReplyError {
801806
source,
802807
extra,
803808
},
809+
SvcError::InvalidLabelCreatedBy { resource_kind, .. } => ReplyError {
810+
kind: ReplyErrorKind::InvalidArgument,
811+
resource: resource_kind,
812+
source,
813+
extra,
814+
},
804815
SvcError::MultipleNexuses { .. } => ReplyError {
805816
kind: ReplyErrorKind::InvalidArgument,
806817
resource: ResourceKind::Unknown,

0 commit comments

Comments
 (0)