Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
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
5 changes: 4 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
: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]
:276: https://github.com/stackabletech/agent/pull/276[#276]

=== Added
* Prints self-diagnostic information on startup ({270})
* 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}).
Expand All @@ -20,6 +21,8 @@
* `certificates.k8s.io/v1` used instead of `certificates.k8s.io/v1beta1`
so that the Stackable Agent is now compatible with Kubernetes v1.22
but not any longer with versions prior to v1.19 ({267}).
* Error message improved which is logged if a systemd unit file cannot
be created ({276}).

== 0.5.0 - 2021-07-26

Expand Down
21 changes: 9 additions & 12 deletions src/provider/states/pod/creating_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::setup_failed::SetupFailed;
use super::starting::Starting;
use crate::provider::systemdmanager::systemdunit::SystemDUnit;
use crate::provider::{ContainerHandle, PodState, ProviderState};
use anyhow::Error;
use anyhow::{Context, Error};
use dirs::home_dir;
use std::env;
use std::fs::create_dir_all;
Expand Down Expand Up @@ -113,17 +113,14 @@ impl State<PodState> for CreatingService {
// Create the service
// As per ADR005 we currently write the unit files directly in the systemd
// unit directory (by passing None as [unit_file_path]).
match systemd_manager.create_unit(&unit, None, true, true).await {
Ok(()) => {}
Err(e) => {
// TODO: We need to discuss what to do here, in theory we could have loaded
// other services already, do we want to stop those?
error!(
"Failed to create systemd unit for service [{}]",
service_name
);
return Transition::Complete(Err(e));
}
if let Err(e) = systemd_manager
.create_unit(&unit, None, true, true)
.await
.with_context(|| format!("Unit file [{}] could not be created", unit))
{
// TODO: We need to discuss what to do here, in theory we could have loaded
// other services already, do we want to stop those?
return Transition::Complete(Err(e));
}

let systemd_service = match systemd_manager
Expand Down
18 changes: 7 additions & 11 deletions src/provider/systemdmanager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::systemd1_api::{
use crate::provider::systemdmanager::systemdunit::SystemDUnit;
use crate::provider::StackableError;
use crate::provider::StackableError::RuntimeError;
use anyhow::anyhow;
use anyhow::{anyhow, Context};
use futures_util::{future, stream::StreamExt};
use log::debug;
use std::fs;
Expand Down Expand Up @@ -190,16 +190,12 @@ impl SystemdManager {
if !target_file.exists() {
// Write unit file, no matter where
// TODO: implement check for content equality
let mut unit_file = match File::create(&target_file) {
Ok(file) => file,
Err(e) => {
debug!(
"Error occurred when creating unit file [{}]: [{}]",
unit_name, e
);
return Err(anyhow::Error::from(e));
}
};
let mut unit_file = File::create(&target_file).with_context(|| {
format!(
"File [{}] could not be created",
target_file.to_string_lossy()
)
})?;
unit_file.write_all(unit.get_unit_file_content().as_bytes())?;
unit_file.flush()?;
}
Expand Down