66 "strings"
77 "time"
88
9- "github.com/google/go-cmp/cmp"
109 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1110
1211 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
@@ -201,10 +200,9 @@ func (c *GrpcRegistryReconciler) currentUpdatePods(logger *logrus.Entry, source
201200}
202201
203202func (c * GrpcRegistryReconciler ) currentPodsWithCorrectImageAndSpec (logger * logrus.Entry , source grpcCatalogSourceDecorator , serviceAccount * corev1.ServiceAccount , defaultPodSecurityConfig v1alpha1.SecurityConfig ) ([]* corev1.Pod , error ) {
204- logger .Info ("searching for current pods" )
205203 pods , err := c .Lister .CoreV1 ().PodLister ().Pods (source .GetNamespace ()).List (labels .SelectorFromValidatedSet (source .Labels ()))
206204 if err != nil {
207- logger .WithError (err ).Warn ("couldn't find pod in cache" )
205+ logger .WithError (err ).Warn ("error searching for catalog source pods: couldn't find pod in cache" )
208206 return nil , nil
209207 }
210208 found := []* corev1.Pod {}
@@ -213,20 +211,10 @@ func (c *GrpcRegistryReconciler) currentPodsWithCorrectImageAndSpec(logger *logr
213211 return nil , err
214212 }
215213 for _ , p := range pods {
216- images , hash := correctImages (source , p ), podHashMatch (p , newPod )
217- logger = logger .WithFields (logrus.Fields {
218- "current-pod.namespace" : p .Namespace , "current-pod.name" : p .Name ,
219- "correctImages" : images , "correctHash" : hash ,
220- })
221- logger .Info ("evaluating current pod" )
222- if ! hash {
223- logger .Infof ("pod spec diff: %s" , cmp .Diff (p .Spec , newPod .Spec ))
224- }
225214 if correctImages (source , p ) && podHashMatch (p , newPod ) {
226215 found = append (found , p )
227216 }
228217 }
229- logger .Infof ("of %d pods matching label selector, %d have the correct images and matching hash" , len (pods ), len (found ))
230218 return found , nil
231219}
232220
@@ -252,64 +240,71 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
252240 // if service status is nil, we force create every object to ensure they're created the first time
253241 valid , err := isRegistryServiceStatusValid (& source )
254242 if err != nil {
243+ logger .WithError (err ).Error ("error ensuring registry server: could not validate registry service status" )
255244 return err
256245 }
257246 overwrite := ! valid
258- if overwrite {
259- logger .Info ("registry service status invalid, need to overwrite" )
260- }
261247
262248 //TODO: if any of these error out, we should write a status back (possibly set RegistryServiceStatus to nil so they get recreated)
263249 sa , err := c .ensureSA (source )
264250 if err != nil && ! apierrors .IsAlreadyExists (err ) {
251+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure registry service account" )
265252 return pkgerrors .Wrapf (err , "error ensuring service account: %s" , source .GetName ())
266253 }
267254
268255 sa , err = c .OpClient .GetServiceAccount (sa .GetNamespace (), sa .GetName ())
269256 if err != nil {
257+ logger .WithError (err ).Error ("error ensuring registry server: could not get registry service account" )
270258 return err
271259 }
272260
273261 defaultPodSecurityConfig , err := getDefaultPodContextConfig (c .OpClient , catalogSource .GetNamespace ())
274262 if err != nil {
263+ logger .WithError (err ).Error ("error ensuring registry server: could not get default pod security config" )
275264 return err
276265 }
277266
278267 // recreate the pod if no existing pod is serving the latest image or correct spec
279268 current , err := c .currentPodsWithCorrectImageAndSpec (logger , source , sa , defaultPodSecurityConfig )
280269 if err != nil {
270+ logger .WithError (err ).Error ("error ensuring registry server: could not get current pods with correct image and spec" )
281271 return err
282272 }
283273 overwritePod := overwrite || len (current ) == 0
284- if overwritePod {
285- logger .Info ("registry pods invalid, need to overwrite" )
286- }
287274
288275 pod , err := source .Pod (sa , defaultPodSecurityConfig )
289276 if err != nil {
277+ logger .WithError (err ).Error ("error ensuring registry server: could not create registry pod" )
290278 return err
291279 }
292280 if err := c .ensurePod (logger , source , sa , defaultPodSecurityConfig , overwritePod ); err != nil {
281+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure registry pod" )
293282 return pkgerrors .Wrapf (err , "error ensuring pod: %s" , pod .GetName ())
294283 }
295284 if err := c .ensureUpdatePod (logger , sa , defaultPodSecurityConfig , source ); err != nil {
285+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure update pod" )
296286 if _ , ok := err .(UpdateNotReadyErr ); ok {
287+ logger .WithError (err ).Error ("error ensuring registry server: ensure update pod error is not of type UpdateNotReadyErr" )
297288 return err
298289 }
299290 return pkgerrors .Wrapf (err , "error ensuring updated catalog source pod: %s" , pod .GetName ())
300291 }
292+
301293 service , err := source .Service ()
302294 if err != nil {
295+ logger .WithError (err ).Error ("couldn't get service" )
303296 return err
304297 }
305298 if err := c .ensureService (source , overwrite ); err != nil {
299+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure service" )
306300 return pkgerrors .Wrapf (err , "error ensuring service: %s" , service .GetName ())
307301 }
308302
309303 if overwritePod {
310304 now := c .now ()
311305 service , err := source .Service ()
312306 if err != nil {
307+ logger .WithError (err ).Error ("error ensuring registry server: could not get service" )
313308 return err
314309 }
315310 catalogSource .Status .RegistryServiceStatus = & v1alpha1.RegistryServiceStatus {
@@ -603,6 +598,7 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(logger *logrus.Entry, catal
603598 serviceAccount := source .ServiceAccount ()
604599 serviceAccount , err := c .OpClient .GetServiceAccount (serviceAccount .GetNamespace (), serviceAccount .GetName ())
605600 if err != nil {
601+ logger .WithError (err ).Error ("registry service not healthy: could not get service account" )
606602 if ! apierrors .IsNotFound (err ) {
607603 return false , err
608604 }
@@ -611,27 +607,41 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(logger *logrus.Entry, catal
611607
612608 registryPodSecurityConfig , err := getDefaultPodContextConfig (c .OpClient , catalogSource .GetNamespace ())
613609 if err != nil {
610+ logger .WithError (err ).Error ("registry service not healthy: could not get registry pod security config" )
614611 return false , err
615612 }
616613
617614 // Check on registry resources
618615 // TODO: add gRPC health check
619616 service , err := c .currentService (source )
620617 if err != nil {
618+ logger .WithError (err ).Error ("registry service not healthy: could not get current service" )
621619 return false , err
622620 }
621+
623622 currentPods , err := c .currentPodsWithCorrectImageAndSpec (logger , source , serviceAccount , registryPodSecurityConfig )
624623 if err != nil {
624+ logger .WithError (err ).Error ("registry service not healthy: could not get current pods" )
625625 return false , err
626626 }
627+
628+ currentServiceAccount := c .currentServiceAccount (source )
627629 if len (currentPods ) < 1 ||
628- service == nil || c .currentServiceAccount (source ) == nil {
630+ service == nil || currentServiceAccount == nil {
631+ logger .WithFields (logrus.Fields {
632+ "numCurrentPods" : len (currentPods ),
633+ "isServiceNil" : service == nil ,
634+ "isCurrentServiceAccountNil" : currentServiceAccount == nil ,
635+ }).Error ("registry service not healthy: one or more required resources are missing" )
629636 return false , nil
630637 }
638+
631639 podsAreLive , e := detectAndDeleteDeadPods (logger , c .OpClient , currentPods , source .GetNamespace ())
632640 if e != nil {
641+ logger .WithError (e ).Error ("registry service not healthy: could not detect and delete dead pods" )
633642 return false , fmt .Errorf ("error deleting dead pods: %v" , e )
634643 }
644+
635645 return podsAreLive , nil
636646}
637647
0 commit comments