Skip to content

Commit

Permalink
chore: add a cli to toggle the force unstage feature
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinandan Purkait <[email protected]>
  • Loading branch information
Abhinandan-Purkait committed Dec 12, 2024
1 parent 827986c commit 93a2ebf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
14 changes: 14 additions & 0 deletions control-plane/csi-driver/src/bin/controller/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub(crate) struct CsiControllerConfig {
node_selector: HashMap<String, String>,
/// Max Outstanding Create Volume Requests.
create_volume_limit: usize,
/// Force unstage volume.
force_unstage_volume: bool,
}

impl CsiControllerConfig {
Expand Down Expand Up @@ -43,11 +45,19 @@ impl CsiControllerConfig {
.map(|s| s.map(|s| s.as_str())),
)?;

let force_unstage_volume = args.get_flag("force-unstage-volume");
if !force_unstage_volume {
tracing::warn!(
"Force unstage volume is disabled, can trigger potential data corruption!"
);
}

CONFIG.get_or_init(|| Self {
rest_endpoint: rest_endpoint.into(),
io_timeout: io_timeout.into(),
node_selector,
create_volume_limit,
force_unstage_volume,
});
Ok(())
}
Expand Down Expand Up @@ -78,4 +88,8 @@ impl CsiControllerConfig {
pub(crate) fn node_selector_segment(&self) -> HashMap<String, String> {
self.node_selector.clone()
}
/// Force unstage volume.
pub(crate) fn force_unstage_volume(&self) -> bool {
self.force_unstage_volume
}
}
10 changes: 5 additions & 5 deletions control-plane/csi-driver/src/bin/controller/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ const SNAPSHOT_NAME_PATTERN: &str =
#[derive(Debug)]
pub(crate) struct CsiControllerSvc {
create_volume_limiter: std::sync::Arc<tokio::sync::Semaphore>,
force_unstage_volume: bool,
}
impl CsiControllerSvc {
pub(crate) fn new(cfg: &CsiControllerConfig) -> Self {
Self {
create_volume_limiter: std::sync::Arc::new(tokio::sync::Semaphore::new(
cfg.create_volume_limit(),
)),
force_unstage_volume: cfg.force_unstage_volume(),
}
}
async fn create_volume_permit(&self) -> Result<tokio::sync::SemaphorePermit, tonic::Status> {
Expand Down Expand Up @@ -592,13 +594,11 @@ impl rpc::csi::controller_server::Controller for CsiControllerSvc {
}?;

// Issue a cleanup rpc to csi node to ensure the subsystem doesn't have any path present before publishing
match RestApiClient::get_client().get_app_node(&args.node_id).await {
Ok(app_node) => force_unstage(app_node, volume_id.to_string()).await?,
Err(ApiClientError::ResourceNotExists(..)) => warn!("App node: {}, not found, skipping force unstage volume", args.node_id),
Err(error) => return Err(error.into())
if self.force_unstage_volume {
let app_node = RestApiClient::get_client().get_app_node(&args.node_id).await?;
force_unstage(app_node, volume_id.to_string()).await?;
}


// Volume is not published.
let v = RestApiClient::get_client()
.publish_volume(&volume_id, target_node, protocol, args.node_id.clone(), &publish_context)
Expand Down
7 changes: 7 additions & 0 deletions control-plane/csi-driver/src/bin/controller/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ async fn main() -> anyhow::Result<()> {
.value_parser(clap::value_parser!(bool))
.help("Enable ansi color for logs")
)
.arg(
Arg::new("force-unstage-volume")
.long("force-unstage-volume")
.default_value("true")
.value_parser(clap::value_parser!(bool))
.help("Enable force unstage volume feature")
)
.get_matches();

utils::print_package_info!();
Expand Down
4 changes: 3 additions & 1 deletion deployer/src/infra/csi-driver/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ impl ComponentAction for CsiController {
.with_args(vec!["--rest-endpoint", "http://rest:8081"])
// Make sure that CSI socket is always under shared directory
// regardless of what its default value is.
.with_args(vec!["--csi-socket", CSI_SOCKET]);
.with_args(vec!["--csi-socket", CSI_SOCKET])
// Disable force unstage volume. TODO: remove the flag and fix test.
.with_args(vec!["--force-unstage-volume", "false"]);

if cfg.container_exists("jaeger") {
let jaeger_config = format!("jaeger.{}", cfg.get_name());
Expand Down

0 comments on commit 93a2ebf

Please sign in to comment.