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

Commit 1b60ad8

Browse files
Set annotation featureRestartCount (#289)
The annotation featureRestartCount is set to "true" if the restart count in the container status can be set properly. This is the case if systemd version 235 or newer is used. If an older systemd version is used then featureRestartCount is set to "false".
1 parent 35e6eae commit 1b60ad8

File tree

6 files changed

+53
-22
lines changed

6 files changed

+53
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Check added on startup if the configured directories exist and are
88
writable by the Stackable agent ([#273]).
99
- Missing directories are created ([#274]).
10+
- Annotation `featureRestartCount` added to the pods to indicate if the
11+
restart count is set properly ([#289]).
1012

1113
### Changed
1214
- Lazy validation of repository URLs changed to eager validation
@@ -35,6 +37,7 @@
3537
[#273]: https://github.com/stackabletech/agent/pull/273
3638
[#274]: https://github.com/stackabletech/agent/pull/274
3739
[#276]: https://github.com/stackabletech/agent/pull/276
40+
[#289]: https://github.com/stackabletech/agent/pull/289
3841

3942
## 0.5.0 - 2021-07-26
4043

Cargo.lock

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ tar = "0.4"
5050
thiserror = "1.0"
5151
tokio = { version = "1.11", features = ["macros", "rt-multi-thread", "time"] }
5252
url = "2.2"
53-
zbus = { git = "https://gitlab.freedesktop.org/dbus/zbus", rev = "0a8a4268be0f844ab4bca429f27766347dc3af58" } # version 2.0.0-beta.6 + merge request !354 (fixes a race condition)
54-
zvariant = { git = "https://gitlab.freedesktop.org/dbus/zbus", rev = "0a8a4268be0f844ab4bca429f27766347dc3af58" } # version 2.8.0 which is compatible with the zbus version
53+
zbus = { git = "https://gitlab.freedesktop.org/dbus/zbus", rev = "ff08cbbbcd3eead16464012b92e3862d4dcb6f16" } # version 2.0.0-beta.6 + merge request !354 (fixes a race condition) + commit 6cdfe48cda5e0bf7b0dd8675be7a84439678afa9 (fixes another race condition)
54+
zvariant = { git = "https://gitlab.freedesktop.org/dbus/zbus", rev = "ff08cbbbcd3eead16464012b92e3862d4dcb6f16" } # version 2.8.0 which is compatible with the zbus version
5555

5656
[dev-dependencies]
5757
indoc = "1.0"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
= Restarts
2+
3+
The restart count is stored in the container status if systemd version
4+
235 or newer is running on the node which is the case for Debian 10 and
5+
CentOS 8 but not for CentOS 7. The annotation `featureRestartCount`
6+
indicates whether or not the restart count is set properly.
7+
8+
$ kubectl get pod <pod-name>
9+
NAME READY STATUS RESTARTS AGE
10+
<pod-name> 1/1 Running 4 10m
11+
12+
$ kubectl describe pod <pod-name>
13+
Name: <pod-name>
14+
Annotations: featureRestartCount: true
15+
Containers:
16+
<service-name>:
17+
Restart Count: 4

src/provider/states/pod/starting.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::HashMap;
2+
13
use super::running::Running;
24
use crate::provider::{
35
kubernetes::status::patch_container_status, systemdmanager::service::ServiceState, PodHandle,
@@ -79,41 +81,46 @@ async fn start_service_units(
7981
);
8082
}
8183

82-
add_annotation(
83-
&client,
84-
pod,
84+
let mut annotations = HashMap::new();
85+
annotations.insert(
8586
"featureLogs",
86-
&systemd_service.invocation_id().await.is_ok().to_string(),
87-
)
88-
.await?;
87+
systemd_service.invocation_id().await.is_ok().to_string(),
88+
);
89+
annotations.insert(
90+
"featureRestartCount",
91+
systemd_service.restart_count().await.is_ok().to_string(),
92+
);
93+
94+
add_annotations(&client, pod, &annotations).await?;
8995

9096
patch_container_status(&client, pod, &container_key, &Status::running()).await;
9197
}
9298

9399
Ok(())
94100
}
95101

96-
/// Adds an annotation to the given pod.
102+
/// Adds annotations to the given pod.
97103
///
98104
/// If there is already an annotation with the given key then the value
99105
/// is replaced.
100106
/// The function returns when the patch is sent. It does not await the
101107
/// changes to be visible to the watching clients.
102-
async fn add_annotation(client: &Client, pod: &Pod, key: &str, value: &str) -> kube::Result<Pod> {
108+
async fn add_annotations(
109+
client: &Client,
110+
pod: &Pod,
111+
annotations: &HashMap<&str, String>,
112+
) -> kube::Result<Pod> {
103113
debug!(
104-
"Adding annotation [{}: {}] to pod [{:?}]",
105-
key,
106-
value,
114+
"Adding annotations [{:?}] to pod [{:?}]",
115+
annotations,
107116
PodKey::from(pod)
108117
);
109118

110119
let api: Api<Pod> = Api::namespaced(client.clone(), pod.namespace());
111120

112121
let patch = json!({
113122
"metadata": {
114-
"annotations": {
115-
key: value
116-
}
123+
"annotations": annotations
117124
}
118125
});
119126

src/provider/systemdmanager/service.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ impl SystemdService {
112112
Ok(service_state)
113113
}
114114

115+
/// Retrieves the current restart count.
116+
///
117+
/// The restart counter was introduced in systemd version 235.
115118
pub async fn restart_count(&self) -> anyhow::Result<u32> {
116119
self.service_proxy
117120
.nrestarts()

0 commit comments

Comments
 (0)