// watchSettings watches the configmap and secret for any setting updates that would warrant a
// restart of the API server.
491899
func (a *ArgoCDServer) watchSettings(ctx context.Context) {
	updateCh := make(chan *settings_util.ArgoCDSettings, 1)
	a.settingsMgr.Subscribe(updateCh)

	prevURL := a.settings.URL
	prevOIDCConfig := a.settings.OIDCConfigRAW
	prevDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings)
	errors.CheckError(err)
	prevGitHubSecret := a.settings.WebhookGitHubSecret
	prevGitLabSecret := a.settings.WebhookGitLabSecret
	prevBitBucketUUID := a.settings.WebhookBitbucketUUID
	var prevCert, prevCertKey string
	if a.settings.Certificate != nil {
		prevCert, prevCertKey = tlsutil.EncodeX509KeyPairString(*a.settings.Certificate)
	}

	for {
		newSettings := <-updateCh
		a.settings = newSettings
		newDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings)
		errors.CheckError(err)
		if string(newDexCfgBytes) != string(prevDexCfgBytes) {
			log.Infof("dex config modified. restarting")
			break
		}
		if prevOIDCConfig != a.settings.OIDCConfigRAW {
			log.Infof("odic config modified. restarting")
			break
		}
		if prevURL != a.settings.URL {
			log.Infof("url modified. restarting")
			break
		}
		if prevGitHubSecret != a.settings.WebhookGitHubSecret {
			log.Infof("github secret modified. restarting")
			break
		}
		if prevGitLabSecret != a.settings.WebhookGitLabSecret {
			log.Infof("gitlab secret modified. restarting")
			break
		}
		if prevBitBucketUUID != a.settings.WebhookBitbucketUUID {
			log.Infof("bitbucket uuid modified. restarting")
			break
		}
		var newCert, newCertKey string
		if a.settings.Certificate != nil {
			newCert, newCertKey = tlsutil.EncodeX509KeyPairString(*a.settings.Certificate)
		}
		if newCert != prevCert || newCertKey != prevCertKey {
			log.Infof("tls certificate modified. restarting")
			break
		}
	}
	log.Info("shutting down settings watch")
	a.Shutdown()
	a.settingsMgr.Unsubscribe(updateCh)
	close(updateCh)
}
563075
func (s *serviceAccounts) Watch(opts api.ListOptions) (watch.Interface, error) {
	return s.client.Get().
		Prefix("watch").
		Namespace(s.namespace).
		Resource("serviceAccounts").
		VersionedParams(&opts, api.Scheme).
		Watch()
}
1250727
func (c *Client) Watch(resp func(keyval.BytesWatchResp), closeChan chan string, keys ...string) error {
	consulLogger.Debug("Watch:", keys)
	for _, k := range keys {
		if err := c.watch(resp, closeChan, k); err != nil {
			return err
		}
	}
	return nil
}
169927
func (w *Watcher) WatchFlags(path string, flags uint32) error {
	w.fsnmut.Lock()
	w.fsnFlags[path] = flags
	w.fsnmut.Unlock()
	return w.watch(path)
}
306947
func (lsa *LeadershipSettingsAccessor) WatchLeadershipSettings(appId string) (watcher.NotifyWatcher, error) {

	if err := lsa.checkAPIVersion("WatchLeadershipSettings"); err != nil {
		return nil, errors.Annotatef(err, "cannot access leadership api")
	}
	var results params.NotifyWatchResults
	if err := lsa.facadeCaller(
		"WatchLeadershipSettings",
		params.Entities{[]params.Entity{{names.NewApplicationTag(appId).String()}}},
		&results,
	); err != nil {
		return nil, errors.Annotate(err, "failed to call leadership api")
	}
	if count := len(results.Results); count != 1 {
		return nil, errors.Errorf("expected 1 result from leadership api, got %d", count)
	}
	if results.Results[0].Error != nil {
		return nil, errors.Annotatef(results.Results[0].Error, "failed to watch leadership settings")
	}
	return lsa.newNotifyWatcher(results.Results[0]), nil
}
210490
func (m *Model) WatchConfig(keys ...string) *ConfigWatcher {
	return newConfigWatcher(keys, m.hashCache, m.hub, m.topic(modelConfigChange), m.Resident)
}
215762
func (i *Info) Watch(resourceVersion string) (watch.Interface, error) {
	return NewHelper(i.Client, i.Mapping).WatchSingle(i.Namespace, i.Name, resourceVersion)
}
734629
func (w *Watcher) WatchCollection(collection string, ch chan<- Change) {
	w.WatchCollectionWithFilter(collection, ch, nil)
}
797692
func (a *Application) WatchConfig(keys ...string) *ConfigWatcher {
	w := newConfigWatcher(keys, a.hashCache, a.hub, a.topic(applicationConfigChange), a.Resident)
	return w
}
1010432
func (adapter *Adapter) Watch(resyncName string, changeChan chan datasync.ChangeEvent,
	resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error) {

	logrus.DefaultLogger().Debug("REST KeyValProtoWatcher WatchData ", resyncName, " ", keyPrefixes)

	for _, keyPrefix := range keyPrefixes {
		adapter.registerHTTPHandler(keyPrefix+"{suffix}", adapter.putMessage, "PUT")
		adapter.registerHTTPHandler(keyPrefix+"{suffix}", adapter.delMessage, "DELETE")
		//TODO adapter.registerHTTPHandler(keyPrefix + "{suffix}", getMessage, "GET")
		//TODO httpmux.RegisterHTTPHandler("/vpprestcon/resync", putResync, "PUT")
	}

	return adapter.base.Watch(resyncName, changeChan, resyncChan, keyPrefixes...)
}
107918
func (u *UnitUpgraderAPI) WatchAPIVersion(args params.Entities) (params.NotifyWatchResults, error) {
	result := params.NotifyWatchResults{
		Results: make([]params.NotifyWatchResult, len(args.Entities)),
	}
	for i, agent := range args.Entities {
		tag, err := names.ParseTag(agent.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}
		err = common.ErrPerm
		if u.authorizer.AuthOwner(tag) {
			var watcherId string
			watcherId, err = u.watchAssignedMachine(tag)
			if err == nil {
				result.Results[i].NotifyWatcherId = watcherId
			}
		}
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
400351
func (c *Client) Watch(resp func(keyval.BytesWatchResp), closeChan chan string, keys ...string) error {
	boltLogger.Debugf("Watch: %q", keys)
	for _, k := range keys {
		if err := c.watch(resp, closeChan, k); err != nil {
			return err
		}
	}
	return nil
}
891237
func (u *UpdateJob) WatchTime(ms int32) *UpdateJob {
	u.req.Settings.MinWaitInInstanceRunningMs = ms
	return u
}
1097345
func (api *API) Watch() params.NotifyWatchResult {
	watch := api.backend.WatchForMigration()
	if _, ok := <-watch.Changes(); ok {
		return params.NotifyWatchResult{
			NotifyWatcherId: api.resources.Register(watch),
		}
	}
	return params.NotifyWatchResult{
		Error: common.ServerError(watcher.EnsureErr(watch)),
	}
}
1271405
func (m *Machine) WatchUnits() (watcher.StringsWatcher, error) {
	var results params.StringsWatchResults
	args := params.Entities{
		Entities: []params.Entity{{Tag: m.tag.String()}},
	}
	err := m.facade.FacadeCall("WatchUnits", args, &results)
	if err != nil {
		return nil, err
	}
	if len(results.Results) != 1 {
		return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
	}
	result := results.Results[0]
	if result.Error != nil {
		return nil, result.Error
	}
	w := apiwatcher.NewStringsWatcher(m.facade.RawAPICaller(), result)
	return w, nil
}
979441
func (u *UnitsWatcher) WatchUnits(args params.Entities) (params.StringsWatchResults, error) {
	result := params.StringsWatchResults{
		Results: make([]params.StringsWatchResult, len(args.Entities)),
	}
	if len(args.Entities) == 0 {
		return result, nil
	}
	canWatch, err := u.getCanWatch()
	if err != nil {
		return params.StringsWatchResults{}, errors.Trace(err)
	}
	for i, entity := range args.Entities {
		tag, err := names.ParseTag(entity.Tag)
		if err != nil {
			result.Results[i].Error = ServerError(ErrPerm)
			continue
		}
		entityResult, err := u.watchOneEntityUnits(canWatch, tag)
		result.Results[i] = entityResult
		result.Results[i].Error = ServerError(err)
	}
	return result, nil
}
394920
func (k *kubernetesClient) WatchUnits(appName string) (watcher.NotifyWatcher, error) {
	selector := applicationSelector(appName)
	logger.Debugf("selecting units %q to watch", selector)
	w, err := k.client().CoreV1().Pods(k.namespace).Watch(v1.ListOptions{
		LabelSelector:        selector,
		Watch:                true,
		IncludeUninitialized: true,
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	return k.newWatcher(w, appName, k.clock)
}