diff --git a/src/libs/kata-types/src/config/agent.rs b/src/libs/kata-types/src/config/agent.rs new file mode 100644 index 000000000..69babf86c --- /dev/null +++ b/src/libs/kata-types/src/config/agent.rs @@ -0,0 +1,80 @@ +// Copyright (c) 2021 Alibaba Cloud +// +// SPDX-License-Identifier: Apache-2.0 +// + +use std::io::Result; + +use crate::config::{ConfigOps, TomlConfig}; + +pub use vendor::AgentVendor; + +/// Kata agent configuration information. +#[derive(Debug, Default, Deserialize, Serialize)] +pub struct Agent { + /// If enabled, the agent will log additional debug messages to the system log. + #[serde(default, rename = "enable_debug")] + pub debug: bool, + + /// Enable agent tracing. + /// + /// If enabled, the agent will generate OpenTelemetry trace spans. + /// # Notes: + /// - If the runtime also has tracing enabled, the agent spans will be associated with the + /// appropriate runtime parent span. + /// - If enabled, the runtime will wait for the container to shutdown, increasing the container + /// shutdown time slightly. + #[serde(default)] + pub enable_tracing: bool, + + /// Enable debug console. + /// If enabled, user can connect guest OS running inside hypervisor through + /// "kata-runtime exec " command + #[serde(default)] + pub debug_console_enabled: bool, + + /// Agent connection dialing timeout value in seconds + #[serde(default)] + pub dial_timeout: u32, + + /// Comma separated list of kernel modules and their parameters. + /// + /// These modules will be loaded in the guest kernel using modprobe(8). + /// The following example can be used to load two kernel modules with parameters: + /// - kernel_modules=["e1000e InterruptThrottleRate=3000,3000,3000 EEE=1", "i915 enable_ppgtt=0"] + /// The first word is considered as the module name and the rest as its parameters. + /// Container will not be started when: + /// - A kernel module is specified and the modprobe command is not installed in the guest + /// or it fails loading the module. + /// - The module is not available in the guest or it doesn't met the guest kernel + /// requirements, like architecture and version. + #[serde(default)] + pub kernel_modules: Vec, +} + +impl ConfigOps for Agent { + fn adjust_configuration(conf: &mut TomlConfig) -> Result<()> { + AgentVendor::adjust_configuration(conf)?; + Ok(()) + } + + fn validate(conf: &TomlConfig) -> Result<()> { + AgentVendor::validate(conf)?; + Ok(()) + } +} + +#[cfg(not(feature = "enable-vendor"))] +mod vendor { + use super::*; + + /// Vendor customization agent configuration. + #[derive(Debug, Default, Deserialize, Serialize)] + pub struct AgentVendor {} + + impl ConfigOps for AgentVendor {} +} + +#[cfg(feature = "enable-vendor")] +#[path = "agent_vendor.rs"] +mod vendor; diff --git a/src/libs/kata-types/src/config/agent_vendor.rs b/src/libs/kata-types/src/config/agent_vendor.rs new file mode 100644 index 000000000..62ce710d0 --- /dev/null +++ b/src/libs/kata-types/src/config/agent_vendor.rs @@ -0,0 +1,12 @@ +// Copyright (c) 2021 Alibaba Cloud +// +// SPDX-License-Identifier: Apache-2.0 +// + +use super::*; + +/// Vendor customization agent configuration. +#[derive(Debug, Default, Deserialize, Serialize)] +pub struct AgentVendor {} + +impl ConfigOps for AgentVendor {} diff --git a/src/libs/kata-types/src/config/default.rs b/src/libs/kata-types/src/config/default.rs index 722156206..a32975621 100644 --- a/src/libs/kata-types/src/config/default.rs +++ b/src/libs/kata-types/src/config/default.rs @@ -20,6 +20,8 @@ lazy_static! { ]; } +pub const DEFAULT_AGENT_NAME: &str = "kata"; + pub const DEFAULT_INTERNETWORKING_MODEL: &str = "tcfilter"; pub const DEFAULT_BLOCK_DEVICE_TYPE: &str = "virtio-blk"; diff --git a/src/libs/kata-types/src/config/mod.rs b/src/libs/kata-types/src/config/mod.rs index 70fd81a5d..12f42794d 100644 --- a/src/libs/kata-types/src/config/mod.rs +++ b/src/libs/kata-types/src/config/mod.rs @@ -14,6 +14,9 @@ use crate::{eother, sl}; /// Default configuration values. pub mod default; +mod agent; +pub use self::agent::{Agent, AgentVendor}; + mod hypervisor; pub use self::hypervisor::{ BootInfo, DragonballConfig, Hypervisor, QemuConfig, HYPERVISOR_NAME_DRAGONBALL, @@ -64,6 +67,9 @@ pub trait ConfigObjectOps { /// Kata configuration information. #[derive(Debug, Default, Deserialize, Serialize)] pub struct TomlConfig { + /// Configuration information for agents. + #[serde(default)] + pub agent: HashMap, /// Configuration information for hypervisors. #[serde(default)] pub hypervisor: HashMap, @@ -123,6 +129,7 @@ impl TomlConfig { Hypervisor::adjust_configuration(&mut config)?; Runtime::adjust_configuration(&mut config)?; + Agent::adjust_configuration(&mut config)?; info!(sl!(), "get kata config: {:?}", config); Ok(config) @@ -132,6 +139,7 @@ impl TomlConfig { pub fn validate(&self) -> Result<()> { Hypervisor::validate(self)?; Runtime::validate(self)?; + Agent::validate(self)?; Ok(()) } diff --git a/src/libs/kata-types/src/config/runtime.rs b/src/libs/kata-types/src/config/runtime.rs index 9784662f9..b4bd2466d 100644 --- a/src/libs/kata-types/src/config/runtime.rs +++ b/src/libs/kata-types/src/config/runtime.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 Alibaba Cloud +// Copyright (c) 2021 Alibaba Cloud // // SPDX-License-Identifier: Apache-2.0 //