@@ -67,7 +67,8 @@ pub enum Error {
6767}
6868
6969pub 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}
0 commit comments