mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 13:14:33 +00:00
agent: fix non_camel_case_types lint and stop hiding the warning
Fixes: #1359 Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
parent
8ffe4d6748
commit
f16ab49b5b
@ -27,7 +27,7 @@ const SERVER_ADDR_ENV_VAR: &str = "KATA_AGENT_SERVER_ADDR";
|
|||||||
const LOG_LEVEL_ENV_VAR: &str = "KATA_AGENT_LOG_LEVEL";
|
const LOG_LEVEL_ENV_VAR: &str = "KATA_AGENT_LOG_LEVEL";
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct agentConfig {
|
pub struct AgentConfig {
|
||||||
pub debug_console: bool,
|
pub debug_console: bool,
|
||||||
pub dev_mode: bool,
|
pub dev_mode: bool,
|
||||||
pub log_level: slog::Level,
|
pub log_level: slog::Level,
|
||||||
@ -69,9 +69,9 @@ macro_rules! parse_cmdline_param {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl agentConfig {
|
impl AgentConfig {
|
||||||
pub fn new() -> agentConfig {
|
pub fn new() -> AgentConfig {
|
||||||
agentConfig {
|
AgentConfig {
|
||||||
debug_console: false,
|
debug_console: false,
|
||||||
dev_mode: false,
|
dev_mode: false,
|
||||||
log_level: DEFAULT_LOG_LEVEL,
|
log_level: DEFAULT_LOG_LEVEL,
|
||||||
@ -311,7 +311,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new() {
|
fn test_new() {
|
||||||
let config = agentConfig::new();
|
let config = AgentConfig::new();
|
||||||
assert_eq!(config.debug_console, false);
|
assert_eq!(config.debug_console, false);
|
||||||
assert_eq!(config.dev_mode, false);
|
assert_eq!(config.dev_mode, false);
|
||||||
assert_eq!(config.log_level, DEFAULT_LOG_LEVEL);
|
assert_eq!(config.log_level, DEFAULT_LOG_LEVEL);
|
||||||
@ -818,7 +818,7 @@ mod tests {
|
|||||||
|
|
||||||
let filename = file_path.to_str().expect("failed to create filename");
|
let filename = file_path.to_str().expect("failed to create filename");
|
||||||
|
|
||||||
let mut config = agentConfig::new();
|
let mut config = AgentConfig::new();
|
||||||
let result = config.parse_cmdline(&filename.to_owned());
|
let result = config.parse_cmdline(&filename.to_owned());
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
|
|
||||||
@ -850,7 +850,7 @@ mod tests {
|
|||||||
vars_to_unset.push(name);
|
vars_to_unset.push(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut config = agentConfig::new();
|
let mut config = AgentConfig::new();
|
||||||
assert_eq!(config.debug_console, false, "{}", msg);
|
assert_eq!(config.debug_console, false, "{}", msg);
|
||||||
assert_eq!(config.dev_mode, false, "{}", msg);
|
assert_eq!(config.dev_mode, false, "{}", msg);
|
||||||
assert_eq!(config.unified_cgroup_hierarchy, false, "{}", msg);
|
assert_eq!(config.unified_cgroup_hierarchy, false, "{}", msg);
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
extern crate oci;
|
extern crate oci;
|
||||||
@ -83,11 +82,11 @@ const DEFAULT_BUF_SIZE: usize = 8 * 1024;
|
|||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref GLOBAL_DEVICE_WATCHER: Arc<Mutex<HashMap<String, Option<Sender<String>>>>> =
|
static ref GLOBAL_DEVICE_WATCHER: Arc<Mutex<HashMap<String, Option<Sender<String>>>>> =
|
||||||
Arc::new(Mutex::new(HashMap::new()));
|
Arc::new(Mutex::new(HashMap::new()));
|
||||||
static ref AGENT_CONFIG: Arc<RwLock<agentConfig>> =
|
static ref AGENT_CONFIG: Arc<RwLock<AgentConfig>> =
|
||||||
Arc::new(RwLock::new(config::agentConfig::new()));
|
Arc::new(RwLock::new(config::AgentConfig::new()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn announce(logger: &Logger, config: &agentConfig) {
|
fn announce(logger: &Logger, config: &AgentConfig) {
|
||||||
info!(logger, "announce";
|
info!(logger, "announce";
|
||||||
"agent-commit" => version::VERSION_COMMIT,
|
"agent-commit" => version::VERSION_COMMIT,
|
||||||
|
|
||||||
@ -247,7 +246,7 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_sandbox(logger: &Logger, config: &agentConfig, init_mode: bool) -> Result<()> {
|
async fn start_sandbox(logger: &Logger, config: &AgentConfig, init_mode: bool) -> Result<()> {
|
||||||
let shells = SHELLS.clone();
|
let shells = SHELLS.clone();
|
||||||
let debug_console_vport = config.debug_console_vport as u32;
|
let debug_console_vport = config.debug_console_vport as u32;
|
||||||
|
|
||||||
@ -446,7 +445,7 @@ lazy_static! {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::config::agentConfig;
|
use crate::config::AgentConfig;
|
||||||
use nix::sys::stat::Mode;
|
use nix::sys::stat::Mode;
|
||||||
use std::os::unix::io::{FromRawFd, RawFd};
|
use std::os::unix::io::{FromRawFd, RawFd};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -84,7 +84,7 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct INIT_MOUNT {
|
pub struct InitMount {
|
||||||
fstype: &'static str,
|
fstype: &'static str,
|
||||||
src: &'static str,
|
src: &'static str,
|
||||||
dest: &'static str,
|
dest: &'static str,
|
||||||
@ -114,13 +114,13 @@ lazy_static!{
|
|||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref INIT_ROOTFS_MOUNTS: Vec<INIT_MOUNT> = vec![
|
pub static ref INIT_ROOTFS_MOUNTS: Vec<InitMount> = vec![
|
||||||
INIT_MOUNT{fstype: "proc", src: "proc", dest: "/proc", options: vec!["nosuid", "nodev", "noexec"]},
|
InitMount{fstype: "proc", src: "proc", dest: "/proc", options: vec!["nosuid", "nodev", "noexec"]},
|
||||||
INIT_MOUNT{fstype: "sysfs", src: "sysfs", dest: "/sys", options: vec!["nosuid", "nodev", "noexec"]},
|
InitMount{fstype: "sysfs", src: "sysfs", dest: "/sys", options: vec!["nosuid", "nodev", "noexec"]},
|
||||||
INIT_MOUNT{fstype: "devtmpfs", src: "dev", dest: "/dev", options: vec!["nosuid"]},
|
InitMount{fstype: "devtmpfs", src: "dev", dest: "/dev", options: vec!["nosuid"]},
|
||||||
INIT_MOUNT{fstype: "tmpfs", src: "tmpfs", dest: "/dev/shm", options: vec!["nosuid", "nodev"]},
|
InitMount{fstype: "tmpfs", src: "tmpfs", dest: "/dev/shm", options: vec!["nosuid", "nodev"]},
|
||||||
INIT_MOUNT{fstype: "devpts", src: "devpts", dest: "/dev/pts", options: vec!["nosuid", "noexec"]},
|
InitMount{fstype: "devpts", src: "devpts", dest: "/dev/pts", options: vec!["nosuid", "noexec"]},
|
||||||
INIT_MOUNT{fstype: "tmpfs", src: "tmpfs", dest: "/run", options: vec!["nosuid", "nodev"]},
|
InitMount{fstype: "tmpfs", src: "tmpfs", dest: "/run", options: vec!["nosuid", "nodev"]},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,7 +492,7 @@ pub async fn add_storages(
|
|||||||
Ok(mount_list)
|
Ok(mount_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mount_to_rootfs(logger: &Logger, m: &INIT_MOUNT) -> Result<()> {
|
fn mount_to_rootfs(logger: &Logger, m: &InitMount) -> Result<()> {
|
||||||
let options_vec: Vec<&str> = m.options.clone();
|
let options_vec: Vec<&str> = m.options.clone();
|
||||||
|
|
||||||
let (flags, options) = parse_mount_flags_and_options(options_vec);
|
let (flags, options) = parse_mount_flags_and_options(options_vec);
|
||||||
@ -568,11 +568,11 @@ pub fn get_cgroup_mounts(
|
|||||||
logger: &Logger,
|
logger: &Logger,
|
||||||
cg_path: &str,
|
cg_path: &str,
|
||||||
unified_cgroup_hierarchy: bool,
|
unified_cgroup_hierarchy: bool,
|
||||||
) -> Result<Vec<INIT_MOUNT>> {
|
) -> Result<Vec<InitMount>> {
|
||||||
// cgroup v2
|
// cgroup v2
|
||||||
// https://github.com/kata-containers/agent/blob/8c9bbadcd448c9a67690fbe11a860aaacc69813c/agent.go#L1249
|
// https://github.com/kata-containers/agent/blob/8c9bbadcd448c9a67690fbe11a860aaacc69813c/agent.go#L1249
|
||||||
if unified_cgroup_hierarchy {
|
if unified_cgroup_hierarchy {
|
||||||
return Ok(vec![INIT_MOUNT {
|
return Ok(vec![InitMount {
|
||||||
fstype: "cgroup2",
|
fstype: "cgroup2",
|
||||||
src: "cgroup2",
|
src: "cgroup2",
|
||||||
dest: "/sys/fs/cgroup",
|
dest: "/sys/fs/cgroup",
|
||||||
@ -584,7 +584,7 @@ pub fn get_cgroup_mounts(
|
|||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
let mut has_device_cgroup = false;
|
let mut has_device_cgroup = false;
|
||||||
let mut cg_mounts: Vec<INIT_MOUNT> = vec![INIT_MOUNT {
|
let mut cg_mounts: Vec<InitMount> = vec![InitMount {
|
||||||
fstype: "tmpfs",
|
fstype: "tmpfs",
|
||||||
src: "tmpfs",
|
src: "tmpfs",
|
||||||
dest: SYSFS_CGROUPPATH,
|
dest: SYSFS_CGROUPPATH,
|
||||||
@ -630,7 +630,7 @@ pub fn get_cgroup_mounts(
|
|||||||
|
|
||||||
if let Some(value) = CGROUPS.get(&fields[0]) {
|
if let Some(value) = CGROUPS.get(&fields[0]) {
|
||||||
let key = CGROUPS.keys().find(|&&f| f == fields[0]).unwrap();
|
let key = CGROUPS.keys().find(|&&f| f == fields[0]).unwrap();
|
||||||
cg_mounts.push(INIT_MOUNT {
|
cg_mounts.push(InitMount {
|
||||||
fstype: "cgroup",
|
fstype: "cgroup",
|
||||||
src: "cgroup",
|
src: "cgroup",
|
||||||
dest: *value,
|
dest: *value,
|
||||||
@ -644,7 +644,7 @@ pub fn get_cgroup_mounts(
|
|||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
cg_mounts.push(INIT_MOUNT {
|
cg_mounts.push(InitMount {
|
||||||
fstype: "tmpfs",
|
fstype: "tmpfs",
|
||||||
src: "tmpfs",
|
src: "tmpfs",
|
||||||
dest: SYSFS_CGROUPPATH,
|
dest: SYSFS_CGROUPPATH,
|
||||||
@ -1142,21 +1142,21 @@ mod tests {
|
|||||||
let drain = slog::Discard;
|
let drain = slog::Discard;
|
||||||
let logger = slog::Logger::root(drain, o!());
|
let logger = slog::Logger::root(drain, o!());
|
||||||
|
|
||||||
let first_mount = INIT_MOUNT {
|
let first_mount = InitMount {
|
||||||
fstype: "tmpfs",
|
fstype: "tmpfs",
|
||||||
src: "tmpfs",
|
src: "tmpfs",
|
||||||
dest: SYSFS_CGROUPPATH,
|
dest: SYSFS_CGROUPPATH,
|
||||||
options: vec!["nosuid", "nodev", "noexec", "mode=755"],
|
options: vec!["nosuid", "nodev", "noexec", "mode=755"],
|
||||||
};
|
};
|
||||||
|
|
||||||
let last_mount = INIT_MOUNT {
|
let last_mount = InitMount {
|
||||||
fstype: "tmpfs",
|
fstype: "tmpfs",
|
||||||
src: "tmpfs",
|
src: "tmpfs",
|
||||||
dest: SYSFS_CGROUPPATH,
|
dest: SYSFS_CGROUPPATH,
|
||||||
options: vec!["remount", "ro", "nosuid", "nodev", "noexec", "mode=755"],
|
options: vec!["remount", "ro", "nosuid", "nodev", "noexec", "mode=755"],
|
||||||
};
|
};
|
||||||
|
|
||||||
let cg_devices_mount = INIT_MOUNT {
|
let cg_devices_mount = InitMount {
|
||||||
fstype: "cgroup",
|
fstype: "cgroup",
|
||||||
src: "cgroup",
|
src: "cgroup",
|
||||||
dest: "/sys/fs/cgroup/devices",
|
dest: "/sys/fs/cgroup/devices",
|
||||||
|
@ -45,7 +45,7 @@ pub enum AddressFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A high level wrapper for netlink (and `rtnetlink` crate) for use by the Agent's RPC.
|
/// A high level wrapper for netlink (and `rtnetlink` crate) for use by the Agent's RPC.
|
||||||
/// It is expected to be consumed by the `agentService`, so it operates with protobuf
|
/// It is expected to be consumed by the `AgentService`, so it operates with protobuf
|
||||||
/// structures directly for convenience.
|
/// structures directly for convenience.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Handle {
|
pub struct Handle {
|
||||||
|
@ -76,11 +76,11 @@ macro_rules! sl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct agentService {
|
pub struct AgentService {
|
||||||
sandbox: Arc<Mutex<Sandbox>>,
|
sandbox: Arc<Mutex<Sandbox>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl agentService {
|
impl AgentService {
|
||||||
async fn do_create_container(
|
async fn do_create_container(
|
||||||
&self,
|
&self,
|
||||||
req: protocols::agent::CreateContainerRequest,
|
req: protocols::agent::CreateContainerRequest,
|
||||||
@ -493,7 +493,7 @@ impl agentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl protocols::agent_ttrpc::AgentService for agentService {
|
impl protocols::agent_ttrpc::AgentService for AgentService {
|
||||||
async fn create_container(
|
async fn create_container(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &TtrpcContext,
|
_ctx: &TtrpcContext,
|
||||||
@ -1203,10 +1203,10 @@ impl protocols::agent_ttrpc::AgentService for agentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct healthService;
|
struct HealthService;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl protocols::health_ttrpc::Health for healthService {
|
impl protocols::health_ttrpc::Health for HealthService {
|
||||||
async fn check(
|
async fn check(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &TtrpcContext,
|
_ctx: &TtrpcContext,
|
||||||
@ -1334,13 +1334,13 @@ fn find_process<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(s: Arc<Mutex<Sandbox>>, server_address: &str) -> TtrpcServer {
|
pub fn start(s: Arc<Mutex<Sandbox>>, server_address: &str) -> TtrpcServer {
|
||||||
let agent_service = Box::new(agentService { sandbox: s })
|
let agent_service = Box::new(AgentService { sandbox: s })
|
||||||
as Box<dyn protocols::agent_ttrpc::AgentService + Send + Sync>;
|
as Box<dyn protocols::agent_ttrpc::AgentService + Send + Sync>;
|
||||||
|
|
||||||
let agent_worker = Arc::new(agent_service);
|
let agent_worker = Arc::new(agent_service);
|
||||||
|
|
||||||
let health_service =
|
let health_service =
|
||||||
Box::new(healthService {}) as Box<dyn protocols::health_ttrpc::Health + Send + Sync>;
|
Box::new(HealthService {}) as Box<dyn protocols::health_ttrpc::Health + Send + Sync>;
|
||||||
let health_worker = Arc::new(health_service);
|
let health_worker = Arc::new(health_service);
|
||||||
|
|
||||||
let aservice = protocols::agent_ttrpc::create_agent_service(agent_worker);
|
let aservice = protocols::agent_ttrpc::create_agent_service(agent_worker);
|
||||||
@ -1670,7 +1670,7 @@ fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::protocols::agent_ttrpc::AgentService;
|
use crate::protocols::agent_ttrpc::AgentService as _;
|
||||||
use oci::{Hook, Hooks};
|
use oci::{Hook, Hooks};
|
||||||
use ttrpc::{r#async::TtrpcContext, MessageHeader};
|
use ttrpc::{r#async::TtrpcContext, MessageHeader};
|
||||||
|
|
||||||
@ -1725,7 +1725,7 @@ mod tests {
|
|||||||
let logger = slog::Logger::root(slog::Discard, o!());
|
let logger = slog::Logger::root(slog::Discard, o!());
|
||||||
let sandbox = Sandbox::new(&logger).unwrap();
|
let sandbox = Sandbox::new(&logger).unwrap();
|
||||||
|
|
||||||
let agent_service = Box::new(agentService {
|
let agent_service = Box::new(AgentService {
|
||||||
sandbox: Arc::new(Mutex::new(sandbox)),
|
sandbox: Arc::new(Mutex::new(sandbox)),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1742,7 +1742,7 @@ mod tests {
|
|||||||
let logger = slog::Logger::root(slog::Discard, o!());
|
let logger = slog::Logger::root(slog::Discard, o!());
|
||||||
let sandbox = Sandbox::new(&logger).unwrap();
|
let sandbox = Sandbox::new(&logger).unwrap();
|
||||||
|
|
||||||
let agent_service = Box::new(agentService {
|
let agent_service = Box::new(AgentService {
|
||||||
sandbox: Arc::new(Mutex::new(sandbox)),
|
sandbox: Arc::new(Mutex::new(sandbox)),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1759,7 +1759,7 @@ mod tests {
|
|||||||
let logger = slog::Logger::root(slog::Discard, o!());
|
let logger = slog::Logger::root(slog::Discard, o!());
|
||||||
let sandbox = Sandbox::new(&logger).unwrap();
|
let sandbox = Sandbox::new(&logger).unwrap();
|
||||||
|
|
||||||
let agent_service = Box::new(agentService {
|
let agent_service = Box::new(AgentService {
|
||||||
sandbox: Arc::new(Mutex::new(sandbox)),
|
sandbox: Arc::new(Mutex::new(sandbox)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user