Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for crun --log-level #2401

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions conmon-rs/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
child_reaper::ChildReaper,
config::{Commands, Config, LogDriver, Verbosity},
config::{Commands, Config, LogDriver, LogLevel, Verbosity},
container_io::{ContainerIO, ContainerIOType},
fd_socket::FdSocket,
init::{DefaultInit, Init},
Expand Down Expand Up @@ -311,6 +311,8 @@ pub(crate) struct GenerateRuntimeArgs<'a> {

impl GenerateRuntimeArgs<'_> {
const SYSTEMD_CGROUP_ARG: &'static str = "--systemd-cgroup";
const RUNTIME_CRUN: &'static str = "crun";
const LOG_LEVEL_FLAG_CRUN: &'static str = "--log-level";

/// Generate the OCI runtime CLI arguments from the provided parameters.
pub fn create_args(
Expand All @@ -319,7 +321,7 @@ impl GenerateRuntimeArgs<'_> {
global_args: Reader,
command_args: Reader,
) -> Result<Vec<String>> {
let mut args = vec![];
let mut args = self.default_args().context("build default runtime args")?;

if let Some(rr) = self.config.runtime_root() {
args.push(format!("--root={}", rr.display()));
Expand Down Expand Up @@ -357,15 +359,7 @@ impl GenerateRuntimeArgs<'_> {

/// Generate the OCI runtime CLI arguments from the provided parameters.
pub(crate) fn exec_sync_args(&self, command: Reader) -> Result<Vec<String>> {
let mut args = vec![];

if let Some(rr) = self.config.runtime_root() {
args.push(format!("--root={}", rr.display()));
}

if self.cgroup_manager == CgroupManager::Systemd {
args.push(Self::SYSTEMD_CGROUP_ARG.into());
}
let mut args = self.default_args().context("build default runtime args")?;

args.push("exec".to_string());
args.push("-d".to_string());
Expand All @@ -385,4 +379,40 @@ impl GenerateRuntimeArgs<'_> {
debug!("Exec args {:?}", args.join(" "));
Ok(args)
}

/// Build the default arguments for any provided runtime.
fn default_args(&self) -> Result<Vec<String>> {
let mut args = vec![];

if self
.config
.runtime()
.file_name()
.context("no filename in path")?
== Self::RUNTIME_CRUN
{
debug!("Found crun used as runtime");
args.push(format!("--log=journald:{}", self.id));

match self.config.log_level() {
&LogLevel::Debug | &LogLevel::Error => args.push(format!(
"{}={}",
Self::LOG_LEVEL_FLAG_CRUN,
self.config.log_level()
)),
&LogLevel::Warn => args.push(format!("{}=warning", Self::LOG_LEVEL_FLAG_CRUN)),
_ => {}
}
}

if let Some(rr) = self.config.runtime_root() {
args.push(format!("--root={}", rr.display()));
}

if self.cgroup_manager == CgroupManager::Systemd {
args.push(Self::SYSTEMD_CGROUP_ARG.into());
}

Ok(args)
}
}
Loading