service/sync.go
func (b *bindSyncer) start() error {
	if b.started {
		return errors.New("syncer already started")
	}
	if b.appLister == nil {
		return errors.New("must set app lister function")
	}
	if b.interval == 0 {
		b.interval = 5 * time.Minute
	}
	b.shutdown = make(chan struct{}, 1)
	b.done = make(chan struct{})
	b.started = true
	log.Debugf("[bind-syncer] starting. Running every %s.\n", b.interval)
	go func(d time.Duration) {
		for {
			select {
			case <-time.After(d):
				start := time.Now()
				log.Debug("[bind-syncer] starting run")
				apps, err := b.appLister()
				if err != nil {
					log.Errorf("[bind-syncer] error listing apps: %v. Aborting sync.", err)
					syncDuration.Set(time.Since(start).Seconds())
					break
				}
				for _, a := range apps {
					err = b.sync(a)
					if err != nil {
						log.Errorf("[bind-syncer] error syncing app %q: %v", a.GetName(), err)
					}
					if len(b.shutdown) > 0 {
						break
					}
				}
				log.Debugf("[bind-syncer] finished running. Synced %d apps.", len(apps))
				d = b.interval
				syncDuration.Set(time.Since(start).Seconds())
			case <-b.shutdown:
				b.done <- struct{}{}
				return
			}
		}
	}(time.Millisecond * 100)
	return nil
}
func (b *bindSyncer) start() error {
	if b.started {
		return errors.New("syncer already started")
	}
	if b.appLister == nil {
		return errors.New("must set app lister function")
	}
	if b.interval == 0 {
		b.interval = 5 * time.Minute
	}
	b.shutdown = make(chan struct{}, 1)
	b.done = make(chan struct{})
	b.started = true
	log.Debugf("[bind-syncer] starting. Running every %s.\n", b.interval)
	go func(d time.Duration) {
		for {
			select {
			case <-time.After(d):
				start := time.Now()
				log.Debug("[bind-syncer] starting run")
				apps, err := b.appLister()
				if err != nil {
					log.Errorf("[bind-syncer] error listing apps: %v. Aborting sync.", err)
					syncDuration.Set(time.Since(start).Seconds())
					break
				}
				for _, a := range apps {
					err = b.sync(a)
					if err != nil {
						log.Errorf("[bind-syncer] error syncing app %q: %v", a.GetName(), err)
					}
					if len(b.shutdown) > 0 {
						break
					}
				}
				log.Debugf("[bind-syncer] finished running. Synced %d apps.", len(apps))
				d = b.interval
				syncDuration.Set(time.Since(start).Seconds())
			case <-b.shutdown:
				b.done <- struct{}{}
				return
			}
		}
	}(time.Millisecond * 100)
	return nil
}
// start starts the sync process on a different goroutine