diff --git a/src/runtime-rs/crates/runtimes/common/src/types/mod.rs b/src/runtime-rs/crates/runtimes/common/src/types/mod.rs index 14f188d7d3..0e6f80a4f6 100644 --- a/src/runtime-rs/crates/runtimes/common/src/types/mod.rs +++ b/src/runtime-rs/crates/runtimes/common/src/types/mod.rs @@ -128,6 +128,7 @@ pub struct ContainerConfig { pub bundle: String, pub rootfs_mounts: Vec, pub terminal: bool, + pub options: Option>, pub stdin: Option, pub stdout: Option, pub stderr: Option, diff --git a/src/runtime-rs/crates/runtimes/common/src/types/trans_from_shim.rs b/src/runtime-rs/crates/runtimes/common/src/types/trans_from_shim.rs index 07f1f8d79e..4d5d7ddf16 100644 --- a/src/runtime-rs/crates/runtimes/common/src/types/trans_from_shim.rs +++ b/src/runtime-rs/crates/runtimes/common/src/types/trans_from_shim.rs @@ -4,19 +4,17 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::{ - convert::{From, TryFrom}, - path::PathBuf, -}; - -use anyhow::{Context, Result}; -use containerd_shim_protos::api; -use kata_types::mount::Mount; - use super::{ ContainerConfig, ContainerID, ContainerProcess, ExecProcessRequest, KillRequest, Request, ResizePTYRequest, ShutdownRequest, UpdateRequest, }; +use anyhow::{Context, Result}; +use containerd_shim_protos::api; +use kata_types::mount::Mount; +use std::{ + convert::{From, TryFrom}, + path::PathBuf, +}; fn trans_from_shim_mount(from: api::Mount) -> Mount { let options = from.options.to_vec(); @@ -42,6 +40,11 @@ fn trans_from_shim_mount(from: api::Mount) -> Mount { impl TryFrom for Request { type Error = anyhow::Error; fn try_from(from: api::CreateTaskRequest) -> Result { + let options = if from.has_options() { + Some(from.get_options().get_value().to_vec()) + } else { + None + }; Ok(Request::CreateContainer(ContainerConfig { container_id: from.id.clone(), bundle: from.bundle.clone(), @@ -52,6 +55,7 @@ impl TryFrom for Request { .map(trans_from_shim_mount) .collect(), terminal: from.terminal, + options, stdin: (!from.stdin.is_empty()).then(|| from.stdin.clone()), stdout: (!from.stdout.is_empty()).then(|| from.stdout.clone()), stderr: (!from.stderr.is_empty()).then(|| from.stderr.clone()), diff --git a/src/runtime-rs/crates/runtimes/src/manager.rs b/src/runtime-rs/crates/runtimes/src/manager.rs index 390cbac159..3d6fa567b5 100644 --- a/src/runtime-rs/crates/runtimes/src/manager.rs +++ b/src/runtime-rs/crates/runtimes/src/manager.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::sync::Arc; +use std::{str::from_utf8, sync::Arc}; use anyhow::{anyhow, Context, Result}; @@ -74,7 +74,7 @@ impl RuntimeHandlerManagerInner { Ok(()) } - async fn try_init(&mut self, spec: &oci::Spec) -> Result<()> { + async fn try_init(&mut self, spec: &oci::Spec, options: &Option>) -> Result<()> { // return if runtime instance has init if self.runtime_instance.is_some() { return Ok(()); @@ -104,7 +104,7 @@ impl RuntimeHandlerManagerInner { None }; - let config = load_config(spec).context("load config")?; + let config = load_config(spec, options).context("load config")?; self.init_runtime_handler(netns, Arc::new(config)) .await .context("init runtime handler")?; @@ -172,9 +172,13 @@ impl RuntimeHandlerManager { .ok_or_else(|| anyhow!("runtime not ready")) } - async fn try_init_runtime_instance(&self, spec: &oci::Spec) -> Result<()> { + async fn try_init_runtime_instance( + &self, + spec: &oci::Spec, + options: &Option>, + ) -> Result<()> { let mut inner = self.inner.write().await; - inner.try_init(spec).await + inner.try_init(spec, options).await } pub async fn handler_message(&self, req: Request) -> Result { @@ -183,7 +187,7 @@ impl RuntimeHandlerManager { let bundler_path = format!("{}/{}", req.bundle, oci::OCI_SPEC_CONFIG_FILE_NAME); let spec = oci::Spec::load(&bundler_path).context("load spec")?; - self.try_init_runtime_instance(&spec) + self.try_init_runtime_instance(&spec, &req.options) .await .context("try init runtime instance")?; let instance = self @@ -298,13 +302,21 @@ impl RuntimeHandlerManager { /// 2. shimv2 create task option /// TODO: https://github.com/kata-containers/kata-containers/issues/3961 /// 3. environment -fn load_config(spec: &oci::Spec) -> Result { +fn load_config(spec: &oci::Spec, option: &Option>) -> Result { const KATA_CONF_FILE: &str = "KATA_CONF_FILE"; let annotation = Annotation::new(spec.annotations.clone()); let config_path = if let Some(path) = annotation.get_sandbox_config_path() { path } else if let Ok(path) = std::env::var(KATA_CONF_FILE) { path + } else if let Some(option) = option { + // get rid of the special characters in options to get the config path + let path = if option.len() > 2 { + from_utf8(&option[2..])?.to_string() + } else { + String::from("") + }; + path } else { String::from("") };