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

Commit

Permalink
Restart setting in systemd units removed
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedweber committed Jun 23, 2021
1 parent 452f4d1 commit 026d008
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* Annotation `featureLogs` added to the pods to indicate if logs can be
retrieved with `kubectl logs` ({188}).

=== Changed
* Restart setting in systemd units removed because the agent already
monitors the units and restarts them according to the restart policy
in the pod spec ({205}).

=== Fixed
* Pods with restart policy `Never` handled correctly ({205}).

Expand Down
35 changes: 0 additions & 35 deletions src/provider/systemdmanager/systemdunit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use kubelet::container::Container;
use kubelet::pod::Pod;

use crate::provider::error::StackableError;

use crate::provider::error::StackableError::PodValidationError;
use crate::provider::states::pod::creating_config::CreatingConfig;
use crate::provider::states::pod::PodState;
Expand All @@ -18,15 +17,6 @@ use std::fmt::{Display, Formatter};
use std::iter;
use strum::{Display, EnumIter, IntoEnumIterator};

lazy_static! {
// This is used to map from Kubernetes restart lingo to systemd restart terms
static ref RESTART_POLICY_MAP: HashMap<&'static str, &'static str> = [
("Always", "always"),
("OnFailure", "on-failure"),
("Never", "no")
].iter().cloned().collect();
}

/// The default timeout for stopping a service, after this has passed systemd will terminate
/// the process
const DEFAULT_TERMINATION_TIMEOUT_SECS: i64 = 30;
Expand Down Expand Up @@ -205,26 +195,6 @@ impl SystemDUnit {
}
};

// Get restart policy from pod, if none is specified default to "Never"
let restart_policy = pod_spec.restart_policy.as_deref().unwrap_or("Never");

// Lookup the equivalent systemd restart policy for the configured one
// If this lookup fails (which means a restart policy was specified which we do not know
// about) then we fail the entire service to avoid unpredictable behavior
let restart_policy = match RESTART_POLICY_MAP.get(restart_policy) {
Some(policy) => policy,
None => {
return Err(PodValidationError {
msg: format!(
"Unknown value [{}] for RestartPolicy in pod [{}]",
restart_policy, unit.name
),
})
}
};

unit.add_property(Section::Service, "Restart", restart_policy);

// If `terminationGracePeriodSeconds` was specified in the PodSpec set the value as
// 'TimeOutStopSec` on the systemd unit
// This means that the service will be killed after this period if it does not shutdown
Expand Down Expand Up @@ -512,14 +482,12 @@ mod test {
name: stackable
spec:
containers: []
restartPolicy: Always
securityContext:
windowsOptions:
runAsUserName: pod-user",
"stackable.service",
indoc! {"
[Service]
Restart=always
TimeoutStopSec=30
User=pod-user"}
)]
Expand Down Expand Up @@ -557,7 +525,6 @@ mod test {
[Service]
Environment="LOG_DIR=/var/log/default-stackable" "LOG_LEVEL=INFO"
ExecStart=start.sh arg /etc/default-stackable
Restart=no
StandardError=journal
StandardOutput=journal
TimeoutStopSec=30
Expand Down Expand Up @@ -591,7 +558,6 @@ mod test {
[Service]
ExecStart=start.sh
Restart=no
StandardError=journal
StandardOutput=journal
TimeoutStopSec=30
Expand All @@ -612,7 +578,6 @@ mod test {
"stackable.service",
indoc! {"
[Service]
Restart=no
TimeoutStopSec=10"}
)]

Expand Down

0 comments on commit 026d008

Please sign in to comment.