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

Commit 4966ef7

Browse files
Create missing directories (#274)
The following directories are created if they do not exist: * config * data * log * package * directory of the certificate file if the file does not exist * directory of the key file if the file does not exist
1 parent 7c072cc commit 4966ef7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
:267: https://github.com/stackabletech/agent/pull/267[#267]
77
:270: https://github.com/stackabletech/agent/pull/270[#270]
88
:273: https://github.com/stackabletech/agent/pull/273[#273]
9+
:274: https://github.com/stackabletech/agent/pull/274[#274]
910

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

1517
=== Changed
1618
* Lazy validation of repository URLs changed to eager validation

src/bin/stackable-agent.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::PathBuf;
77
use kubelet::config::{Config, ServerConfig};
88
use kubelet::Kubelet;
99
use log::{error, info};
10-
use tokio::fs::File;
10+
use tokio::fs::{create_dir_all, File};
1111

1212
use stackable_agent::config::AgentConfig;
1313
use stackable_agent::fsext::check_dir_is_writable;
@@ -56,6 +56,7 @@ async fn main() -> anyhow::Result<()> {
5656
);
5757

5858
check_optional_files(&agent_config).await;
59+
create_missing_directories(&agent_config).await;
5960
check_configured_directories(&agent_config).await;
6061

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

172+
/// Creates the directories where write access is required and which do
173+
/// not exist yet.
174+
///
175+
/// If a directory could not be created then an error is logged.
176+
async fn create_missing_directories(config: &AgentConfig) {
177+
for (config_option, directory) in directories_where_write_access_is_required(config).await {
178+
if directory.components().count() != 0 && !directory.exists() {
179+
if let Err(error) = create_dir_all(&directory).await {
180+
error!(
181+
"Could not create the directory [{}] which is \
182+
specified in the configuration option [{}]. {}",
183+
directory.to_string_lossy(),
184+
config_option.name,
185+
error
186+
);
187+
} else {
188+
info!(
189+
"Directory [{}] created which is specified in the \
190+
configuration option [{}].",
191+
directory.to_string_lossy(),
192+
config_option.name
193+
);
194+
}
195+
};
196+
}
197+
}
198+
171199
/// Checks the configured directories if they are writable by the
172200
/// current process. If this is not the case then errors are logged.
173201
///

0 commit comments

Comments
 (0)