-
Notifications
You must be signed in to change notification settings - Fork 21
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
WIP: Add support for pinned sb implementation #135
Open
mrunalp
wants to merge
1
commit into
containers:master
Choose a base branch
from
mrunalp:pinned_sb_impl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,69 @@ | ||||||||||||||
//! A pod sandbox implementation which does pin it's namespaces to file descriptors. | ||||||||||||||
//! A pod sandbox implementation which does pin its namespaces to file descriptors. | ||||||||||||||
|
||||||||||||||
use crate::sandbox::Pod; | ||||||||||||||
use crate::sandbox::{LinuxNamespaces, Pod, SandboxData}; | ||||||||||||||
use async_trait::async_trait; | ||||||||||||||
use anyhow::{bail, Context, Result}; | ||||||||||||||
use tokio::process::Command; | ||||||||||||||
use which::which; | ||||||||||||||
use std::path::PathBuf; | ||||||||||||||
|
||||||||||||||
#[derive(Default)] | ||||||||||||||
pub struct PinnedSandbox {} | ||||||||||||||
pub struct PinnedSandbox { | ||||||||||||||
pinner_path: PathBuf, | ||||||||||||||
namespaces_dir: String, | ||||||||||||||
ready: bool, | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
impl Pod for PinnedSandbox {} | ||||||||||||||
impl PinnedSandbox { | ||||||||||||||
pub fn new(pinner: &str) -> Result<PinnedSandbox> { | ||||||||||||||
let path = which(pinner) | ||||||||||||||
.with_context(|| format!("failed to find {} in PATH", pinner))?; | ||||||||||||||
let ps = PinnedSandbox { | ||||||||||||||
pinner_path: path, | ||||||||||||||
// TODO: Make this configurable | ||||||||||||||
namespaces_dir: String::from("/var/run/cri"), | ||||||||||||||
ready: false, | ||||||||||||||
}; | ||||||||||||||
Ok(ps) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#[async_trait] | ||||||||||||||
impl Pod for PinnedSandbox { | ||||||||||||||
async fn run(&mut self, sd: &SandboxData) -> Result<()> { | ||||||||||||||
let mut args = Vec::new(); | ||||||||||||||
args.push("-d"); | ||||||||||||||
args.push(&self.namespaces_dir); | ||||||||||||||
args.push("-f"); | ||||||||||||||
args.push(&sd.id); | ||||||||||||||
Comment on lines
+34
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
let linux_namespaces = sd.linux_namespaces.context("linux namespaces not set")?; | ||||||||||||||
if linux_namespaces.contains(LinuxNamespaces::NET) { | ||||||||||||||
args.push("-n"); | ||||||||||||||
} | ||||||||||||||
if linux_namespaces.contains(LinuxNamespaces::IPC) { | ||||||||||||||
args.push("-i"); | ||||||||||||||
} | ||||||||||||||
if linux_namespaces.contains(LinuxNamespaces::UTS) { | ||||||||||||||
args.push("-u"); | ||||||||||||||
} | ||||||||||||||
let output = Command::new(&self.pinner_path).args(&args[..]).output().await?; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
if !output.status.success() { | ||||||||||||||
bail!("Failed to pin namespaces for sandbox") | ||||||||||||||
} | ||||||||||||||
self.ready = true; | ||||||||||||||
Ok(()) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
fn stop(&mut self, _: &SandboxData) -> Result<()> { | ||||||||||||||
self.ready = false; | ||||||||||||||
Ok(()) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
fn remove(&mut self, _: &SandboxData) -> Result<()> { | ||||||||||||||
Ok(()) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
fn ready(&mut self, _: &SandboxData) -> Result<bool> { | ||||||||||||||
Ok(false) | ||||||||||||||
} | ||||||||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saschagrunert We want to be able to setup a PinnedSandbox::new and then use it in the Sandbox but that doesn't work so we may need to use trait objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, yes it might be the better approach to use trait objects here. 👍