Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Create missing directories #274

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
:267: https://github.com/stackabletech/agent/pull/267[#267]
:270: https://github.com/stackabletech/agent/pull/270[#270]
:273: https://github.com/stackabletech/agent/pull/273[#273]
:274: https://github.com/stackabletech/agent/pull/274[#274]

=== Added
* Prints self-diagnostic information on startup ({270})
* Check added on startup if the configured directories exist and are
writable by the Stackable agent ({273}).
* Missing directories are created ({274}).

=== Changed
* Lazy validation of repository URLs changed to eager validation
Expand Down
30 changes: 29 additions & 1 deletion src/bin/stackable-agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::PathBuf;
use kubelet::config::{Config, ServerConfig};
use kubelet::Kubelet;
use log::{error, info};
use tokio::fs::File;
use tokio::fs::{create_dir_all, File};

use stackable_agent::config::AgentConfig;
use stackable_agent::fsext::check_dir_is_writable;
Expand Down Expand Up @@ -56,6 +56,7 @@ async fn main() -> anyhow::Result<()> {
);

check_optional_files(&agent_config).await;
create_missing_directories(&agent_config).await;
check_configured_directories(&agent_config).await;

// Currently the only way to _properly_ configure the Krustlet is via these environment exports,
Expand Down Expand Up @@ -168,6 +169,33 @@ async fn check_optional_files(config: &AgentConfig) {
}
}

/// Creates the directories where write access is required and which do
/// not exist yet.
///
/// If a directory could not be created then an error is logged.
async fn create_missing_directories(config: &AgentConfig) {
for (config_option, directory) in directories_where_write_access_is_required(config).await {
if directory.components().count() != 0 && !directory.exists() {
if let Err(error) = create_dir_all(&directory).await {
error!(
"Could not create the directory [{}] which is \
specified in the configuration option [{}]. {}",
directory.to_string_lossy(),
config_option.name,
error
);
} else {
info!(
"Directory [{}] created which is specified in the \
configuration option [{}].",
directory.to_string_lossy(),
config_option.name
);
}
};
}
}

/// Checks the configured directories if they are writable by the
/// current process. If this is not the case then errors are logged.
///
Expand Down