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-scope",
|
||||
"tokio",
|
||||
"url",
|
||||
"virt_container",
|
||||
"wasm_container",
|
||||
]
|
||||
|
@ -115,5 +115,6 @@ impl_agent!(
|
||||
copy_file | crate::CopyFileRequest | crate::Empty | None,
|
||||
get_oom_event | crate::Empty | crate::OomEventResponse | Some(0),
|
||||
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::{
|
||||
agent::{self, OOMEvent},
|
||||
empty, health, types,
|
||||
csi, empty, health, types,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -24,7 +24,7 @@ use crate::{
|
||||
SetGuestDateTimeRequest, SetIPTablesRequest, SetIPTablesResponse, SignalProcessRequest,
|
||||
StatsContainerResponse, Storage, StringUser, ThrottlingData, TtyWinResizeRequest,
|
||||
UpdateContainerRequest, UpdateInterfaceRequest, UpdateRoutesRequest, VersionCheckResponse,
|
||||
WaitProcessRequest, WriteStreamRequest,
|
||||
VolumeStatsRequest, VolumeStatsResponse, WaitProcessRequest, WriteStreamRequest,
|
||||
},
|
||||
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,
|
||||
SetIPTablesRequest, SetIPTablesResponse, SignalProcessRequest, StatsContainerResponse, Storage,
|
||||
TtyWinResizeRequest, UpdateContainerRequest, UpdateInterfaceRequest, UpdateRoutesRequest,
|
||||
VersionCheckResponse, WaitProcessRequest, WaitProcessResponse, WriteStreamRequest,
|
||||
WriteStreamResponse,
|
||||
VersionCheckResponse, VolumeStatsRequest, VolumeStatsResponse, WaitProcessRequest,
|
||||
WaitProcessResponse, WriteStreamRequest, WriteStreamResponse,
|
||||
};
|
||||
|
||||
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_ip_tables(&self, req: GetIPTablesRequest) -> Result<GetIPTablesResponse>;
|
||||
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,
|
||||
}
|
||||
|
||||
#[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)]
|
||||
mod test {
|
||||
use std::convert::TryFrom;
|
||||
|
@ -26,4 +26,5 @@ pub trait Sandbox: Send + Sync {
|
||||
// utils
|
||||
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 direct_volume_stats(&self, volume_path: &str) -> Result<String>;
|
||||
}
|
||||
|
@ -11,8 +11,9 @@ use anyhow::{anyhow, Result};
|
||||
use common::Sandbox;
|
||||
use hyper::{Body, Method, Request, Response, StatusCode};
|
||||
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
|
||||
// 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) => {
|
||||
ipv6_table_handler(sandbox, req).await
|
||||
}
|
||||
(&Method::POST, DIRECT_VOLUMN_STATS_URL) => direct_volume_stats_handler(sandbox, 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")),
|
||||
}
|
||||
}
|
||||
|
||||
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::{
|
||||
self, kata::KataAgent, types::KernelModule, Agent, GetIPTablesRequest, SetIPTablesRequest,
|
||||
VolumeStatsRequest,
|
||||
};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use async_trait::async_trait;
|
||||
@ -329,6 +330,14 @@ impl Sandbox for VirtSandbox {
|
||||
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>> {
|
||||
info!(sl!(), "sb: set_iptables invoked");
|
||||
let req = SetIPTablesRequest { is_ipv6, data };
|
||||
|
Loading…
Reference in New Issue
Block a user