@@ -67,7 +67,8 @@ pub enum Error {
67
67
}
68
68
69
69
pub struct EndOfSupportChecker {
70
- datetime : DateTime < Utc > ,
70
+ built_datetime : DateTime < Utc > ,
71
+ eos_datetime : DateTime < Utc > ,
71
72
interval : Duration ,
72
73
disabled : bool ,
73
74
}
@@ -90,7 +91,7 @@ impl EndOfSupportChecker {
90
91
91
92
// Parse the built-time from the RFC2822-encoded string when this is compiled as a release
92
93
// 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) {
94
95
Utc :: now ( )
95
96
} else {
96
97
DateTime :: parse_from_rfc2822 ( built_time)
@@ -99,10 +100,11 @@ impl EndOfSupportChecker {
99
100
} ;
100
101
101
102
// 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;
103
104
104
105
Ok ( Self {
105
- datetime,
106
+ built_datetime,
107
+ eos_datetime,
106
108
interval,
107
109
disabled,
108
110
} )
@@ -125,37 +127,37 @@ impl EndOfSupportChecker {
125
127
// TODO: Add way to stop from the outside
126
128
// The first tick ticks immediately.
127
129
interval. tick ( ) . await ;
130
+ let now = Utc :: now ( ) ;
131
+
128
132
tracing:: info_span!(
129
133
"checking end-of-support state" ,
130
134
eos. interval = self . interval. to_string( ) ,
135
+ eos. now = now. to_rfc3339( ) ,
131
136
) ;
132
137
133
138
// 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 {
135
140
continue ;
136
141
}
137
142
138
- self . emit_warning ( ) ;
143
+ self . emit_warning ( now ) ;
139
144
}
140
145
}
141
146
142
147
/// Emits the end-of-support warning.
143
148
#[ 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
+
145
155
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."
148
161
) ;
149
162
}
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
- }
161
163
}
0 commit comments