mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
runtime-rs: add the missing default trait
Some structs in the runtime-rs don't implement Default trait. This commit adds the missing Default. Fixes: #5463 Signed-off-by: Li Hongyu <lihongyu1999@bupt.edu.cn>
This commit is contained in:
parent
7566a7eae4
commit
844bf053b2
@ -9,14 +9,16 @@ use crate::config::{ConfigOps, TomlConfig};
|
||||
|
||||
pub use vendor::AgentVendor;
|
||||
|
||||
use super::default::{DEFAULT_AGENT_LOG_PORT, DEFAULT_AGENT_VSOCK_PORT};
|
||||
use super::default::{
|
||||
DEFAULT_AGENT_DIAL_TIMEOUT_MS, DEFAULT_AGENT_LOG_PORT, DEFAULT_AGENT_VSOCK_PORT,
|
||||
};
|
||||
use crate::eother;
|
||||
|
||||
/// agent name of Kata agent.
|
||||
pub const AGENT_NAME_KATA: &str = "kata";
|
||||
|
||||
/// Kata agent configuration information.
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct Agent {
|
||||
/// If enabled, the agent will log additional debug messages to the system log.
|
||||
#[serde(default, rename = "enable_debug")]
|
||||
@ -81,6 +83,24 @@ pub struct Agent {
|
||||
pub container_pipe_size: u32,
|
||||
}
|
||||
|
||||
impl std::default::Default for Agent {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
debug: true,
|
||||
enable_tracing: false,
|
||||
debug_console_enabled: false,
|
||||
server_port: DEFAULT_AGENT_VSOCK_PORT,
|
||||
log_port: DEFAULT_AGENT_LOG_PORT,
|
||||
dial_timeout_ms: DEFAULT_AGENT_DIAL_TIMEOUT_MS,
|
||||
reconnect_timeout_ms: 3_000,
|
||||
request_timeout_ms: 30_000,
|
||||
health_check_request_timeout_ms: 90_000,
|
||||
kernel_modules: Default::default(),
|
||||
container_pipe_size: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_server_port() -> u32 {
|
||||
DEFAULT_AGENT_VSOCK_PORT
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ pub const DEFAULT_AGENT_VSOCK_PORT: u32 = 1024;
|
||||
pub const DEFAULT_AGENT_LOG_PORT: u32 = 1025;
|
||||
pub const DEFAULT_AGENT_DBG_CONSOLE_PORT: u32 = 1026;
|
||||
pub const DEFAULT_AGENT_TYPE_NAME: &str = AGENT_NAME_KATA;
|
||||
pub const DEFAULT_AGENT_DIAL_TIMEOUT_MS: u32 = 10;
|
||||
|
||||
pub const DEFAULT_RUNTIME_NAME: &str = RUNTIME_NAME_VIRTCONTAINER;
|
||||
pub const DEFAULT_HYPERVISOR: &str = HYPERVISOR_NAME_DRAGONBALL;
|
||||
|
@ -9,6 +9,8 @@ use std::convert::TryFrom;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const DEFAULT_REMOVE_CONTAINER_REQUEST_TIMEOUT: u32 = 10;
|
||||
|
||||
#[derive(PartialEq, Clone, Default)]
|
||||
pub struct Empty {}
|
||||
|
||||
@ -164,7 +166,7 @@ impl ContainerProcessID {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Default)]
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
pub struct RemoveContainerRequest {
|
||||
pub container_id: String,
|
||||
pub timeout: u32,
|
||||
@ -179,6 +181,15 @@ impl RemoveContainerRequest {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for RemoveContainerRequest {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
container_id: "".to_string(),
|
||||
timeout: DEFAULT_REMOVE_CONTAINER_REQUEST_TIMEOUT,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Default)]
|
||||
pub struct SignalProcessRequest {
|
||||
pub process_id: ContainerProcessID,
|
||||
|
@ -164,9 +164,12 @@ impl ContainerInner {
|
||||
let exit_status = self.get_exit_status().await;
|
||||
let _locked_exit_status = exit_status.read().await;
|
||||
info!(self.logger, "container terminated");
|
||||
let timeout: u32 = 10;
|
||||
let remove_request = agent::RemoveContainerRequest {
|
||||
container_id: cid.to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
self.agent
|
||||
.remove_container(agent::RemoveContainerRequest::new(cid, timeout))
|
||||
.remove_container(remove_request)
|
||||
.await
|
||||
.or_else(|e| {
|
||||
if force {
|
||||
|
@ -18,10 +18,7 @@ use common::{
|
||||
use containerd_shim_protos::events::task::TaskOOM;
|
||||
use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL};
|
||||
use kata_sys_util::hooks::HookStates;
|
||||
use kata_types::config::{
|
||||
default::{DEFAULT_AGENT_LOG_PORT, DEFAULT_AGENT_VSOCK_PORT},
|
||||
TomlConfig,
|
||||
};
|
||||
use kata_types::config::TomlConfig;
|
||||
use resource::{
|
||||
manager::ManagerArgs,
|
||||
network::{NetworkConfig, NetworkWithNetNsConfig},
|
||||
@ -380,19 +377,7 @@ impl Persist for VirtSandbox {
|
||||
HYPERVISOR_DRAGONBALL => Ok(Arc::new(Dragonball::restore((), h).await?)),
|
||||
_ => Err(anyhow!("Unsupported hypervisor {}", &h.hypervisor_type)),
|
||||
}?;
|
||||
let agent = Arc::new(KataAgent::new(kata_types::config::Agent {
|
||||
debug: true,
|
||||
enable_tracing: false,
|
||||
server_port: DEFAULT_AGENT_VSOCK_PORT,
|
||||
log_port: DEFAULT_AGENT_LOG_PORT,
|
||||
dial_timeout_ms: 10,
|
||||
reconnect_timeout_ms: 3_000,
|
||||
request_timeout_ms: 30_000,
|
||||
health_check_request_timeout_ms: 90_000,
|
||||
kernel_modules: Default::default(),
|
||||
container_pipe_size: 0,
|
||||
debug_console_enabled: false,
|
||||
}));
|
||||
let agent = Arc::new(KataAgent::new(kata_types::config::Agent::default()));
|
||||
let sid = sandbox_args.sid;
|
||||
let args = ManagerArgs {
|
||||
sid: sid.clone(),
|
||||
|
@ -117,12 +117,11 @@ mod tests {
|
||||
result: Result<()>,
|
||||
}
|
||||
|
||||
let default_id = "1dfc0567".to_string();
|
||||
let default_namespace = "ns1".to_string();
|
||||
let default_id = "default_id".to_string();
|
||||
let default_namespace = "default_namespace".to_string();
|
||||
let default_address = bind_address.to_string();
|
||||
let default_publish_binary = "containerd".to_string();
|
||||
let default_bundle = path.to_string();
|
||||
let default_debug = false;
|
||||
|
||||
let mut arg = Args {
|
||||
id: default_id.clone(),
|
||||
@ -130,7 +129,7 @@ mod tests {
|
||||
address: default_address.clone(),
|
||||
publish_binary: default_publish_binary.clone(),
|
||||
bundle: default_bundle.clone(),
|
||||
debug: default_debug,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let tests = &[
|
||||
|
@ -93,12 +93,12 @@ mod tests {
|
||||
std::env::set_current_dir(bundle_path).unwrap();
|
||||
|
||||
let args = Args {
|
||||
id: "1dfc0567".to_string(),
|
||||
namespace: "test_namespace".into(),
|
||||
address: "containerd_socket".into(),
|
||||
id: "default_id".into(),
|
||||
namespace: "default_namespace".into(),
|
||||
address: "default_address".into(),
|
||||
publish_binary: "containerd".into(),
|
||||
bundle: bundle_path.to_str().unwrap().into(),
|
||||
debug: false,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let executor = ShimExecutor::new(args);
|
||||
|
@ -153,12 +153,12 @@ mod tests {
|
||||
std::env::set_current_dir(bundle_path).unwrap();
|
||||
|
||||
let args = Args {
|
||||
id: "sandbox1".into(),
|
||||
namespace: "ns".into(),
|
||||
address: "address".into(),
|
||||
id: "default_id".into(),
|
||||
namespace: "default_namespace".into(),
|
||||
address: "default_address".into(),
|
||||
publish_binary: "containerd".into(),
|
||||
bundle: bundle_path.to_str().unwrap().into(),
|
||||
debug: false,
|
||||
..Default::default()
|
||||
};
|
||||
let mut executor = ShimExecutor::new(args);
|
||||
|
||||
@ -185,11 +185,11 @@ mod tests {
|
||||
|
||||
let args = Args {
|
||||
id: sandbox_id.to_owned(),
|
||||
namespace: "ns1".into(),
|
||||
address: "containerd_socket".into(),
|
||||
namespace: "default_namespace".into(),
|
||||
address: "default_address".into(),
|
||||
publish_binary: "containerd".into(),
|
||||
bundle: bundle_path.to_str().unwrap().into(),
|
||||
debug: false,
|
||||
..Default::default()
|
||||
};
|
||||
let executor = ShimExecutor::new(args);
|
||||
|
||||
@ -204,11 +204,11 @@ mod tests {
|
||||
|
||||
let args = Args {
|
||||
id: container_id,
|
||||
namespace: "ns1".into(),
|
||||
address: "containerd_socket".into(),
|
||||
namespace: "default_namespace".into(),
|
||||
address: "default_address".into(),
|
||||
publish_binary: "containerd".into(),
|
||||
bundle: bundle_path2.to_str().unwrap().into(),
|
||||
debug: false,
|
||||
..Default::default()
|
||||
};
|
||||
let executor2 = ShimExecutor::new(args);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user