Skip to content

Commit

Permalink
feat(topology/poolaffinitykey): add topology/poolaffinitykey code to …
Browse files Browse the repository at this point in the history
…csi-driver

Signed-off-by: sinhaashish <[email protected]>
  • Loading branch information
sinhaashish committed Sep 9, 2024
1 parent fce465f commit 7b1e1d4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions control-plane/csi-driver/src/bin/controller/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ fn context_into_topology(context: &CreateParams) -> CreateVolumeTopology {
let mut pool_inclusive_label_topology: HashMap<String, String> = HashMap::new();
let mut node_inclusive_label_topology: HashMap<String, String> = HashMap::new();
let mut node_exclusive_label_topology: HashMap<String, String> = HashMap::new();
let mut pool_affinity_label_topology: Vec<String> = Vec::<String>::new();
pool_inclusive_label_topology.insert(dsp_created_by_key(), String::from(DSP_OPERATOR));
pool_inclusive_label_topology.extend(
context
Expand All @@ -1090,6 +1091,13 @@ fn context_into_topology(context: &CreateParams) -> CreateVolumeTopology {
.clone()
.unwrap_or_default(),
);
pool_affinity_label_topology.extend(
context
.publish_params()
.pool_affinity_topology_key()
.clone()
.unwrap_or_default(),
);
node_inclusive_label_topology.extend(
context
.publish_params()
Expand All @@ -1111,14 +1119,17 @@ fn context_into_topology(context: &CreateParams) -> CreateVolumeTopology {
.clone()
.unwrap_or_default(),
);

CreateVolumeTopology::new(
Some(models::NodeTopology::labelled(LabelledTopology {
exclusion: node_exclusive_label_topology,
inclusion: node_inclusive_label_topology,
affinitykey: Default::default(),
})),
Some(PoolTopology::labelled(LabelledTopology {
exclusion: Default::default(),
inclusion: pool_inclusive_label_topology,
affinitykey: pool_affinity_label_topology,
})),
)
}
40 changes: 40 additions & 0 deletions control-plane/csi-driver/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub enum Parameters {
QuiesceFs,
#[strum(serialize = "poolAffinityTopologyLabel")]
PoolAffinityTopologyLabel,
#[strum(serialize = "poolAffinityTopologyKey")]
PoolAffinityTopologyKey,
#[strum(serialize = "poolHasTopologyKey")]
PoolHasTopologyKey,
#[strum(serialize = "nodeAffinityTopologyLabel")]
Expand Down Expand Up @@ -116,6 +118,27 @@ impl Parameters {
})
}

fn parse_topology_param_vec(
value: Option<&String>,
) -> Result<Option<Vec<String>>, tonic::Status> {
Ok(match value {
Some(labels) => {
let mut result_vec = Vec::new();
for label in labels.split('\n') {
if !label.is_empty() {
result_vec.push(label.to_string())
} else {
return Err(tonic::Status::invalid_argument(format!(
"Invalid label : {value:?}"
)));
}
}
Some(result_vec)
}
None => None,
})
}

fn parse_u32(value: Option<&String>) -> Result<Option<u32>, ParseIntError> {
Ok(match value {
Some(value) => value.parse::<u32>().map(Some)?,
Expand Down Expand Up @@ -176,6 +199,12 @@ impl Parameters {
) -> Result<Option<HashMap<String, String>>, tonic::Status> {
Self::parse_topology_param(value)
}
/// Parse the value for `Self::PoolAffinityTopologyKey`.
pub fn pool_affinity_topology_key(
value: Option<&String>,
) -> Result<Option<Vec<String>>, tonic::Status> {
Self::parse_topology_param_vec(value)
}
/// Parse the value for `Self::PoolHasTopologyKey`.
pub fn pool_has_topology_key(
value: Option<&String>,
Expand Down Expand Up @@ -217,6 +246,7 @@ pub struct PublishParams {
fs_type: Option<FileSystem>,
fs_id: Option<Uuid>,
pool_affinity_topology_label: Option<HashMap<String, String>>,
pool_affinity_topology_key: Option<Vec<String>>,
pool_has_topology_key: Option<HashMap<String, String>>,
node_affinity_topology_label: Option<HashMap<String, String>>,
node_has_topology_key: Option<HashMap<String, String>>,
Expand Down Expand Up @@ -247,6 +277,10 @@ impl PublishParams {
pub fn pool_affinity_topology_label(&self) -> &Option<HashMap<String, String>> {
&self.pool_affinity_topology_label
}
/// Get the `Parameters::PoolAffinityTopologyKey` value.
pub fn pool_affinity_topology_key(&self) -> &Option<Vec<String>> {
&self.pool_affinity_topology_key
}
/// Get the `Parameters::PoolHasTopologyKey` value.
pub fn pool_has_topology_key(&self) -> &Option<HashMap<String, String>> {
&self.pool_has_topology_key
Expand Down Expand Up @@ -319,6 +353,11 @@ impl TryFrom<&HashMap<String, String>> for PublishParams {
)
.map_err(|_| tonic::Status::invalid_argument("Invalid pool_affinity_topology_label"))?;

let pool_affinity_topology_key = Parameters::pool_affinity_topology_key(
args.get(Parameters::PoolAffinityTopologyKey.as_ref()),
)
.map_err(|_| tonic::Status::invalid_argument("Invalid pool_affinity_topology_key"))?;

let pool_has_topology_key =
Parameters::pool_has_topology_key(args.get(Parameters::PoolHasTopologyKey.as_ref()))
.map_err(|_| tonic::Status::invalid_argument("Invalid pool_has_topology_key"))?;
Expand Down Expand Up @@ -356,6 +395,7 @@ impl TryFrom<&HashMap<String, String>> for PublishParams {
fs_type,
fs_id,
pool_affinity_topology_label,
pool_affinity_topology_key,
pool_has_topology_key,
node_affinity_topology_label,
node_has_topology_key,
Expand Down

0 comments on commit 7b1e1d4

Please sign in to comment.