func()

in readers/apiserver/watchlist/internal/watchlist/watchlist.go [200:236]


func (r *Reader) Run(ctx context.Context) (err error) {
	if r.started {
		return fmt.Errorf("cannot call Run once the Reader has already started")
	}
	if r.ch == nil {
		return fmt.Errorf("cannot call Run if SetOut has not been called(%v)", r.ch)
	}
	r.mapCreators()
	if mapCreationErr != nil {
		return mapCreationErr
	}

	defer func() {
		if err != nil {
			r.Close(ctx)
		}
	}()

	if err := r.setupFilter(ctx); err != nil {
		return fmt.Errorf("error setting up cache: %v", err)
	}

	ctx, r.cancelWatches = context.WithCancel(context.WithoutCancel(ctx))

	for rt := range rtMap {
		if r.retrieveTypes&rt == rt {
			if err := r.startWatch(ctx, r.cancelWatches, rt); err != nil {
				if errors.Is(err, context.Canceled) {
					err = fmt.Errorf("could not connect to server by deadline")
				}
				return fmt.Errorf("error starting %s watcher: %v", rt.String(), err)
			}
		}
	}

	return nil
}