Skip to content

Commit

Permalink
Merge pull request #350 from vigh-m/ephemeral-storage
Browse files Browse the repository at this point in the history
Fix errors with apiserver and bootstrap-commands
  • Loading branch information
vigh-m authored Jan 16, 2025
2 parents 42717c7 + fd7360c commit fe2354d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions sources/api/apiserver/src/server/ephemeral_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ pub fn bind(variant: &str, dirs: Vec<String>) -> Result<()> {
_ => format!("{}{}", RAID_DEVICE_DIR, RAID_DEVICE_NAME),
};

// Normalize input by trimming trailing "/"
let dirs: Vec<String> = dirs
.into_iter()
.map(|dir| dir.trim_end_matches("/").to_string())
.collect();

let mount_point = format!("/mnt/{}", EPHEMERAL_MNT);
let mount_point = Path::new(&mount_point);
let allowed_dirs = allowed_bind_dirs(variant);
Expand Down
24 changes: 18 additions & 6 deletions sources/bootstrap-commands/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ prior to `preconfigured.target` while `[email protected]` which is a requ
running "exec" commands are launched after preconfigured.target.
*/

use log::info;
use log::{info, warn};
use serde::Deserialize;
use simplelog::{Config as LogConfig, LevelFilter, SimpleLogger};
use snafu::{ensure, OptionExt, ResultExt};
Expand Down Expand Up @@ -100,11 +100,16 @@ where
{
let mut command = Command::new(bin_path);

command
let output = command
.args(args)
.status()
.output()
.context(error::ExecutionFailureSnafu { command })?;

ensure!(
output.status.success(),
error::CommandFailureSnafu { bin_path, output }
);

Ok(())
}

Expand Down Expand Up @@ -198,10 +203,13 @@ fn run() -> Result<()> {
for (bootstrap_command_name, bootstrap_command) in bootstrap_commands.iter() {
let name = bootstrap_command_name.as_ref();
let essential = bootstrap_command.essential;
let status = handle_bootstrap_command(name, bootstrap_command);
let result = handle_bootstrap_command(name, bootstrap_command);

if let Err(ref e) = result {
warn!("Bootstrap command failed to execute {}", e);
}
ensure!(
!essential || status.is_ok(),
!essential || result.is_ok(),
error::BootstrapCommandExecutionSnafu { name }
)
}
Expand All @@ -221,7 +229,7 @@ fn main() {
mod error {
use snafu::Snafu;
use std::path::PathBuf;
use std::process::Command;
use std::process::{Command, Output};

#[derive(Debug, Snafu)]
#[snafu(visibility(pub(super)))]
Expand All @@ -247,6 +255,10 @@ mod error {
source: std::io::Error,
},

#[snafu(display("'{}' failed - stderr: {}",
bin_path, String::from_utf8_lossy(&output.stderr)))]
CommandFailure { bin_path: String, output: Output },

#[snafu(display("Logger setup error: {}", source))]
Logger { source: log::SetLoggerError },

Expand Down

0 comments on commit fe2354d

Please sign in to comment.