@@ -296,59 +296,69 @@ func StartControllers(s *options.ControllerManagerServer,
296
296
recorder record.EventRecorder ,
297
297
stop <- chan struct {}) error {
298
298
299
- // Get available service-catalog resources
300
- glog .V (5 ).Info ("Getting available resources" )
301
- availableResources , err := getAvailableResources (serviceCatalogClientBuilder )
299
+ // When Catalog Controller and Catalog API Server are started at the
300
+ // same time with API Aggregation enabled, it may take some time before
301
+ // Catalog registration shows up in API Server. Attempt to get resources
302
+ // every 10 seconds and quit after 3 minutes if unsuccessful.
303
+ var availableResources map [schema.GroupVersionResource ]bool
304
+ err := wait .PollImmediate (10 * time .Second , 3 * time .Minute , func () (bool , error ) {
305
+ var err error
306
+ availableResources , err = getAvailableResources (serviceCatalogClientBuilder )
307
+ if err != nil {
308
+ return false , err
309
+ }
310
+ return availableResources [catalogGVR ], nil
311
+ },
312
+ )
313
+
302
314
if err != nil {
315
+ if err == wait .ErrWaitTimeout {
316
+ return fmt .Errorf ("unable to start service-catalog controller: API GroupVersion %q is not available; found %#v" , catalogGVR , availableResources )
317
+ }
303
318
return err
304
319
}
305
320
321
+ // Launch service-catalog controller
306
322
coreKubeconfig = rest .AddUserAgent (coreKubeconfig , controllerManagerAgentName )
307
323
coreClient , err := kubernetes .NewForConfig (coreKubeconfig )
308
324
if err != nil {
309
325
glog .Fatal (err )
310
326
}
327
+ glog .V (5 ).Infof ("Creating shared informers; resync interval: %v" , s .ResyncInterval )
311
328
312
- // Launch service-catalog controller
313
- if availableResources [catalogGVR ] {
314
- glog .V (5 ).Infof ("Creating shared informers; resync interval: %v" , s .ResyncInterval )
315
-
316
- // Build the informer factory for service-catalog resources
317
- informerFactory := servicecataloginformers .NewSharedInformerFactory (
318
- serviceCatalogClientBuilder .ClientOrDie ("shared-informers" ),
319
- s .ResyncInterval ,
320
- )
321
- // All shared informers are v1beta1 API level
322
- serviceCatalogSharedInformers := informerFactory .Servicecatalog ().V1beta1 ()
323
-
324
- glog .V (5 ).Infof ("Creating controller; broker relist interval: %v" , s .ServiceBrokerRelistInterval )
325
- serviceCatalogController , err := controller .NewController (
326
- coreClient ,
327
- serviceCatalogClientBuilder .ClientOrDie (controllerManagerAgentName ).ServicecatalogV1beta1 (),
328
- serviceCatalogSharedInformers .ClusterServiceBrokers (),
329
- serviceCatalogSharedInformers .ClusterServiceClasses (),
330
- serviceCatalogSharedInformers .ServiceInstances (),
331
- serviceCatalogSharedInformers .ServiceBindings (),
332
- serviceCatalogSharedInformers .ClusterServicePlans (),
333
- osbclientproxy .NewClient ,
334
- s .ServiceBrokerRelistInterval ,
335
- s .OSBAPIPreferredVersion ,
336
- recorder ,
337
- s .ReconciliationRetryDuration ,
338
- s .OperationPollingMaximumBackoffDuration ,
339
- )
340
- if err != nil {
341
- return err
342
- }
329
+ // Build the informer factory for service-catalog resources
330
+ informerFactory := servicecataloginformers .NewSharedInformerFactory (
331
+ serviceCatalogClientBuilder .ClientOrDie ("shared-informers" ),
332
+ s .ResyncInterval ,
333
+ )
334
+ // All shared informers are v1beta1 API level
335
+ serviceCatalogSharedInformers := informerFactory .Servicecatalog ().V1beta1 ()
336
+
337
+ glog .V (5 ).Infof ("Creating controller; broker relist interval: %v" , s .ServiceBrokerRelistInterval )
338
+ serviceCatalogController , err := controller .NewController (
339
+ coreClient ,
340
+ serviceCatalogClientBuilder .ClientOrDie (controllerManagerAgentName ).ServicecatalogV1beta1 (),
341
+ serviceCatalogSharedInformers .ClusterServiceBrokers (),
342
+ serviceCatalogSharedInformers .ClusterServiceClasses (),
343
+ serviceCatalogSharedInformers .ServiceInstances (),
344
+ serviceCatalogSharedInformers .ServiceBindings (),
345
+ serviceCatalogSharedInformers .ClusterServicePlans (),
346
+ osbclientproxy .NewClient ,
347
+ s .ServiceBrokerRelistInterval ,
348
+ s .OSBAPIPreferredVersion ,
349
+ recorder ,
350
+ s .ReconciliationRetryDuration ,
351
+ s .OperationPollingMaximumBackoffDuration ,
352
+ )
353
+ if err != nil {
354
+ return err
355
+ }
343
356
344
- glog .V (5 ).Info ("Running controller" )
345
- go serviceCatalogController .Run (s .ConcurrentSyncs , stop )
357
+ glog .V (5 ).Info ("Running controller" )
358
+ go serviceCatalogController .Run (s .ConcurrentSyncs , stop )
346
359
347
- glog .V (1 ).Info ("Starting shared informers" )
348
- informerFactory .Start (stop )
349
- } else {
350
- return fmt .Errorf ("unable to start service-catalog controller: API GroupVersion %q is not available; found %#v" , catalogGVR , availableResources )
351
- }
360
+ glog .V (1 ).Info ("Starting shared informers" )
361
+ informerFactory .Start (stop )
352
362
353
363
select {}
354
364
}
0 commit comments