mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
runtime-rs: impl volume-stats trait for sandbox
Implements get-volume-stats trait for sandbox, handler for shim-mgmt and add RPC calls to agent. Also added type conversions in trans.rs Fixes #5369 Signed-off-by: Tingzhou Yuan <tzyuan15@bu.edu>
This commit is contained in:
parent
7566a7eae4
commit
42b8867148
1
src/runtime-rs/Cargo.lock
generated
1
src/runtime-rs/Cargo.lock
generated
@ -2470,6 +2470,7 @@ dependencies = [
|
|||||||
"slog",
|
"slog",
|
||||||
"slog-scope",
|
"slog-scope",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"url",
|
||||||
"virt_container",
|
"virt_container",
|
||||||
"wasm_container",
|
"wasm_container",
|
||||||
]
|
]
|
||||||
|
@ -115,5 +115,6 @@ impl_agent!(
|
|||||||
copy_file | crate::CopyFileRequest | crate::Empty | None,
|
copy_file | crate::CopyFileRequest | crate::Empty | None,
|
||||||
get_oom_event | crate::Empty | crate::OomEventResponse | Some(0),
|
get_oom_event | crate::Empty | crate::OomEventResponse | Some(0),
|
||||||
get_ip_tables | crate::GetIPTablesRequest | crate::GetIPTablesResponse | None,
|
get_ip_tables | crate::GetIPTablesRequest | crate::GetIPTablesResponse | None,
|
||||||
set_ip_tables | crate::SetIPTablesRequest | crate::SetIPTablesResponse | None
|
set_ip_tables | crate::SetIPTablesRequest | crate::SetIPTablesResponse | None,
|
||||||
|
get_volume_stats | crate::VolumeStatsRequest | crate::VolumeStatsResponse | None
|
||||||
);
|
);
|
||||||
|
@ -8,7 +8,7 @@ use std::convert::Into;
|
|||||||
|
|
||||||
use protocols::{
|
use protocols::{
|
||||||
agent::{self, OOMEvent},
|
agent::{self, OOMEvent},
|
||||||
empty, health, types,
|
csi, empty, health, types,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -24,7 +24,7 @@ use crate::{
|
|||||||
SetGuestDateTimeRequest, SetIPTablesRequest, SetIPTablesResponse, SignalProcessRequest,
|
SetGuestDateTimeRequest, SetIPTablesRequest, SetIPTablesResponse, SignalProcessRequest,
|
||||||
StatsContainerResponse, Storage, StringUser, ThrottlingData, TtyWinResizeRequest,
|
StatsContainerResponse, Storage, StringUser, ThrottlingData, TtyWinResizeRequest,
|
||||||
UpdateContainerRequest, UpdateInterfaceRequest, UpdateRoutesRequest, VersionCheckResponse,
|
UpdateContainerRequest, UpdateInterfaceRequest, UpdateRoutesRequest, VersionCheckResponse,
|
||||||
WaitProcessRequest, WriteStreamRequest,
|
VolumeStatsRequest, VolumeStatsResponse, WaitProcessRequest, WriteStreamRequest,
|
||||||
},
|
},
|
||||||
OomEventResponse, WaitProcessResponse, WriteStreamResponse,
|
OomEventResponse, WaitProcessResponse, WriteStreamResponse,
|
||||||
};
|
};
|
||||||
@ -846,3 +846,24 @@ impl From<agent::OOMEvent> for OomEventResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<VolumeStatsRequest> for agent::VolumeStatsRequest {
|
||||||
|
fn from(from: VolumeStatsRequest) -> Self {
|
||||||
|
Self {
|
||||||
|
volume_guest_path: from.volume_guest_path,
|
||||||
|
unknown_fields: Default::default(),
|
||||||
|
cached_size: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<csi::VolumeStatsResponse> for VolumeStatsResponse {
|
||||||
|
fn from(from: csi::VolumeStatsResponse) -> Self {
|
||||||
|
let result: String = format!(
|
||||||
|
"Usage: {:?}\nVolume Condition: {:?}",
|
||||||
|
from.get_usage(),
|
||||||
|
from.get_volume_condition()
|
||||||
|
);
|
||||||
|
Self { data: result }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,8 +23,8 @@ pub use types::{
|
|||||||
ReseedRandomDevRequest, ResizeVolumeRequest, Route, Routes, SetGuestDateTimeRequest,
|
ReseedRandomDevRequest, ResizeVolumeRequest, Route, Routes, SetGuestDateTimeRequest,
|
||||||
SetIPTablesRequest, SetIPTablesResponse, SignalProcessRequest, StatsContainerResponse, Storage,
|
SetIPTablesRequest, SetIPTablesResponse, SignalProcessRequest, StatsContainerResponse, Storage,
|
||||||
TtyWinResizeRequest, UpdateContainerRequest, UpdateInterfaceRequest, UpdateRoutesRequest,
|
TtyWinResizeRequest, UpdateContainerRequest, UpdateInterfaceRequest, UpdateRoutesRequest,
|
||||||
VersionCheckResponse, WaitProcessRequest, WaitProcessResponse, WriteStreamRequest,
|
VersionCheckResponse, VolumeStatsRequest, VolumeStatsResponse, WaitProcessRequest,
|
||||||
WriteStreamResponse,
|
WaitProcessResponse, WriteStreamRequest, WriteStreamResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@ -88,4 +88,5 @@ pub trait Agent: AgentManager + HealthService + Send + Sync {
|
|||||||
async fn get_oom_event(&self, req: Empty) -> Result<OomEventResponse>;
|
async fn get_oom_event(&self, req: Empty) -> Result<OomEventResponse>;
|
||||||
async fn get_ip_tables(&self, req: GetIPTablesRequest) -> Result<GetIPTablesResponse>;
|
async fn get_ip_tables(&self, req: GetIPTablesRequest) -> Result<GetIPTablesResponse>;
|
||||||
async fn set_ip_tables(&self, req: SetIPTablesRequest) -> Result<SetIPTablesResponse>;
|
async fn set_ip_tables(&self, req: SetIPTablesRequest) -> Result<SetIPTablesResponse>;
|
||||||
|
async fn get_volume_stats(&self, req: VolumeStatsRequest) -> Result<VolumeStatsResponse>;
|
||||||
}
|
}
|
||||||
|
@ -568,6 +568,16 @@ pub struct ResizeVolumeRequest {
|
|||||||
pub size: u64,
|
pub size: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Clone, Default, Debug)]
|
||||||
|
pub struct VolumeStatsRequest {
|
||||||
|
pub volume_guest_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Clone, Default, Debug)]
|
||||||
|
pub struct VolumeStatsResponse {
|
||||||
|
pub data: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
@ -26,4 +26,5 @@ pub trait Sandbox: Send + Sync {
|
|||||||
// utils
|
// utils
|
||||||
async fn set_iptables(&self, is_ipv6: bool, data: Vec<u8>) -> Result<Vec<u8>>;
|
async fn set_iptables(&self, is_ipv6: bool, data: Vec<u8>) -> Result<Vec<u8>>;
|
||||||
async fn get_iptables(&self, is_ipv6: bool) -> Result<Vec<u8>>;
|
async fn get_iptables(&self, is_ipv6: bool) -> Result<Vec<u8>>;
|
||||||
|
async fn direct_volume_stats(&self, volume_path: &str) -> Result<String>;
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,9 @@ use anyhow::{anyhow, Result};
|
|||||||
use common::Sandbox;
|
use common::Sandbox;
|
||||||
use hyper::{Body, Method, Request, Response, StatusCode};
|
use hyper::{Body, Method, Request, Response, StatusCode};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use shim_interface::shim_mgmt::{AGENT_URL, IP6_TABLE_URL, IP_TABLE_URL};
|
use shim_interface::shim_mgmt::{AGENT_URL, IP6_TABLE_URL, IP_TABLE_URL, DIRECT_VOLUMN_PATH_KEY, DIRECT_VOLUMN_STATS_URL,};
|
||||||
|
|
||||||
// main router for response, this works as a multiplexer on
|
// main router for response, this works as a multiplexer on
|
||||||
// http arrival which invokes the corresponding handler function
|
// http arrival which invokes the corresponding handler function
|
||||||
@ -34,6 +35,7 @@ pub(crate) async fn handler_mux(
|
|||||||
(&Method::PUT, IP6_TABLE_URL) | (&Method::GET, IP6_TABLE_URL) => {
|
(&Method::PUT, IP6_TABLE_URL) | (&Method::GET, IP6_TABLE_URL) => {
|
||||||
ipv6_table_handler(sandbox, req).await
|
ipv6_table_handler(sandbox, req).await
|
||||||
}
|
}
|
||||||
|
(&Method::POST, DIRECT_VOLUMN_STATS_URL) => direct_volume_stats_handler(sandbox, req).await,
|
||||||
_ => Ok(not_found(req).await),
|
_ => Ok(not_found(req).await),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,3 +103,24 @@ async fn generic_ip_table_handler(
|
|||||||
_ => Err(anyhow!("IP Tables only takes PUT and GET")),
|
_ => Err(anyhow!("IP Tables only takes PUT and GET")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn direct_volume_stats_handler(
|
||||||
|
sandbox: Arc<dyn Sandbox>,
|
||||||
|
req: Request<Body>,
|
||||||
|
) -> Result<Response<Body>> {
|
||||||
|
let params = Url::parse(&req.uri().to_string())
|
||||||
|
.unwrap()
|
||||||
|
.query_pairs()
|
||||||
|
.into_owned()
|
||||||
|
.collect::<std::collections::HashMap<String, String>>();
|
||||||
|
let volume_path = params.get(DIRECT_VOLUMN_PATH_KEY).unwrap();
|
||||||
|
let result = sandbox.direct_volume_stats(volume_path).await;
|
||||||
|
match result {
|
||||||
|
Ok(stats) => Ok(Response::new(Body::from(stats))),
|
||||||
|
Err(e) => {
|
||||||
|
let builder = Response::builder().status(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
let resp = builder.body(Body::from(e.to_string())).unwrap();
|
||||||
|
Ok(resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,6 +8,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use agent::{
|
use agent::{
|
||||||
self, kata::KataAgent, types::KernelModule, Agent, GetIPTablesRequest, SetIPTablesRequest,
|
self, kata::KataAgent, types::KernelModule, Agent, GetIPTablesRequest, SetIPTablesRequest,
|
||||||
|
VolumeStatsRequest,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@ -329,6 +330,14 @@ impl Sandbox for VirtSandbox {
|
|||||||
self.agent.agent_sock().await
|
self.agent.agent_sock().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn direct_volume_stats(&self, volume_guest_path: &str) -> Result<String> {
|
||||||
|
let req: agent::VolumeStatsRequest = VolumeStatsRequest {
|
||||||
|
volume_guest_path: volume_guest_path.to_string(),
|
||||||
|
};
|
||||||
|
let result = self.agent.get_volume_stats(req).await?.data;
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
async fn set_iptables(&self, is_ipv6: bool, data: Vec<u8>) -> Result<Vec<u8>> {
|
async fn set_iptables(&self, is_ipv6: bool, data: Vec<u8>) -> Result<Vec<u8>> {
|
||||||
info!(sl!(), "sb: set_iptables invoked");
|
info!(sl!(), "sb: set_iptables invoked");
|
||||||
let req = SetIPTablesRequest { is_ipv6, data };
|
let req = SetIPTablesRequest { is_ipv6, data };
|
||||||
|
Loading…
Reference in New Issue
Block a user