krata: improvements to event handling during reconciliation

This commit is contained in:
Alex Zenla
2024-03-14 23:29:07 +00:00
parent 9bbf8420f2
commit 31a43f9108
9 changed files with 156 additions and 127 deletions

View File

@ -191,11 +191,10 @@ impl ControlService for RuntimeControlService {
.into());
};
let request = request?;
let mut console = self
.runtime
.console(&request.guest_id)
.await
.map_err(ApiError::from)?;
let uuid = Uuid::from_str(&request.guest_id).map_err(|error| ApiError {
message: error.to_string(),
})?;
let mut console = self.runtime.console(uuid).await.map_err(ApiError::from)?;
let output = try_stream! {
let mut buffer: Vec<u8> = vec![0u8; 256];

View File

@ -1,10 +1,7 @@
use std::{collections::HashMap, time::Duration};
use anyhow::Result;
use krata::{
common::{GuestExitInfo, GuestState, GuestStatus},
control::watch_events_reply::Event,
};
use krata::common::{GuestExitInfo, GuestState, GuestStatus};
use log::error;
use tokio::{
sync::{broadcast, mpsc::Sender},
@ -42,7 +39,7 @@ pub struct DaemonEventGenerator {
guests: GuestStore,
guest_reconciler_notify: Sender<Uuid>,
last: HashMap<Uuid, GuestInfo>,
_sender: broadcast::Sender<Event>,
_sender: broadcast::Sender<DaemonEvent>,
}
impl DaemonEventGenerator {

View File

@ -107,12 +107,8 @@ impl GuestReconciler {
}))?;
let result = match guest.state.as_ref().map(|x| x.status()).unwrap_or_default() {
GuestStatus::Start => self.start(uuid, guest).await.map(|_| true),
GuestStatus::Destroy | GuestStatus::Exited => {
self.destroy(uuid, guest).await.map(|_| true)
}
GuestStatus::Start => self.start(uuid, guest).await,
GuestStatus::Destroy | GuestStatus::Exited => self.destroy(uuid, guest).await,
_ => Ok(false),
};
@ -149,7 +145,7 @@ impl GuestReconciler {
Ok(())
}
async fn start(&self, uuid: Uuid, guest: &mut Guest) -> Result<()> {
async fn start(&self, uuid: Uuid, guest: &mut Guest) -> Result<bool> {
let Some(ref spec) = guest.spec else {
return Err(anyhow!("guest spec not specified"));
};
@ -191,11 +187,11 @@ impl GuestReconciler {
exit_info: None,
error_info: None,
});
Ok(())
Ok(true)
}
async fn destroy(&self, uuid: Uuid, guest: &mut Guest) -> Result<()> {
self.runtime.destroy(&uuid.to_string()).await?;
async fn destroy(&self, uuid: Uuid, guest: &mut Guest) -> Result<bool> {
self.runtime.destroy(uuid).await?;
info!("destroyed guest {}", uuid);
guest.network = None;
guest.state = Some(GuestState {
@ -203,7 +199,7 @@ impl GuestReconciler {
exit_info: None,
error_info: None,
});
Ok(())
Ok(true)
}
}