code: func (gb *GraphBuilder) syncMonitors(resources map[schema.GroupVersionResource]struct{}) error {
  	gb.monitorLock.Lock()
  	defer gb.monitorLock.Unlock()
  
  	toRemove := gb.monitors
  	if toRemove == nil {
  		toRemove = monitors{}
  	}
  	current := monitors{}
  	errs := []error{}
  	kept := 0
  	added := 0
  	for resource := range resources {
  		if _, ok := gb.ignoredResources[resource.GroupResource()]; ok {
  			continue
  		}
  		if m, ok := toRemove[resource]; ok {
  			current[resource] = m
  			delete(toRemove, resource)
  			kept++
  			continue
  		}
  		kind, err := gb.restMapper.KindFor(resource)
  		if err != nil {
  			errs = append(errs, fmt.Errorf("couldn't look up resource %q: %v", resource, err))
  			continue
  		}
  		c, s, err := gb.controllerFor(resource, kind)
  		if err != nil {
  			errs = append(errs, fmt.Errorf("couldn't start monitor for resource %q: %v", resource, err))
  			continue
  		}
  		current[resource] = &monitor{store: s, controller: c}
  		added++
  	}
  	gb.monitors = current
  
  	for _, monitor := range toRemove {
  		if monitor.stopCh != nil {
  			close(monitor.stopCh)
  		}
  	}
  
  	klog.V(4).Infof("synced monitors; added %d, kept %d, removed %d", added, kept, len(toRemove))
  	// NewAggregate returns nil if errs is 0-length
  	return utilerrors.NewAggregate(errs)
  }
docs: // syncMonitors rebuilds the monitor set according to the supplied resources,
  // creating or deleting monitors as necessary. It will return any error
  // encountered, but will make an attempt to create a monitor for each resource
  // instead of immediately exiting on an error. It may be called before or after
  // Run. Monitors are NOT started as part of the sync. To ensure all existing
  // monitors are started, call startMonitors.