Skip to content

Commit

Permalink
create and start containers one at a time
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Oct 4, 2023
1 parent 13fd9fb commit 1440c73
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions crates/containerd-shim-wasm/src/sandbox/shim/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::fs::create_dir_all;
use std::ops::Not;
use std::path::Path;
use std::sync::{Arc, RwLock};
use std::sync::{Arc, Mutex, RwLock};
use std::thread;
use std::time::Duration;

Expand Down Expand Up @@ -42,6 +42,7 @@ pub struct Local<T: Instance + Send + Sync, E: EventSender = RemoteEventSender>
exit: Arc<ExitSignal>,
namespace: String,
containerd_address: String,
mutex: Mutex<()>,
}

impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
Expand All @@ -56,13 +57,15 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
let instances = RwLock::default();
let namespace = namespace.as_ref().to_string();
let containerd_address = containerd_address.as_ref().to_string();
let mutex = Mutex::default();
Self {
engine,
instances,
events,
exit,
namespace,
containerd_address,
mutex,
}
}

Expand Down Expand Up @@ -148,12 +151,15 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
.set_stderr(&req.stderr);

// Check if this is a cri container
let instance = if self.is_empty() && is_cri_container(&spec) {
// If it is cri, then this is the "pause" container, which we don't need to deal with.
// TODO: maybe we can just go ahead and execute the actual container with runc?
InstanceData::new_base(req.id(), cfg)?
} else {
InstanceData::new_instance(req.id(), cfg)?
let instance = {
let _guard = self.mutex.lock();
if self.is_empty() && is_cri_container(&spec) {
// If it is cri, then this is the "pause" container, which we don't need to deal with.
// TODO: maybe we can just go ahead and execute the actual container with runc?
InstanceData::new_base(req.id(), cfg)?
} else {
InstanceData::new_instance(req.id(), cfg)?
}
};

self.instances
Expand Down Expand Up @@ -193,7 +199,10 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
}

let i = self.get_instance(req.id())?;
let pid = i.start()?;
let pid = {
let _guard = self.mutex.lock();
i.start()?
};

self.events.send(TaskStart {
container_id: req.id().into(),
Expand Down

0 comments on commit 1440c73

Please sign in to comment.