@@ -18,7 +18,7 @@ use hyper::{
18
18
Server ,
19
19
} ;
20
20
use paw:: ParseArgs ;
21
- use slog_scope :: { crit , error, info} ;
21
+ use tracing :: { error, info} ;
22
22
23
23
use crate :: {
24
24
cmd:: crd:: CustomResourceDefinitionError ,
@@ -51,6 +51,14 @@ pub enum Error {
51
51
Execution ( String , Arc < Error > ) ,
52
52
#[ error( "failed to execute command, {0}" ) ]
53
53
CustomResourceDefinition ( CustomResourceDefinitionError ) ,
54
+ #[ error( "failed to parse listen address '{0}', {1}" ) ]
55
+ Listen ( String , AddrParseError ) ,
56
+ #[ error( "failed to handle termintion signal, {0}" ) ]
57
+ SigTerm ( io:: Error ) ,
58
+ #[ error( "failed to create kubernetes client, {0}" ) ]
59
+ Client ( client:: Error ) ,
60
+ #[ error( "failed to create clever cloud client, {0}" ) ]
61
+ CleverClient ( clevercloud_sdk:: oauth10a:: proxy:: Error ) ,
54
62
}
55
63
56
64
// -----------------------------------------------------------------------------
@@ -111,35 +119,15 @@ impl ParseArgs for Args {
111
119
}
112
120
}
113
121
114
- // -----------------------------------------------------------------------------
115
- // DaemonError enum
116
-
117
- #[ derive( thiserror:: Error , Debug ) ]
118
- pub enum DaemonError {
119
- #[ error( "failed to parse listen address '{0}', {1}" ) ]
120
- Listen ( String , AddrParseError ) ,
121
- #[ error( "failed to handle termintion signal, {0}" ) ]
122
- SigTerm ( io:: Error ) ,
123
- #[ error( "failed to create kubernetes client, {0}" ) ]
124
- Client ( client:: Error ) ,
125
- #[ error( "failed to create clever cloud client, {0}" ) ]
126
- CleverClient ( clevercloud_sdk:: oauth10a:: proxy:: Error ) ,
127
- }
128
-
129
122
// -----------------------------------------------------------------------------
130
123
// daemon function
131
124
132
125
#[ cfg_attr( feature = "trace" , tracing:: instrument) ]
133
- pub async fn daemon (
134
- kubeconfig : Option < PathBuf > ,
135
- config : Arc < Configuration > ,
136
- ) -> Result < ( ) , DaemonError > {
126
+ pub async fn daemon ( kubeconfig : Option < PathBuf > , config : Arc < Configuration > ) -> Result < ( ) , Error > {
137
127
// -------------------------------------------------------------------------
138
128
// Create a new kubernetes client from path if defined, or via the
139
129
// environment or defaults locations
140
- let kube_client = client:: try_new ( kubeconfig)
141
- . await
142
- . map_err ( DaemonError :: Client ) ?;
130
+ let kube_client = client:: try_new ( kubeconfig) . await . map_err ( Error :: Client ) ?;
143
131
144
132
// -------------------------------------------------------------------------
145
133
// Create a new clever-cloud client
@@ -155,14 +143,14 @@ pub async fn daemon(
155
143
} ) ,
156
144
proxy. no . to_owned ( ) ,
157
145
)
158
- . map_err ( DaemonError :: CleverClient ) ?;
146
+ . map_err ( Error :: CleverClient ) ?;
159
147
160
148
ProxyConnectorBuilder :: default ( )
161
149
. with_proxy ( proxy)
162
150
. build ( HttpsConnector :: new ( ) )
163
- . map_err ( DaemonError :: CleverClient ) ?
151
+ . map_err ( Error :: CleverClient ) ?
164
152
}
165
- _ => ProxyConnectorBuilder :: try_from_env ( ) . map_err ( DaemonError :: CleverClient ) ?,
153
+ _ => ProxyConnectorBuilder :: try_from_env ( ) . map_err ( Error :: CleverClient ) ?,
166
154
} ;
167
155
168
156
let clever_client = Client :: builder ( )
@@ -187,7 +175,10 @@ pub async fn daemon(
187
175
188
176
info!( "Start to listen for events of postgresql addon custom resource" ) ;
189
177
if let Err ( err) = reconciler. watch( postgresql_state) . await {
190
- crit!( "Could not reconcile postgresql addon custom resource" ; "error" => err. to_string( ) ) ;
178
+ error!(
179
+ "Could not reconcile postgresql addon custom resource, {}" ,
180
+ err
181
+ ) ;
191
182
}
192
183
193
184
abort( ) ;
@@ -197,7 +188,7 @@ pub async fn daemon(
197
188
198
189
info!( "Start to listen for events of redis addon custom resource" ) ;
199
190
if let Err ( err) = reconciler. watch( redis_state) . await {
200
- crit !( "Could not reconcile redis addon custom resource" ; "error" => err. to_string ( ) ) ;
191
+ error !( "Could not reconcile redis addon custom resource, {}" , err) ;
201
192
}
202
193
203
194
abort( ) ;
@@ -207,7 +198,7 @@ pub async fn daemon(
207
198
208
199
info!( "Start to listen for events of mysql addon custom resource" ) ;
209
200
if let Err ( err) = reconciler. watch( mysql_state) . await {
210
- crit !( "Could not reconcile mysql addon custom resource" ; "error" => err. to_string ( ) ) ;
201
+ error !( "Could not reconcile mysql addon custom resource, {}" , err) ;
211
202
}
212
203
213
204
abort( ) ;
@@ -217,7 +208,7 @@ pub async fn daemon(
217
208
218
209
info!( "Start to listen for events of mongodb addon custom resource" ) ;
219
210
if let Err ( err) = reconciler. watch( mongodb_state) . await {
220
- crit !( "Could not reconcile mongodb addon custom resource" ; "error" => err. to_string ( ) ) ;
211
+ error !( "Could not reconcile mongodb addon custom resource, {}" , err) ;
221
212
}
222
213
223
214
abort( ) ;
@@ -227,7 +218,7 @@ pub async fn daemon(
227
218
228
219
info!( "Start to listen for events of pulsar addon custom resource" ) ;
229
220
if let Err ( err) = reconciler. watch( pulsar_state) . await {
230
- crit !( "Could not reconcile plusar addon custom resource" ; "error" => err. to_string ( ) ) ;
221
+ error !( "Could not reconcile plusar addon custom resource, {}" , err) ;
231
222
}
232
223
233
224
abort( ) ;
@@ -237,7 +228,10 @@ pub async fn daemon(
237
228
238
229
info!( "Start to listen for events of config-provider addon custom resource" ) ;
239
230
if let Err ( err) = reconciler. watch( config_provider_state) . await {
240
- crit!( "Could not reconcile config-provider addon custom resource" ; "error" => err. to_string( ) ) ;
231
+ error!(
232
+ "Could not reconcile config-provider addon custom resource, {}" ,
233
+ err
234
+ ) ;
241
235
}
242
236
243
237
abort( ) ;
@@ -247,7 +241,10 @@ pub async fn daemon(
247
241
248
242
info!( "Start to listen for events of elasticsearch addon custom resource" ) ;
249
243
if let Err ( err) = reconciler. watch( elasticsearch_state) . await {
250
- crit!( "Could not reconcile elasticsearch addon custom resource" ; "error" => err. to_string( ) ) ;
244
+ error!(
245
+ "Could not reconcile elasticsearch addon custom resource, {}" ,
246
+ err
247
+ ) ;
251
248
}
252
249
253
250
abort( ) ;
@@ -260,13 +257,13 @@ pub async fn daemon(
260
257
. operator
261
258
. listen
262
259
. parse ( )
263
- . map_err ( |err| DaemonError :: Listen ( config. operator . listen . to_owned ( ) , err) ) ?;
260
+ . map_err ( |err| Error :: Listen ( config. operator . listen . to_owned ( ) , err) ) ?;
264
261
265
262
let server = tokio:: spawn ( async move {
266
263
let builder = match Server :: try_bind ( & addr) {
267
264
Ok ( builder) => builder,
268
265
Err ( err) => {
269
- crit ! ( "Could not bind http server" ; "error" => err. to_string ( ) ) ;
266
+ error ! ( "Could not bind http server, {}" , err) ;
270
267
abort ( ) ;
271
268
}
272
269
} ;
@@ -277,17 +274,15 @@ pub async fn daemon(
277
274
278
275
info ! ( "Start to listen for http request on {}" , addr) ;
279
276
if let Err ( err) = server. await {
280
- crit ! ( "Could not serve http server" ; "error" => err. to_string ( ) ) ;
277
+ error ! ( "Could not serve http server, {}" , err) ;
281
278
}
282
279
283
280
abort ( )
284
281
} ) ;
285
282
286
283
// -------------------------------------------------------------------------
287
284
// Wait for termination signal
288
- tokio:: signal:: ctrl_c ( )
289
- . await
290
- . map_err ( DaemonError :: SigTerm ) ?;
285
+ tokio:: signal:: ctrl_c ( ) . await . map_err ( Error :: SigTerm ) ?;
291
286
292
287
// -------------------------------------------------------------------------
293
288
// Cancel reconcilers
@@ -296,7 +291,7 @@ pub async fn daemon(
296
291
for handle in handles {
297
292
if let Err ( err) = handle. await {
298
293
if !err. is_cancelled ( ) {
299
- error ! ( "Could not wait for the task to complete" ; "error" => err. to_string ( ) ) ;
294
+ error ! ( "Could not wait for the task to complete, {}" , err) ;
300
295
}
301
296
}
302
297
}
@@ -306,7 +301,10 @@ pub async fn daemon(
306
301
server. abort ( ) ;
307
302
if let Err ( err) = server. await {
308
303
if !err. is_cancelled ( ) {
309
- error ! ( "Could not wait for the http server to gracefully close" ; "error" => err. to_string( ) ) ;
304
+ error ! (
305
+ "Could not wait for the http server to gracefully close, {}" ,
306
+ err
307
+ ) ;
310
308
}
311
309
}
312
310
0 commit comments