mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-02 05:34:46 +00:00
libs/types: support load Kata agent configuration from file
Add structures to load Kata agent configuration from configuration files. Also define a mechanism for vendor to extend the Kata configuration structure. Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This commit is contained in:
parent
69f10afb71
commit
387ffa914e
80
src/libs/kata-types/src/config/agent.rs
Normal file
80
src/libs/kata-types/src/config/agent.rs
Normal file
@ -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 <sandbox-id>" 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<String>,
|
||||
}
|
||||
|
||||
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;
|
12
src/libs/kata-types/src/config/agent_vendor.rs
Normal file
12
src/libs/kata-types/src/config/agent_vendor.rs
Normal file
@ -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 {}
|
@ -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";
|
||||
|
@ -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<String, Agent>,
|
||||
/// Configuration information for hypervisors.
|
||||
#[serde(default)]
|
||||
pub hypervisor: HashMap<String, Hypervisor>,
|
||||
@ -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(())
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2019-2021 Alibaba Cloud
|
||||
// Copyright (c) 2021 Alibaba Cloud
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user