mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 13:14:33 +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;
|
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;
|
use crate::eother;
|
||||||
|
|
||||||
/// agent name of Kata agent.
|
/// agent name of Kata agent.
|
||||||
pub const AGENT_NAME_KATA: &str = "kata";
|
pub const AGENT_NAME_KATA: &str = "kata";
|
||||||
|
|
||||||
/// Kata agent configuration information.
|
/// Kata agent configuration information.
|
||||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct Agent {
|
pub struct Agent {
|
||||||
/// If enabled, the agent will log additional debug messages to the system log.
|
/// If enabled, the agent will log additional debug messages to the system log.
|
||||||
#[serde(default, rename = "enable_debug")]
|
#[serde(default, rename = "enable_debug")]
|
||||||
@ -81,6 +83,24 @@ pub struct Agent {
|
|||||||
pub container_pipe_size: u32,
|
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 {
|
fn default_server_port() -> u32 {
|
||||||
DEFAULT_AGENT_VSOCK_PORT
|
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_LOG_PORT: u32 = 1025;
|
||||||
pub const DEFAULT_AGENT_DBG_CONSOLE_PORT: u32 = 1026;
|
pub const DEFAULT_AGENT_DBG_CONSOLE_PORT: u32 = 1026;
|
||||||
pub const DEFAULT_AGENT_TYPE_NAME: &str = AGENT_NAME_KATA;
|
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_RUNTIME_NAME: &str = RUNTIME_NAME_VIRTCONTAINER;
|
||||||
pub const DEFAULT_HYPERVISOR: &str = HYPERVISOR_NAME_DRAGONBALL;
|
pub const DEFAULT_HYPERVISOR: &str = HYPERVISOR_NAME_DRAGONBALL;
|
||||||
|
@ -9,6 +9,8 @@ use std::convert::TryFrom;
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub const DEFAULT_REMOVE_CONTAINER_REQUEST_TIMEOUT: u32 = 10;
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Default)]
|
#[derive(PartialEq, Clone, Default)]
|
||||||
pub struct Empty {}
|
pub struct Empty {}
|
||||||
|
|
||||||
@ -164,7 +166,7 @@ impl ContainerProcessID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug, Default)]
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
pub struct RemoveContainerRequest {
|
pub struct RemoveContainerRequest {
|
||||||
pub container_id: String,
|
pub container_id: String,
|
||||||
pub timeout: u32,
|
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)]
|
#[derive(PartialEq, Clone, Default)]
|
||||||
pub struct SignalProcessRequest {
|
pub struct SignalProcessRequest {
|
||||||
pub process_id: ContainerProcessID,
|
pub process_id: ContainerProcessID,
|
||||||
|
@ -164,9 +164,12 @@ impl ContainerInner {
|
|||||||
let exit_status = self.get_exit_status().await;
|
let exit_status = self.get_exit_status().await;
|
||||||
let _locked_exit_status = exit_status.read().await;
|
let _locked_exit_status = exit_status.read().await;
|
||||||
info!(self.logger, "container terminated");
|
info!(self.logger, "container terminated");
|
||||||
let timeout: u32 = 10;
|
let remove_request = agent::RemoveContainerRequest {
|
||||||
|
container_id: cid.to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
self.agent
|
self.agent
|
||||||
.remove_container(agent::RemoveContainerRequest::new(cid, timeout))
|
.remove_container(remove_request)
|
||||||
.await
|
.await
|
||||||
.or_else(|e| {
|
.or_else(|e| {
|
||||||
if force {
|
if force {
|
||||||
|
@ -18,10 +18,7 @@ use common::{
|
|||||||
use containerd_shim_protos::events::task::TaskOOM;
|
use containerd_shim_protos::events::task::TaskOOM;
|
||||||
use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL};
|
use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL};
|
||||||
use kata_sys_util::hooks::HookStates;
|
use kata_sys_util::hooks::HookStates;
|
||||||
use kata_types::config::{
|
use kata_types::config::TomlConfig;
|
||||||
default::{DEFAULT_AGENT_LOG_PORT, DEFAULT_AGENT_VSOCK_PORT},
|
|
||||||
TomlConfig,
|
|
||||||
};
|
|
||||||
use resource::{
|
use resource::{
|
||||||
manager::ManagerArgs,
|
manager::ManagerArgs,
|
||||||
network::{NetworkConfig, NetworkWithNetNsConfig},
|
network::{NetworkConfig, NetworkWithNetNsConfig},
|
||||||
@ -380,19 +377,7 @@ impl Persist for VirtSandbox {
|
|||||||
HYPERVISOR_DRAGONBALL => Ok(Arc::new(Dragonball::restore((), h).await?)),
|
HYPERVISOR_DRAGONBALL => Ok(Arc::new(Dragonball::restore((), h).await?)),
|
||||||
_ => Err(anyhow!("Unsupported hypervisor {}", &h.hypervisor_type)),
|
_ => Err(anyhow!("Unsupported hypervisor {}", &h.hypervisor_type)),
|
||||||
}?;
|
}?;
|
||||||
let agent = Arc::new(KataAgent::new(kata_types::config::Agent {
|
let agent = Arc::new(KataAgent::new(kata_types::config::Agent::default()));
|
||||||
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 sid = sandbox_args.sid;
|
let sid = sandbox_args.sid;
|
||||||
let args = ManagerArgs {
|
let args = ManagerArgs {
|
||||||
sid: sid.clone(),
|
sid: sid.clone(),
|
||||||
|
@ -117,12 +117,11 @@ mod tests {
|
|||||||
result: Result<()>,
|
result: Result<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
let default_id = "1dfc0567".to_string();
|
let default_id = "default_id".to_string();
|
||||||
let default_namespace = "ns1".to_string();
|
let default_namespace = "default_namespace".to_string();
|
||||||
let default_address = bind_address.to_string();
|
let default_address = bind_address.to_string();
|
||||||
let default_publish_binary = "containerd".to_string();
|
let default_publish_binary = "containerd".to_string();
|
||||||
let default_bundle = path.to_string();
|
let default_bundle = path.to_string();
|
||||||
let default_debug = false;
|
|
||||||
|
|
||||||
let mut arg = Args {
|
let mut arg = Args {
|
||||||
id: default_id.clone(),
|
id: default_id.clone(),
|
||||||
@ -130,7 +129,7 @@ mod tests {
|
|||||||
address: default_address.clone(),
|
address: default_address.clone(),
|
||||||
publish_binary: default_publish_binary.clone(),
|
publish_binary: default_publish_binary.clone(),
|
||||||
bundle: default_bundle.clone(),
|
bundle: default_bundle.clone(),
|
||||||
debug: default_debug,
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let tests = &[
|
let tests = &[
|
||||||
|
@ -93,12 +93,12 @@ mod tests {
|
|||||||
std::env::set_current_dir(bundle_path).unwrap();
|
std::env::set_current_dir(bundle_path).unwrap();
|
||||||
|
|
||||||
let args = Args {
|
let args = Args {
|
||||||
id: "1dfc0567".to_string(),
|
id: "default_id".into(),
|
||||||
namespace: "test_namespace".into(),
|
namespace: "default_namespace".into(),
|
||||||
address: "containerd_socket".into(),
|
address: "default_address".into(),
|
||||||
publish_binary: "containerd".into(),
|
publish_binary: "containerd".into(),
|
||||||
bundle: bundle_path.to_str().unwrap().into(),
|
bundle: bundle_path.to_str().unwrap().into(),
|
||||||
debug: false,
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let executor = ShimExecutor::new(args);
|
let executor = ShimExecutor::new(args);
|
||||||
|
@ -153,12 +153,12 @@ mod tests {
|
|||||||
std::env::set_current_dir(bundle_path).unwrap();
|
std::env::set_current_dir(bundle_path).unwrap();
|
||||||
|
|
||||||
let args = Args {
|
let args = Args {
|
||||||
id: "sandbox1".into(),
|
id: "default_id".into(),
|
||||||
namespace: "ns".into(),
|
namespace: "default_namespace".into(),
|
||||||
address: "address".into(),
|
address: "default_address".into(),
|
||||||
publish_binary: "containerd".into(),
|
publish_binary: "containerd".into(),
|
||||||
bundle: bundle_path.to_str().unwrap().into(),
|
bundle: bundle_path.to_str().unwrap().into(),
|
||||||
debug: false,
|
..Default::default()
|
||||||
};
|
};
|
||||||
let mut executor = ShimExecutor::new(args);
|
let mut executor = ShimExecutor::new(args);
|
||||||
|
|
||||||
@ -185,11 +185,11 @@ mod tests {
|
|||||||
|
|
||||||
let args = Args {
|
let args = Args {
|
||||||
id: sandbox_id.to_owned(),
|
id: sandbox_id.to_owned(),
|
||||||
namespace: "ns1".into(),
|
namespace: "default_namespace".into(),
|
||||||
address: "containerd_socket".into(),
|
address: "default_address".into(),
|
||||||
publish_binary: "containerd".into(),
|
publish_binary: "containerd".into(),
|
||||||
bundle: bundle_path.to_str().unwrap().into(),
|
bundle: bundle_path.to_str().unwrap().into(),
|
||||||
debug: false,
|
..Default::default()
|
||||||
};
|
};
|
||||||
let executor = ShimExecutor::new(args);
|
let executor = ShimExecutor::new(args);
|
||||||
|
|
||||||
@ -204,11 +204,11 @@ mod tests {
|
|||||||
|
|
||||||
let args = Args {
|
let args = Args {
|
||||||
id: container_id,
|
id: container_id,
|
||||||
namespace: "ns1".into(),
|
namespace: "default_namespace".into(),
|
||||||
address: "containerd_socket".into(),
|
address: "default_address".into(),
|
||||||
publish_binary: "containerd".into(),
|
publish_binary: "containerd".into(),
|
||||||
bundle: bundle_path2.to_str().unwrap().into(),
|
bundle: bundle_path2.to_str().unwrap().into(),
|
||||||
debug: false,
|
..Default::default()
|
||||||
};
|
};
|
||||||
let executor2 = ShimExecutor::new(args);
|
let executor2 = ShimExecutor::new(args);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user