Skip to content

Commit d14ebcc

Browse files
Techassilfranckesbernauer
authored
chore(operator/eos): Adjust the warning message (#1103)
* chore(operator/eos): Adjust the warning message * chore(operator): Add changelog entry * chore(shared): Add changelog entry * chore: Apply suggestion Co-authored-by: Lars Francke <[email protected]> * chore: Remove "days" from the warning message * chore: Apply suggestion This was accidentally reverted. Co-authored-by: Lars Francke <[email protected]> Co-authored-by: Sebastian Bernauer <[email protected]> * chore: Apply TOML formatting Co-authored-by: Sebastian Bernauer <[email protected]> --------- Co-authored-by: Lars Francke <[email protected]> Co-authored-by: Sebastian Bernauer <[email protected]>
1 parent 880a496 commit d14ebcc

File tree

8 files changed

+58
-22
lines changed

8 files changed

+58
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-operator/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
1616

1717
### Changed
1818

19+
- Update the end-of-support warning message ([#1103])
1920
- BREAKING: `ProductOperatorRun` was renamed to `RunArguments` ([#1096]).
2021
- BREAKING: The `disable_crd_maintenance` field was moved from `RunArguments` into `MaintenanceOptions`.
2122
The CLI interface is unchanged ([#1096]).
@@ -26,6 +27,7 @@ All notable changes to this project will be documented in this file.
2627
[#1096]: https://github.com/stackabletech/operator-rs/pull/1096
2728
[#1098]: https://github.com/stackabletech/operator-rs/pull/1098
2829
[#1101]: https://github.com/stackabletech/operator-rs/pull/1101
30+
[#1103]: https://github.com/stackabletech/operator-rs/pull/1103
2931

3032
## [0.98.0] - 2025-09-22
3133

crates/stackable-operator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ webhook = ["dep:stackable-webhook"]
2121
[dependencies]
2222
stackable-certs = { path = "../stackable-certs", optional = true }
2323
stackable-operator-derive = { path = "../stackable-operator-derive" }
24-
stackable-shared = { path = "../stackable-shared" }
24+
stackable-shared = { path = "../stackable-shared", features = ["chrono", "time"] }
2525
stackable-telemetry = { path = "../stackable-telemetry", optional = true, features = ["clap"] }
2626
stackable-versioned = { path = "../stackable-versioned", optional = true }
2727
stackable-webhook = { path = "../stackable-webhook", optional = true }

crates/stackable-operator/src/eos/mod.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ pub enum Error {
6767
}
6868

6969
pub struct EndOfSupportChecker {
70-
datetime: DateTime<Utc>,
70+
built_datetime: DateTime<Utc>,
71+
eos_datetime: DateTime<Utc>,
7172
interval: Duration,
7273
disabled: bool,
7374
}
@@ -90,7 +91,7 @@ impl EndOfSupportChecker {
9091

9192
// Parse the built-time from the RFC2822-encoded string when this is compiled as a release
9293
// build. If this is a debug/dev build, use the current datetime instead.
93-
let mut datetime = if cfg!(debug_assertions) {
94+
let built_datetime = if cfg!(debug_assertions) {
9495
Utc::now()
9596
} else {
9697
DateTime::parse_from_rfc2822(built_time)
@@ -99,10 +100,11 @@ impl EndOfSupportChecker {
99100
};
100101

101102
// Add the support duration to the built date. This marks the end-of-support date.
102-
datetime += *support_duration;
103+
let eos_datetime = built_datetime + *support_duration;
103104

104105
Ok(Self {
105-
datetime,
106+
built_datetime,
107+
eos_datetime,
106108
interval,
107109
disabled,
108110
})
@@ -125,37 +127,37 @@ impl EndOfSupportChecker {
125127
// TODO: Add way to stop from the outside
126128
// The first tick ticks immediately.
127129
interval.tick().await;
130+
let now = Utc::now();
131+
128132
tracing::info_span!(
129133
"checking end-of-support state",
130134
eos.interval = self.interval.to_string(),
135+
eos.now = now.to_rfc3339(),
131136
);
132137

133138
// Continue the loop and wait for the next tick to run the check again.
134-
if !self.is_eos() {
139+
if now <= self.eos_datetime {
135140
continue;
136141
}
137142

138-
self.emit_warning();
143+
self.emit_warning(now);
139144
}
140145
}
141146

142147
/// Emits the end-of-support warning.
143148
#[instrument(level = Level::DEBUG, skip(self))]
144-
fn emit_warning(&self) {
149+
fn emit_warning(&self, now: DateTime<Utc>) {
150+
let built_datetime = self.built_datetime.to_rfc3339();
151+
let build_age = Duration::try_from(now - self.built_datetime)
152+
.expect("time delta of now and built datetime must not be less than 0")
153+
.to_string();
154+
145155
tracing::warn!(
146-
eos.date = self.datetime.to_rfc3339(),
147-
"the operator reached end-of-support"
156+
eos.built.datetime = built_datetime,
157+
eos.build.age = build_age,
158+
"This operator version was built on {built_datetime} ({build_age} ago) and may have reached end-of-support. \
159+
Running unsupported versions may contain security vulnerabilities. \
160+
Please upgrade to a supported version as soon as possible."
148161
);
149162
}
150-
151-
/// Returns if the operator is considered as end-of-support based on the built-time and the
152-
/// support duration.
153-
#[instrument(level = Level::DEBUG, skip(self), fields(eos.now))]
154-
fn is_eos(&self) -> bool {
155-
let now = Utc::now();
156-
157-
tracing::Span::current().record("eos.now", now.to_rfc3339());
158-
159-
now > self.datetime
160-
}
161163
}

crates/stackable-shared/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Unreleased
6+
7+
### Added
8+
9+
- Add conversion implementations between `Duration` and `chrono::TimeDelta` ([#1103]).
10+
11+
[#1103]: https://github.com/stackabletech/operator-rs/pull/1103
12+
513
## [0.0.2] - 2025-08-21
614

715
### Added

crates/stackable-shared/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ edition.workspace = true
77
repository.workspace = true
88

99
[features]
10-
full = ["time"]
10+
full = ["chrono", "time"]
1111
default = ["time"]
1212

13+
chrono = ["dep:chrono"]
1314
time = ["dep:time"]
1415

1516
[dependencies]
17+
chrono = { workspace = true, optional = true }
1618
k8s-openapi.workspace = true
1719
kube.workspace = true
1820
schemars.workspace = true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::time::Duration;
2+
3+
impl TryFrom<chrono::TimeDelta> for Duration {
4+
type Error = chrono::OutOfRangeError;
5+
6+
fn try_from(value: chrono::TimeDelta) -> Result<Self, Self::Error> {
7+
let std_duration = value.to_std()?;
8+
Ok(Self::from(std_duration))
9+
}
10+
}
11+
12+
impl TryFrom<Duration> for chrono::TimeDelta {
13+
type Error = chrono::OutOfRangeError;
14+
15+
fn try_from(value: Duration) -> Result<Self, Self::Error> {
16+
chrono::TimeDelta::from_std(value.into())
17+
}
18+
}

crates/stackable-shared/src/time/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
mod duration;
22
mod serde_impl;
33

4+
#[cfg(feature = "chrono")]
5+
mod chrono_impl;
6+
47
#[cfg(feature = "time")]
58
mod time_impl;
69

0 commit comments

Comments
 (0)