7
7
"time"
8
8
9
9
"github.com/google/go-cmp/cmp"
10
+
10
11
"github.com/operator-framework/api/pkg/operators/v1alpha1"
11
12
12
13
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
@@ -201,10 +202,9 @@ func (c *GrpcRegistryReconciler) currentUpdatePods(logger *logrus.Entry, source
201
202
}
202
203
203
204
func (c * GrpcRegistryReconciler ) currentPodsWithCorrectImageAndSpec (logger * logrus.Entry , source grpcCatalogSourceDecorator , serviceAccount * corev1.ServiceAccount , defaultPodSecurityConfig v1alpha1.SecurityConfig ) ([]* corev1.Pod , error ) {
204
- logger .Info ("searching for current pods" )
205
205
pods , err := c .Lister .CoreV1 ().PodLister ().Pods (source .GetNamespace ()).List (labels .SelectorFromValidatedSet (source .Labels ()))
206
206
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" )
208
208
return nil , nil
209
209
}
210
210
found := []* corev1.Pod {}
@@ -222,7 +222,7 @@ func (c *GrpcRegistryReconciler) currentPodsWithCorrectImageAndSpec(logger *logr
222
222
if ! hash {
223
223
logger .Infof ("pod spec diff: %s" , cmp .Diff (p .Spec , newPod .Spec ))
224
224
}
225
- if correctImages ( source , p ) && podHashMatch ( p , newPod ) {
225
+ if images && hash {
226
226
found = append (found , p )
227
227
}
228
228
}
@@ -252,6 +252,7 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
252
252
// if service status is nil, we force create every object to ensure they're created the first time
253
253
valid , err := isRegistryServiceStatusValid (& source )
254
254
if err != nil {
255
+ logger .WithError (err ).Error ("error ensuring registry server: could not validate registry service status" )
255
256
return err
256
257
}
257
258
overwrite := ! valid
@@ -262,22 +263,26 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
262
263
//TODO: if any of these error out, we should write a status back (possibly set RegistryServiceStatus to nil so they get recreated)
263
264
sa , err := c .ensureSA (source )
264
265
if err != nil && ! apierrors .IsAlreadyExists (err ) {
266
+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure registry service account" )
265
267
return pkgerrors .Wrapf (err , "error ensuring service account: %s" , source .GetName ())
266
268
}
267
269
268
270
sa , err = c .OpClient .GetServiceAccount (sa .GetNamespace (), sa .GetName ())
269
271
if err != nil {
272
+ logger .WithError (err ).Error ("error ensuring registry server: could not get registry service account" )
270
273
return err
271
274
}
272
275
273
276
defaultPodSecurityConfig , err := getDefaultPodContextConfig (c .OpClient , catalogSource .GetNamespace ())
274
277
if err != nil {
278
+ logger .WithError (err ).Error ("error ensuring registry server: could not get default pod security config" )
275
279
return err
276
280
}
277
281
278
282
// recreate the pod if no existing pod is serving the latest image or correct spec
279
283
current , err := c .currentPodsWithCorrectImageAndSpec (logger , source , sa , defaultPodSecurityConfig )
280
284
if err != nil {
285
+ logger .WithError (err ).Error ("error ensuring registry server: could not get current pods with correct image and spec" )
281
286
return err
282
287
}
283
288
overwritePod := overwrite || len (current ) == 0
@@ -287,29 +292,37 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, cata
287
292
288
293
pod , err := source .Pod (sa , defaultPodSecurityConfig )
289
294
if err != nil {
295
+ logger .WithError (err ).Error ("error ensuring registry server: could not create registry pod" )
290
296
return err
291
297
}
292
298
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" )
293
300
return pkgerrors .Wrapf (err , "error ensuring pod: %s" , pod .GetName ())
294
301
}
295
302
if err := c .ensureUpdatePod (logger , sa , defaultPodSecurityConfig , source ); err != nil {
303
+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure update pod" )
296
304
if _ , ok := err .(UpdateNotReadyErr ); ok {
305
+ logger .WithError (err ).Error ("error ensuring registry server: ensure update pod error is not of type UpdateNotReadyErr" )
297
306
return err
298
307
}
299
308
return pkgerrors .Wrapf (err , "error ensuring updated catalog source pod: %s" , pod .GetName ())
300
309
}
310
+
301
311
service , err := source .Service ()
302
312
if err != nil {
313
+ logger .WithError (err ).Error ("couldn't get service" )
303
314
return err
304
315
}
305
316
if err := c .ensureService (source , overwrite ); err != nil {
317
+ logger .WithError (err ).Error ("error ensuring registry server: could not ensure service" )
306
318
return pkgerrors .Wrapf (err , "error ensuring service: %s" , service .GetName ())
307
319
}
308
320
309
321
if overwritePod {
310
322
now := c .now ()
311
323
service , err := source .Service ()
312
324
if err != nil {
325
+ logger .WithError (err ).Error ("error ensuring registry server: could not get service" )
313
326
return err
314
327
}
315
328
catalogSource .Status .RegistryServiceStatus = & v1alpha1.RegistryServiceStatus {
@@ -603,6 +616,7 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(logger *logrus.Entry, catal
603
616
serviceAccount := source .ServiceAccount ()
604
617
serviceAccount , err := c .OpClient .GetServiceAccount (serviceAccount .GetNamespace (), serviceAccount .GetName ())
605
618
if err != nil {
619
+ logger .WithError (err ).Error ("registry service not healthy: could not get service account" )
606
620
if ! apierrors .IsNotFound (err ) {
607
621
return false , err
608
622
}
@@ -611,25 +625,38 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(logger *logrus.Entry, catal
611
625
612
626
registryPodSecurityConfig , err := getDefaultPodContextConfig (c .OpClient , catalogSource .GetNamespace ())
613
627
if err != nil {
628
+ logger .WithError (err ).Error ("registry service not healthy: could not get registry pod security config" )
614
629
return false , err
615
630
}
616
631
617
632
// Check on registry resources
618
633
// TODO: add gRPC health check
619
634
service , err := c .currentService (source )
620
635
if err != nil {
636
+ logger .WithError (err ).Error ("registry service not healthy: could not get current service" )
621
637
return false , err
622
638
}
639
+
623
640
currentPods , err := c .currentPodsWithCorrectImageAndSpec (logger , source , serviceAccount , registryPodSecurityConfig )
624
641
if err != nil {
642
+ logger .WithError (err ).Error ("registry service not healthy: could not get current pods" )
625
643
return false , err
626
644
}
645
+
646
+ currentServiceAccount := c .currentServiceAccount (source )
627
647
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" )
629
654
return false , nil
630
655
}
656
+
631
657
podsAreLive , e := detectAndDeleteDeadPods (logger , c .OpClient , currentPods , source .GetNamespace ())
632
658
if e != nil {
659
+ logger .WithError (e ).Error ("registry service not healthy: could not detect and delete dead pods" )
633
660
return false , fmt .Errorf ("error deleting dead pods: %v" , e )
634
661
}
635
662
return podsAreLive , nil
0 commit comments