77 "time"
88
99 "github.com/google/go-cmp/cmp"
10+
1011 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1112
1213 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
@@ -201,10 +202,9 @@ func (c *GrpcRegistryReconciler) currentUpdatePods(logger *logrus.Entry, source
201202}
202203
203204func (c * GrpcRegistryReconciler ) currentPodsWithCorrectImageAndSpec (logger * logrus.Entry , source grpcCatalogSourceDecorator , serviceAccount * corev1.ServiceAccount , defaultPodSecurityConfig v1alpha1.SecurityConfig ) ([]* corev1.Pod , error ) {
204- logger .Info ("searching for current pods" )
205205 pods , err := c .Lister .CoreV1 ().PodLister ().Pods (source .GetNamespace ()).List (labels .SelectorFromValidatedSet (source .Labels ()))
206206 if err != nil {
207- logger .WithError (err ).Warn ("couldn't find pod in cache" )
207+ logger .WithError (err ).Warn ("error searching for catalog source pods: couldn't find pod in cache" )
208208 return nil , nil
209209 }
210210 found := []* corev1.Pod {}
@@ -222,7 +222,7 @@ func (c *GrpcRegistryReconciler) currentPodsWithCorrectImageAndSpec(logger *logr
222222 if ! hash {
223223 logger .Infof ("pod spec diff: %s" , cmp .Diff (p .Spec , newPod .Spec ))
224224 }
225- if correctImages ( source , p ) && podHashMatch ( p , newPod ) {
225+ if images && hash {
226226 found = append (found , p )
227227 }
228228 }
@@ -252,6 +252,7 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
252252 // if service status is nil, we force create every object to ensure they're created the first time
253253 valid , err := isRegistryServiceStatusValid (& source )
254254 if err != nil {
255+ logger .WithError (err ).Error ("error ensuring registry server: could not validate registry service status" )
255256 return err
256257 }
257258 overwrite := ! valid
@@ -262,22 +263,26 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
262263 //TODO: if any of these error out, we should write a status back (possibly set RegistryServiceStatus to nil so they get recreated)
263264 sa , err := c .ensureSA (source )
264265 if err != nil && ! apierrors .IsAlreadyExists (err ) {
266+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure registry service account" )
265267 return pkgerrors .Wrapf (err , "error ensuring service account: %s" , source .GetName ())
266268 }
267269
268270 sa , err = c .OpClient .GetServiceAccount (sa .GetNamespace (), sa .GetName ())
269271 if err != nil {
272+ logger .WithError (err ).Error ("error ensuring registry server: could not get registry service account" )
270273 return err
271274 }
272275
273276 defaultPodSecurityConfig , err := getDefaultPodContextConfig (c .OpClient , catalogSource .GetNamespace ())
274277 if err != nil {
278+ logger .WithError (err ).Error ("error ensuring registry server: could not get default pod security config" )
275279 return err
276280 }
277281
278282 // recreate the pod if no existing pod is serving the latest image or correct spec
279283 current , err := c .currentPodsWithCorrectImageAndSpec (logger , source , sa , defaultPodSecurityConfig )
280284 if err != nil {
285+ logger .WithError (err ).Error ("error ensuring registry server: could not get current pods with correct image and spec" )
281286 return err
282287 }
283288 overwritePod := overwrite || len (current ) == 0
@@ -287,29 +292,37 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
287292
288293 pod , err := source .Pod (sa , defaultPodSecurityConfig )
289294 if err != nil {
295+ logger .WithError (err ).Error ("error ensuring registry server: could not create registry pod" )
290296 return err
291297 }
292298 if err := c .ensurePod (logger , source , sa , defaultPodSecurityConfig , overwritePod ); err != nil {
299+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure registry pod" )
293300 return pkgerrors .Wrapf (err , "error ensuring pod: %s" , pod .GetName ())
294301 }
295302 if err := c .ensureUpdatePod (logger , sa , defaultPodSecurityConfig , source ); err != nil {
303+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure update pod" )
296304 if _ , ok := err .(UpdateNotReadyErr ); ok {
305+ logger .WithError (err ).Error ("error ensuring registry server: ensure update pod error is not of type UpdateNotReadyErr" )
297306 return err
298307 }
299308 return pkgerrors .Wrapf (err , "error ensuring updated catalog source pod: %s" , pod .GetName ())
300309 }
310+
301311 service , err := source .Service ()
302312 if err != nil {
313+ logger .WithError (err ).Error ("couldn't get service" )
303314 return err
304315 }
305316 if err := c .ensureService (source , overwrite ); err != nil {
317+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure service" )
306318 return pkgerrors .Wrapf (err , "error ensuring service: %s" , service .GetName ())
307319 }
308320
309321 if overwritePod {
310322 now := c .now ()
311323 service , err := source .Service ()
312324 if err != nil {
325+ logger .WithError (err ).Error ("error ensuring registry server: could not get service" )
313326 return err
314327 }
315328 catalogSource .Status .RegistryServiceStatus = & v1alpha1.RegistryServiceStatus {
@@ -603,6 +616,7 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(logger *logrus.Entry, catal
603616 serviceAccount := source .ServiceAccount ()
604617 serviceAccount , err := c .OpClient .GetServiceAccount (serviceAccount .GetNamespace (), serviceAccount .GetName ())
605618 if err != nil {
619+ logger .WithError (err ).Error ("registry service not healthy: could not get service account" )
606620 if ! apierrors .IsNotFound (err ) {
607621 return false , err
608622 }
@@ -611,25 +625,38 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(logger *logrus.Entry, catal
611625
612626 registryPodSecurityConfig , err := getDefaultPodContextConfig (c .OpClient , catalogSource .GetNamespace ())
613627 if err != nil {
628+ logger .WithError (err ).Error ("registry service not healthy: could not get registry pod security config" )
614629 return false , err
615630 }
616631
617632 // Check on registry resources
618633 // TODO: add gRPC health check
619634 service , err := c .currentService (source )
620635 if err != nil {
636+ logger .WithError (err ).Error ("registry service not healthy: could not get current service" )
621637 return false , err
622638 }
639+
623640 currentPods , err := c .currentPodsWithCorrectImageAndSpec (logger , source , serviceAccount , registryPodSecurityConfig )
624641 if err != nil {
642+ logger .WithError (err ).Error ("registry service not healthy: could not get current pods" )
625643 return false , err
626644 }
645+
646+ currentServiceAccount := c .currentServiceAccount (source )
627647 if len (currentPods ) < 1 ||
628- service == nil || c .currentServiceAccount (source ) == nil {
648+ service == nil || currentServiceAccount == nil {
649+ logger .WithFields (logrus.Fields {
650+ "numCurrentPods" : len (currentPods ),
651+ "isServiceNil" : service == nil ,
652+ "isCurrentServiceAccountNil" : currentServiceAccount == nil ,
653+ }).Error ("registry service not healthy: one or more required resources are missing" )
629654 return false , nil
630655 }
656+
631657 podsAreLive , e := detectAndDeleteDeadPods (logger , c .OpClient , currentPods , source .GetNamespace ())
632658 if e != nil {
659+ logger .WithError (e ).Error ("registry service not healthy: could not detect and delete dead pods" )
633660 return false , fmt .Errorf ("error deleting dead pods: %v" , e )
634661 }
635662 return podsAreLive , nil
0 commit comments