Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Handle "mount" and "network" for LinuxNamespaceType #187

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/runtime/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,13 @@ impl TryFrom<&str> for LinuxNamespaceType {

fn try_from(namespace: &str) -> Result<Self, Self::Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I use the same way LinuxNamespace::try_from(ns_str)? in my project too.
Thx @utam0k @saschagrunert and the great project oci-spec-rs

match namespace {
"mnt" => Ok(LinuxNamespaceType::Mount),
"mnt" | "mount" => Ok(LinuxNamespaceType::Mount),
"cgroup" => Ok(LinuxNamespaceType::Cgroup),
"uts" => Ok(LinuxNamespaceType::Uts),
"ipc" => Ok(LinuxNamespaceType::Ipc),
"user" => Ok(LinuxNamespaceType::User),
"pid" => Ok(LinuxNamespaceType::Pid),
"net" => Ok(LinuxNamespaceType::Network),
"net" | "network" => Ok(LinuxNamespaceType::Network),
"time" => Ok(LinuxNamespaceType::Time),
_ => Err(oci_error(format!(
"unknown namespace {namespace}, could not convert"
Expand Down Expand Up @@ -1525,6 +1525,10 @@ mod tests {
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Network);

let nstype_str = "network";
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Network);

let nstype_str = "ipc";
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Ipc);
Expand All @@ -1533,7 +1537,11 @@ mod tests {
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Cgroup);

let invalid_nstype_str = "mount";
let nstype_str = "mount";
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Mount);

let invalid_nstype_str = "xxx";
let unknown_nstype = LinuxNamespaceType::try_from(invalid_nstype_str);
assert!(unknown_nstype.is_err());
}
Expand Down
Loading