@@ -79,6 +79,7 @@ impl EvaluationEnvironment {
79
79
always_accept_admission_reviews_on_namespace : Option < String > ,
80
80
policy_evaluation_limit_seconds : Option < u64 > ,
81
81
callback_handler_tx : mpsc:: Sender < CallbackRequest > ,
82
+ continue_on_errors : bool ,
82
83
) -> Result < Self > {
83
84
let mut eval_env = Self {
84
85
always_accept_admission_reviews_on_namespace,
@@ -114,7 +115,7 @@ impl EvaluationEnvironment {
114
115
)
115
116
. map_err ( |e| EvaluationError :: BootstrapFailure ( e. to_string ( ) ) ) ?;
116
117
117
- eval_env. validate_settings ( policy_id) ?;
118
+ eval_env. validate_settings ( policy_id, continue_on_errors ) ?;
118
119
}
119
120
120
121
Ok ( eval_env)
@@ -236,7 +237,11 @@ impl EvaluationEnvironment {
236
237
}
237
238
238
239
/// Validate the settings the user provided for the given policy
239
- fn validate_settings ( & mut self , policy_id : & str ) -> Result < ( ) > {
240
+ fn validate_settings (
241
+ & mut self ,
242
+ policy_id : & str ,
243
+ continue_on_policy_initialization_errors : bool ,
244
+ ) -> Result < ( ) > {
240
245
let settings = self . get_policy_settings ( policy_id) ?;
241
246
let mut evaluator = self . rehydrate ( policy_id) ?;
242
247
@@ -249,13 +254,17 @@ impl EvaluationEnvironment {
249
254
valid : false ,
250
255
message,
251
256
} => {
252
- self . policy_initialization_errors . insert (
253
- policy_id. to_string ( ) ,
254
- format ! (
255
- "Policy settings are invalid: {}" ,
256
- message. unwrap_or( "no message" . to_owned( ) )
257
- ) ,
257
+ let error_message = format ! (
258
+ "Policy settings are invalid: {}" ,
259
+ message. unwrap_or( "no message" . to_owned( ) )
258
260
) ;
261
+
262
+ if !continue_on_policy_initialization_errors {
263
+ return Err ( EvaluationError :: PolicyInitialization ( error_message) ) ;
264
+ }
265
+
266
+ self . policy_initialization_errors
267
+ . insert ( policy_id. to_string ( ) , error_message. clone ( ) ) ;
259
268
}
260
269
} ;
261
270
@@ -371,6 +380,7 @@ mod tests {
371
380
None ,
372
381
None ,
373
382
callback_handler_tx,
383
+ true ,
374
384
)
375
385
}
376
386
0 commit comments