Skip to content

Commit

Permalink
kata-types: add single_container support
Browse files Browse the repository at this point in the history
For now, only pod_sandbox and pod_container are supported. It doesn't cover
the case that container started by ctr which is a single_container defined
in kata 2.0. port the single_container kata type from kata 2.0 to kata 3.0.

Fixes: kata-containers#6006
Signed-off-by: Jianyong Wu <[email protected]>
  • Loading branch information
jongwu committed Jan 9, 2023
1 parent 2c10b37 commit 5f9c892
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libs/kata-sys-util/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn get_container_type(spec: &oci::Spec) -> Result<ContainerType, Error> {
pub fn get_shim_id_info() -> Result<ShimIdInfo, Error> {
let spec = load_oci_spec()?;
match get_container_type(&spec)? {
ContainerType::PodSandbox => Ok(ShimIdInfo::Sandbox),
ContainerType::PodSandbox | ContainerType::SingleContainer => Ok(ShimIdInfo::Sandbox),
ContainerType::PodContainer => {
for k in CRI_SANDBOX_ID_KEY_LIST {
if let Some(sandbox_id) = spec.annotations.get(*k) {
Expand Down
5 changes: 5 additions & 0 deletions src/libs/kata-types/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub(crate) const SANDBOX: &str = "sandbox";
// docker: a sandbox sandbox container
pub(crate) const PODSANDBOX: &str = "podsandbox";

pub(crate) const SINGLE_CONTAINER: &str = "single_container";

const STATE_READY: &str = "ready";
const STATE_RUNNING: &str = "running";
const STATE_STOPPED: &str = "stopped";
Expand All @@ -45,6 +47,8 @@ pub enum ContainerType {
PodContainer,
/// A pod sandbox.
PodSandbox,
/// A single container.
SingleContainer,
}

impl ContainerType {
Expand All @@ -64,6 +68,7 @@ impl Display for ContainerType {
match self {
ContainerType::PodContainer => write!(f, "{}", POD_CONTAINER),
ContainerType::PodSandbox => write!(f, "{}", POD_SANDBOX),
ContainerType::SingleContainer => write!(f, "{}", SINGLE_CONTAINER),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/kata-types/src/k8s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn container_type(spec: &oci::Spec) -> ContainerType {
}
}

ContainerType::PodSandbox
ContainerType::SingleContainer
}

/// Determine the k8s sandbox ID from OCI annotations.
Expand Down Expand Up @@ -269,7 +269,7 @@ mod tests {
// default
assert_eq!(
container_type_with_id(&spec),
(ContainerType::PodSandbox, None)
(ContainerType::SingleContainer, None)
);

// crio sandbox
Expand Down

0 comments on commit 5f9c892

Please sign in to comment.