@@ -3,10 +3,10 @@ package reconciler
33import  (
44	"context" 
55	"fmt" 
6+ 	"github.com/google/go-cmp/cmp" 
67	"strings" 
78	"time" 
89
9- 	"github.com/google/go-cmp/cmp" 
1010	"github.com/operator-framework/api/pkg/operators/v1alpha1" 
1111
1212	"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install" 
@@ -201,10 +201,9 @@ func (c *GrpcRegistryReconciler) currentUpdatePods(logger *logrus.Entry, source
201201}
202202
203203func  (c  * GrpcRegistryReconciler ) currentPodsWithCorrectImageAndSpec (logger  * logrus.Entry , source  grpcCatalogSourceDecorator , serviceAccount  * corev1.ServiceAccount , defaultPodSecurityConfig  v1alpha1.SecurityConfig ) ([]* corev1.Pod , error ) {
204- 	logger .Info ("searching for current pods" )
205204	pods , err  :=  c .Lister .CoreV1 ().PodLister ().Pods (source .GetNamespace ()).List (labels .SelectorFromValidatedSet (source .Labels ()))
206205	if  err  !=  nil  {
207- 		logger .WithError (err ).Warn ("couldn't find pod in cache" )
206+ 		logger .WithError (err ).Warn ("error searching for catalog source pods:  couldn't find pod in cache" )
208207		return  nil , nil 
209208	}
210209	found  :=  []* corev1.Pod {}
@@ -222,7 +221,7 @@ func (c *GrpcRegistryReconciler) currentPodsWithCorrectImageAndSpec(logger *logr
222221		if  ! hash  {
223222			logger .Infof ("pod spec diff: %s" , cmp .Diff (p .Spec , newPod .Spec ))
224223		}
225- 		if  correctImages ( source ,  p )  &&  podHashMatch ( p ,  newPod )  {
224+ 		if  images   &&  hash  {
226225			found  =  append (found , p )
227226		}
228227	}
@@ -252,6 +251,7 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
252251	// if service status is nil, we force create every object to ensure they're created the first time 
253252	valid , err  :=  isRegistryServiceStatusValid (& source )
254253	if  err  !=  nil  {
254+ 		logger .WithError (err ).Error ("error ensuring registry server: could not validate registry service status" )
255255		return  err 
256256	}
257257	overwrite  :=  ! valid 
@@ -262,22 +262,26 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
262262	//TODO: if any of these error out, we should write a status back (possibly set RegistryServiceStatus to nil so they get recreated) 
263263	sa , err  :=  c .ensureSA (source )
264264	if  err  !=  nil  &&  ! apierrors .IsAlreadyExists (err ) {
265+ 		logger .WithError (err ).Error ("error ensuring registry server: could not ensure registry service account" )
265266		return  pkgerrors .Wrapf (err , "error ensuring service account: %s" , source .GetName ())
266267	}
267268
268269	sa , err  =  c .OpClient .GetServiceAccount (sa .GetNamespace (), sa .GetName ())
269270	if  err  !=  nil  {
271+ 		logger .WithError (err ).Error ("error ensuring registry server: could not get registry service account" )
270272		return  err 
271273	}
272274
273275	defaultPodSecurityConfig , err  :=  getDefaultPodContextConfig (c .OpClient , catalogSource .GetNamespace ())
274276	if  err  !=  nil  {
277+ 		logger .WithError (err ).Error ("error ensuring registry server: could not get default pod security config" )
275278		return  err 
276279	}
277280
278281	// recreate the pod if no existing pod is serving the latest image or correct spec 
279282	current , err  :=  c .currentPodsWithCorrectImageAndSpec (logger , source , sa , defaultPodSecurityConfig )
280283	if  err  !=  nil  {
284+ 		logger .WithError (err ).Error ("error ensuring registry server: could not get current pods with correct image and spec" )
281285		return  err 
282286	}
283287	overwritePod  :=  overwrite  ||  len (current ) ==  0 
@@ -287,29 +291,37 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
287291
288292	pod , err  :=  source .Pod (sa , defaultPodSecurityConfig )
289293	if  err  !=  nil  {
294+ 		logger .WithError (err ).Error ("error ensuring registry server: could not create registry pod" )
290295		return  err 
291296	}
292297	if  err  :=  c .ensurePod (logger , source , sa , defaultPodSecurityConfig , overwritePod ); err  !=  nil  {
298+ 		logger .WithError (err ).Error ("error ensuring registry server: could not ensure registry pod" )
293299		return  pkgerrors .Wrapf (err , "error ensuring pod: %s" , pod .GetName ())
294300	}
295301	if  err  :=  c .ensureUpdatePod (logger , sa , defaultPodSecurityConfig , source ); err  !=  nil  {
302+ 		logger .WithError (err ).Error ("error ensuring registry server: could not ensure update pod" )
296303		if  _ , ok  :=  err .(UpdateNotReadyErr ); ok  {
304+ 			logger .WithError (err ).Error ("error ensuring registry server: ensure update pod error is not of type UpdateNotReadyErr" )
297305			return  err 
298306		}
299307		return  pkgerrors .Wrapf (err , "error ensuring updated catalog source pod: %s" , pod .GetName ())
300308	}
309+ 
301310	service , err  :=  source .Service ()
302311	if  err  !=  nil  {
312+ 		logger .WithError (err ).Error ("couldn't get service" )
303313		return  err 
304314	}
305315	if  err  :=  c .ensureService (source , overwrite ); err  !=  nil  {
316+ 		logger .WithError (err ).Error ("error ensuring registry server: could not ensure service" )
306317		return  pkgerrors .Wrapf (err , "error ensuring service: %s" , service .GetName ())
307318	}
308319
309320	if  overwritePod  {
310321		now  :=  c .now ()
311322		service , err  :=  source .Service ()
312323		if  err  !=  nil  {
324+ 			logger .WithError (err ).Error ("error ensuring registry server: could not get service" )
313325			return  err 
314326		}
315327		catalogSource .Status .RegistryServiceStatus  =  & v1alpha1.RegistryServiceStatus {
@@ -603,6 +615,7 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(logger *logrus.Entry, catal
603615	serviceAccount  :=  source .ServiceAccount ()
604616	serviceAccount , err  :=  c .OpClient .GetServiceAccount (serviceAccount .GetNamespace (), serviceAccount .GetName ())
605617	if  err  !=  nil  {
618+ 		logger .WithError (err ).Error ("registry service not healthy: could not get service account" )
606619		if  ! apierrors .IsNotFound (err ) {
607620			return  false , err 
608621		}
@@ -611,25 +624,38 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(logger *logrus.Entry, catal
611624
612625	registryPodSecurityConfig , err  :=  getDefaultPodContextConfig (c .OpClient , catalogSource .GetNamespace ())
613626	if  err  !=  nil  {
627+ 		logger .WithError (err ).Error ("registry service not healthy: could not get registry pod security config" )
614628		return  false , err 
615629	}
616630
617631	// Check on registry resources 
618632	// TODO: add gRPC health check 
619633	service , err  :=  c .currentService (source )
620634	if  err  !=  nil  {
635+ 		logger .WithError (err ).Error ("registry service not healthy: could not get current service" )
621636		return  false , err 
622637	}
638+ 
623639	currentPods , err  :=  c .currentPodsWithCorrectImageAndSpec (logger , source , serviceAccount , registryPodSecurityConfig )
624640	if  err  !=  nil  {
641+ 		logger .WithError (err ).Error ("registry service not healthy: could not get current pods" )
625642		return  false , err 
626643	}
644+ 
645+ 	currentServiceAccount  :=  c .currentServiceAccount (source )
627646	if  len (currentPods ) <  1  || 
628- 		service  ==  nil  ||  c .currentServiceAccount (source ) ==  nil  {
647+ 		service  ==  nil  ||  currentServiceAccount  ==  nil  {
648+ 		logger .WithFields (logrus.Fields {
649+ 			"numCurrentPods" :             len (currentPods ),
650+ 			"isServiceNil" :               service  ==  nil ,
651+ 			"isCurrentServiceAccountNil" : currentServiceAccount  ==  nil ,
652+ 		}).Error ("registry service not healthy: one or more required resources are missing" )
629653		return  false , nil 
630654	}
655+ 
631656	podsAreLive , e  :=  detectAndDeleteDeadPods (logger , c .OpClient , currentPods , source .GetNamespace ())
632657	if  e  !=  nil  {
658+ 		logger .WithError (e ).Error ("registry service not healthy: could not detect and delete dead pods" )
633659		return  false , fmt .Errorf ("error deleting dead pods: %v" , e )
634660	}
635661	return  podsAreLive , nil 
0 commit comments