(ctx context.Context, r *Registrar, gvk schema.GroupVersionKind)
| 208 | } |
| 209 | |
| 210 | func (wm *Manager) doRemoveWatch(ctx context.Context, r *Registrar, gvk schema.GroupVersionKind) error { |
| 211 | // lock acquired by caller |
| 212 | |
| 213 | v, ok := wm.watchedKinds[gvk] |
| 214 | if !ok || !v.registrars[r] { |
| 215 | // Not watching. |
| 216 | return nil |
| 217 | } |
| 218 | |
| 219 | // Cancel any replays that may be pending |
| 220 | wm.cancelReplay(r, gvk) |
| 221 | |
| 222 | // Remove this registrar from the watch list |
| 223 | delete(v.registrars, r) |
| 224 | |
| 225 | // Skip if there are additional watchers that would prevent us from removing it |
| 226 | if len(v.registrars) > 0 { |
| 227 | return nil |
| 228 | } |
| 229 | |
| 230 | log.Info("all watches removed for gvk, waiting for replays to end", "gvk", gvk) |
| 231 | |
| 232 | // Wait until all replays have exited before canceling the watch, |
| 233 | // otherwise the list may unintentionally restart a watch |
| 234 | select { |
| 235 | case <-wm.replayTracker.replayWaitCh(gvk): |
| 236 | case <-wm.stopped: |
| 237 | } |
| 238 | |
| 239 | u := &unstructured.Unstructured{} |
| 240 | u.SetGroupVersionKind(gvk) |
| 241 | if err := wm.cache.RemoveInformer(ctx, u); err != nil { |
| 242 | return fmt.Errorf("removing %+v: %w", gvk, err) |
| 243 | } |
| 244 | delete(wm.watchedKinds, gvk) |
| 245 | if err := wm.metrics.reportGvkCount(int64(len(wm.watchedKinds))); err != nil { |
| 246 | log.Error(err, "while trying to report gvk count metric") |
| 247 | } |
| 248 | log.Info("watch removed", "gvk", gvk) |
| 249 | return nil |
| 250 | } |
| 251 | |
| 252 | // replaceWatches ensures all and only desired watches are running. |
| 253 | func (wm *Manager) replaceWatches(ctx context.Context, r *Registrar) error { |
no test coverage detected