@@ -570,6 +570,9 @@ func (r *GlanceAPIReconciler) reconcileInit(
570570 err .Error ())
571571 return ctrlResult , err
572572 }
573+ if (ctrlResult != ctrl.Result {}) {
574+ return ctrlResult , nil
575+ }
573576 r .Log .Info (fmt .Sprintf ("Reconciled Service '%s' init successfully" , instance .Name ))
574577 return ctrl.Result {}, nil
575578}
@@ -600,7 +603,7 @@ func (r *GlanceAPIReconciler) reconcileNormal(
600603 & configVars ,
601604 )
602605 if (err != nil || ctrlResult != ctrl.Result {}) {
603- return ctrlResult , nil
606+ return ctrlResult , err
604607 }
605608 instance .Status .Conditions .MarkTrue (condition .InputReadyCondition , condition .InputReadyMessage )
606609 // run check OpenStack secret - end
@@ -661,16 +664,27 @@ func (r *GlanceAPIReconciler) reconcileNormal(
661664 case backendToken [1 ] == "cinder" :
662665 cinder := & cinderv1.Cinder {}
663666 err := r .Get (ctx , types.NamespacedName {Namespace : instance .Namespace , Name : glance .CinderName }, cinder )
664- if err != nil && ! k8s_errors .IsNotFound (err ) {
665- // Request object not found, GlanceAPI can't be executed with this config
666- r .Log .Info ("Cinder resource not found. Waiting for it to be deployed" )
667- instance .Status .Conditions .Set (condition .FalseCondition (
667+ if err != nil {
668+ if k8s_errors .IsNotFound (err ) {
669+ // Request object not found, GlanceAPI can't be executed with this config
670+ r .Log .Info ("Cinder resource not found. Waiting for it to be deployed" )
671+ instance .Status .Conditions .Set (condition .FalseCondition (
672+ glancev1 .CinderCondition ,
673+ condition .RequestedReason ,
674+ condition .SeverityInfo ,
675+ glancev1 .CinderInitMessage ),
676+ )
677+ return glance .ResultRequeue , nil
678+ }
679+
680+ instance .Status .Conditions .MarkFalse (
668681 glancev1 .CinderCondition ,
669682 condition .RequestedReason ,
670- condition .SeverityInfo ,
671- glancev1 .CinderInitMessage ),
683+ condition .SeverityError ,
684+ glancev1 .CinderReadyErrorMessage ,
685+ err .Error (),
672686 )
673- return glance . ResultRequeue , nil
687+ return ctrl. Result {}, err
674688 }
675689 // Cinder CR is found, we can unblock glance deployment because
676690 // it represents a valid backend.
@@ -755,6 +769,8 @@ func (r *GlanceAPIReconciler) reconcileNormal(
755769 err ,
756770 )
757771 return ctrlResult , err
772+ } else if (ctrlResult != ctrl.Result {}) {
773+ return ctrlResult , nil
758774 }
759775
760776 // Handle service init
@@ -928,13 +944,15 @@ func (r *GlanceAPIReconciler) reconcileNormal(
928944 }
929945 }
930946 // Cleanup existing (but not required anymore) ImageCache cronJob
931- if ctrlResult , err : = r .cleanupImageCacheJob (
947+ if ctrlResult , err = r .cleanupImageCacheJob (
932948 ctx ,
933949 helper ,
934950 instance ,
935951 GetServiceLabels (instance ),
936952 ); err != nil {
937953 return ctrlResult , err
954+ } else if (ctrlResult != ctrl.Result {}) {
955+ return ctrlResult , nil
938956 }
939957
940958 // If we reach this point, we can mark the CronJobReadyCondition as True
@@ -1232,10 +1250,7 @@ func (r *GlanceAPIReconciler) ensureDeletedEndpoints(
12321250 // It might happen that the resource is not found because it does not match
12331251 // with the one exposing the keystone endpoints. If the keystoneendpoints
12341252 // CR does not exist it doesn't mean there's an issue, hence we don't have
1235- // to do nothing, just return without an error
1236- if k8s_errors .IsNotFound (err ) {
1237- return ctrl.Result {}, nil
1238- }
1253+ // to do nothing, just return without an error (below)
12391254 if err != nil && ! k8s_errors .IsNotFound (err ) {
12401255 return ctrl.Result {}, err
12411256 }
@@ -1248,7 +1263,7 @@ func (r *GlanceAPIReconciler) ensureDeletedEndpoints(
12481263 util .LogForObject (h , "Removed finalizer from our KeystoneEndpoint" , instance )
12491264 }
12501265 }
1251- return ctrl.Result {}, err
1266+ return ctrl.Result {}, nil
12521267}
12531268
12541269func (r * GlanceAPIReconciler ) ensureImageCacheJob (
@@ -1260,8 +1275,7 @@ func (r *GlanceAPIReconciler) ensureImageCacheJob(
12601275 cjType glance.CronJobType ,
12611276) (ctrl.Result , error ) {
12621277
1263- var err error
1264- var ctrlResult ctrl.Result
1278+ var overallCtrlResult ctrl.Result
12651279
12661280 command := glance .GlanceCacheCleaner
12671281 schedule := instance .Spec .ImageCache .CleanerScheduler
@@ -1295,10 +1309,17 @@ func (r *GlanceAPIReconciler) ensureImageCacheJob(
12951309 ctrlResult , err := imageCacheCronJob .CreateOrPatch (ctx , h )
12961310 if err != nil {
12971311 return ctrlResult , err
1312+ } else if (ctrlResult != ctrl.Result {}) {
1313+ // If we get a non-empty ctrlResult here, we'll save it
1314+ // to return to the caller for their consideration. If
1315+ // more than one non-empty ctrlResult is encountered in
1316+ // the course of the encompassing loop, we'll just pick
1317+ // the last one
1318+ overallCtrlResult = ctrlResult
12981319 }
12991320 }
13001321 }
1301- return ctrlResult , err
1322+ return overallCtrlResult , nil
13021323}
13031324
13041325// cleanupImageCacheJob - delete the ImageCache cronJobs associated to a given
@@ -1309,8 +1330,8 @@ func (r *GlanceAPIReconciler) cleanupImageCacheJob(
13091330 instance * glancev1.GlanceAPI ,
13101331 serviceLabels map [string ]string ,
13111332) (ctrl.Result , error ) {
1312- var err error
1313- var ctrlResult ctrl. Result
1333+ var overallCtrlResult ctrl. Result
1334+
13141335 // Get the PVCs using labelSelector (only the PVCs associated to the current
13151336 // GlanceAPI are retrieved)
13161337 cachePVCs , _ := GetPvcListWithLabel (ctx , h , instance .Namespace , serviceLabels )
@@ -1329,13 +1350,21 @@ func (r *GlanceAPIReconciler) cleanupImageCacheJob(
13291350 }, & pod ); err != nil && k8s_errors .IsNotFound (err ) || instance .Spec .ImageCache .Size == "" {
13301351 // if we have no pod Running with the associated cache pvc,
13311352 // we can delete the imageCache cronJob if still exists
1332- if ctrlResult , err = r .deleteJob (ctx , instance , pvcName ); err != nil {
1333- return ctrl.Result {}, nil
1353+ ctrlResult , err := r .deleteJob (ctx , instance , pvcName )
1354+ if err != nil && ! k8s_errors .IsNotFound (err ) {
1355+ return ctrlResult , err
1356+ } else if (ctrlResult != ctrl.Result {}) {
1357+ // If we get a non-empty ctrlResult here, we'll save it
1358+ // to return to the caller for their consideration. If
1359+ // more than one non-empty ctrlResult is encountered in
1360+ // the course of the encompassing loop, we'll just pick
1361+ // the last one
1362+ overallCtrlResult = ctrlResult
13341363 }
13351364 }
13361365 }
13371366 }
1338- return ctrlResult , err
1367+ return overallCtrlResult , nil
13391368}
13401369
13411370// deleteJob - delete an imageCache cronJob no longer used
@@ -1345,7 +1374,6 @@ func (r *GlanceAPIReconciler) deleteJob(
13451374 pvcName string ,
13461375) (ctrl.Result , error ) {
13471376 var err error
1348- var ctrlResult ctrl.Result
13491377 var cronJob batchv1.CronJob
13501378 // For each imageCache we have both cleaner and pruner cronJobs to check and
13511379 // cleanup if the conditions are met
@@ -1363,11 +1391,11 @@ func (r *GlanceAPIReconciler) deleteJob(
13631391 continue
13641392 }
13651393 // A cronJob is found and the delete is called
1366- if err = r .Delete (ctx , & cronJob , client .PropagationPolicy (metav1 .DeletePropagationBackground )); err != nil {
1367- return ctrlResult , err
1394+ if err = r .Delete (ctx , & cronJob , client .PropagationPolicy (metav1 .DeletePropagationBackground )); err != nil && ! k8s_errors . IsNotFound ( err ) {
1395+ return ctrl. Result {} , err
13681396 }
13691397 }
1370- return ctrlResult , err
1398+ return ctrl. Result {}, nil
13711399}
13721400
13731401// getEndpointID - returns the endpointID associated to a keystone Endpoint
@@ -1397,7 +1425,7 @@ func (r *GlanceAPIReconciler) getEndpointID(
13971425 if ep .Status .EndpointIDs != nil {
13981426 epID = ep .Status .EndpointIDs [string (epType )]
13991427 }
1400- return epID , err
1428+ return epID , nil
14011429}
14021430
14031431// glanceAPIRefresh - delete a StateFulSet when a configuration for a Forbidden
@@ -1419,6 +1447,7 @@ func (r *GlanceAPIReconciler) glanceAPIRefresh(
14191447 r .Log .Info (fmt .Sprintf ("GlanceAPI %s-api: Statefulset not found." , instance .Name ))
14201448 return nil
14211449 }
1450+ return err
14221451 }
14231452 err = r .Client .Delete (ctx , sts )
14241453 if err != nil && ! k8s_errors .IsNotFound (err ) {
0 commit comments