@@ -2,6 +2,7 @@ use crate::history::operations::pdb::add_pdbs;
22use crate :: product_logging:: { self , resolve_vector_aggregator_address} ;
33use crate :: Ctx ;
44use product_config:: { types:: PropertyNameKind , writer:: to_java_properties_string} ;
5+ use stackable_operator:: kube:: core:: { error_boundary, DeserializeGuard } ;
56use stackable_operator:: {
67 builder:: {
78 self ,
@@ -196,6 +197,11 @@ pub enum Error {
196197 AddVolumeMount {
197198 source : builder:: pod:: container:: Error ,
198199 } ,
200+
201+ #[ snafu( display( "SparkHistoryServer object is invalid" ) ) ]
202+ InvalidSparkHistoryServer {
203+ source : error_boundary:: InvalidObject ,
204+ } ,
199205}
200206
201207type Result < T , E = Error > = std:: result:: Result < T , E > ;
@@ -206,9 +212,18 @@ impl ReconcilerError for Error {
206212 }
207213}
208214/// Updates the status of the SparkApplication that started the pod.
209- pub async fn reconcile ( shs : Arc < SparkHistoryServer > , ctx : Arc < Ctx > ) -> Result < Action > {
215+ pub async fn reconcile (
216+ shs : Arc < DeserializeGuard < SparkHistoryServer > > ,
217+ ctx : Arc < Ctx > ,
218+ ) -> Result < Action > {
210219 tracing:: info!( "Starting reconcile history server" ) ;
211220
221+ let shs = shs
222+ . 0
223+ . as_ref ( )
224+ . map_err ( error_boundary:: InvalidObject :: clone)
225+ . context ( InvalidSparkHistoryServerSnafu ) ?;
226+
212227 let client = & ctx. client ;
213228
214229 let mut cluster_resources = ClusterResources :: new (
@@ -244,7 +259,7 @@ pub async fn reconcile(shs: Arc<SparkHistoryServer>, ctx: Arc<Ctx>) -> Result<Ac
244259
245260 // Use a dedicated service account for history server pods.
246261 let ( serviceaccount, rolebinding) =
247- build_history_role_serviceaccount ( & shs, & resolved_product_image. app_version_label ) ?;
262+ build_history_role_serviceaccount ( shs, & resolved_product_image. app_version_label ) ?;
248263 let serviceaccount = cluster_resources
249264 . add ( client, serviceaccount)
250265 . await
@@ -261,7 +276,7 @@ pub async fn reconcile(shs: Arc<SparkHistoryServer>, ctx: Arc<Ctx>) -> Result<Ac
261276 . iter ( )
262277 {
263278 let service = build_service (
264- & shs,
279+ shs,
265280 & resolved_product_image. app_version_label ,
266281 role_name,
267282 None ,
@@ -273,7 +288,7 @@ pub async fn reconcile(shs: Arc<SparkHistoryServer>, ctx: Arc<Ctx>) -> Result<Ac
273288
274289 for ( rolegroup_name, rolegroup_config) in role_config. iter ( ) {
275290 let rgr = RoleGroupRef {
276- cluster : ObjectRef :: from_obj ( & * shs) ,
291+ cluster : ObjectRef :: from_obj ( shs) ,
277292 role : role_name. into ( ) ,
278293 role_group : rolegroup_name. into ( ) ,
279294 } ;
@@ -283,7 +298,7 @@ pub async fn reconcile(shs: Arc<SparkHistoryServer>, ctx: Arc<Ctx>) -> Result<Ac
283298 . context ( FailedToResolveConfigSnafu ) ?;
284299
285300 let service = build_service (
286- & shs,
301+ shs,
287302 & resolved_product_image. app_version_label ,
288303 role_name,
289304 Some ( & rgr) ,
@@ -294,7 +309,7 @@ pub async fn reconcile(shs: Arc<SparkHistoryServer>, ctx: Arc<Ctx>) -> Result<Ac
294309 . context ( ApplyServiceSnafu ) ?;
295310
296311 let config_map = build_config_map (
297- & shs,
312+ shs,
298313 rolegroup_config,
299314 & merged_config,
300315 & resolved_product_image. app_version_label ,
@@ -308,7 +323,7 @@ pub async fn reconcile(shs: Arc<SparkHistoryServer>, ctx: Arc<Ctx>) -> Result<Ac
308323 . context ( ApplyConfigMapSnafu ) ?;
309324
310325 let sts = build_stateful_set (
311- & shs,
326+ shs,
312327 & resolved_product_image,
313328 & rgr,
314329 & log_dir,
@@ -324,7 +339,7 @@ pub async fn reconcile(shs: Arc<SparkHistoryServer>, ctx: Arc<Ctx>) -> Result<Ac
324339 let role_config = & shs. spec . nodes . role_config ;
325340 add_pdbs (
326341 & role_config. pod_disruption_budget ,
327- & shs,
342+ shs,
328343 client,
329344 & mut cluster_resources,
330345 )
@@ -340,8 +355,15 @@ pub async fn reconcile(shs: Arc<SparkHistoryServer>, ctx: Arc<Ctx>) -> Result<Ac
340355 Ok ( Action :: await_change ( ) )
341356}
342357
343- pub fn error_policy ( _obj : Arc < SparkHistoryServer > , _error : & Error , _ctx : Arc < Ctx > ) -> Action {
344- Action :: requeue ( * Duration :: from_secs ( 5 ) )
358+ pub fn error_policy (
359+ _obj : Arc < DeserializeGuard < SparkHistoryServer > > ,
360+ error : & Error ,
361+ _ctx : Arc < Ctx > ,
362+ ) -> Action {
363+ match error {
364+ Error :: InvalidSparkHistoryServer { .. } => Action :: await_change ( ) ,
365+ _ => Action :: requeue ( * Duration :: from_secs ( 5 ) ) ,
366+ }
345367}
346368
347369#[ allow( clippy:: result_large_err) ]
0 commit comments