func (c *Controller) Run(stopCh <-chan struct{}) {
	// handle a panic with logging and exiting
	defer utilruntime.HandleCrash()
	// ignore new items in the queue but when all goroutines
	// have completed existing items then shutdown
	defer c.queue.ShutDown()

	logrus.Info("Initiating controller")
	c.informer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: func(obj interface{}) {
			key, err := cache.MetaNamespaceKeyFunc(obj)
			logrus.WithField("prowjob", key).Infof("Add prowjob")
			if err != nil {
				logrus.WithError(err).Error("Cannot get key from object meta")
				return
			}
			c.queue.AddRateLimited(key)
		},
		UpdateFunc: func(oldObj, newObj interface{}) {
			key, err := cache.MetaNamespaceKeyFunc(newObj)
			logrus.WithField("prowjob", key).Infof("Update prowjob")
			if err != nil {
				logrus.WithError(err).Error("Cannot get key from object meta")
				return
			}
			c.queue.AddRateLimited(key)
		},
	})

	// run the informer to start listing and watching resources
	go c.informer.Informer().Run(stopCh)

	// do the initial synchronization (one time) to populate resources
	if !cache.WaitForCacheSync(stopCh, c.HasSynced) {
		utilruntime.HandleError(fmt.Errorf("Error syncing cache"))
		return
	}
	logrus.Info("Controller.Run: cache sync complete")

	// run the runWorker method every second with a stop channel
	for i := 0; i < c.numWorkers; i++ {
		go wait.Until(c.runWorker, time.Second, stopCh)
	}

	logrus.Infof("Started %d workers", c.numWorkers)
	<-stopCh
	logrus.Info("Shutting down workers")
}
func (c *Controller) Run(stopCh <-chan struct{}) {
	
	defer utilruntime.HandleCrash()
	
	
	defer c.queue.ShutDown()

	logrus.Info("Initiating controller")
	c.informer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: func(obj interface{}) {
			key, err := cache.MetaNamespaceKeyFunc(obj)
			logrus.WithField("prowjob", key).Infof("Add prowjob")
			if err != nil {
				logrus.WithError(err).Error("Cannot get key from object meta")
				return
			}
			c.queue.AddRateLimited(key)
		},
		UpdateFunc: func(oldObj, newObj interface{}) {
			key, err := cache.MetaNamespaceKeyFunc(newObj)
			logrus.WithField("prowjob", key).Infof("Update prowjob")
			if err != nil {
				logrus.WithError(err).Error("Cannot get key from object meta")
				return
			}
			c.queue.AddRateLimited(key)
		},
	})

	
	go c.informer.Informer().Run(stopCh)

	
	if !cache.WaitForCacheSync(stopCh, c.HasSynced) {
		utilruntime.HandleError(fmt.Errorf("Error syncing cache"))
		return
	}
	logrus.Info("Controller.Run: cache sync complete")

	
	for i := 0; i < c.numWorkers; i++ {
		go wait.Until(c.runWorker, time.Second, stopCh)
	}

	logrus.Infof("Started %d workers", c.numWorkers)
	<-stopCh
	logrus.Info("Shutting down workers")
}
func ( c * Controller ) Run ( stopCh <- chan struct { } ) { // handle a panic with logging and exiting defer utilruntime . HandleCrash ( ) // ignore new items in the queue but when all goroutines // have completed existing items then shutdown defer c . queue . ShutDown ( ) logrus . Info ( " " ) c . informer . Informer ( ) . AddEventHandler ( cache . ResourceEventHandlerFuncs { AddFunc : func ( obj interface { } ) { key , err := cache . MetaNamespaceKeyFunc ( obj ) logrus . WithField ( " " , key ) . Infof ( " " ) if err != nil { logrus . WithError ( err ) . Error ( " " ) return } c . queue . AddRateLimited ( key ) } , UpdateFunc : func ( oldObj , newObj interface { } ) { key , err := cache . MetaNamespaceKeyFunc ( newObj ) logrus . WithField ( " " , key ) . Infof ( " " ) if err != nil { logrus . WithError ( err ) . Error ( " " ) return } c . queue . AddRateLimited ( key ) } , } ) // run the informer to start listing and watching resources go c . informer . Informer ( ) . Run ( stopCh ) // do the initial synchronization (one time) to populate resources if ! cache . WaitForCacheSync ( stopCh , c . HasSynced ) { utilruntime . HandleError ( fmt . Errorf ( " " ) ) return } logrus . Info ( " " ) // run the runWorker method every second with a stop channel for i := 0 ; i < c . numWorkers ; i ++ { go wait . Until ( c . runWorker , time . Second , stopCh ) } logrus . Infof ( " " , c . numWorkers ) <- stopCh logrus . Info ( " " ) }
// Run is the main path of execution for the controller loop.
Run is the main path of execution for the controller loop .