| 308 | } |
| 309 | |
| 310 | func (c *CacheManager) AddObject(ctx context.Context, instance *unstructured.Unstructured) error { |
| 311 | gvk := instance.GroupVersionKind() |
| 312 | |
| 313 | isNamespaceExcluded, err := c.processExcluder.IsNamespaceExcluded(process.Sync, instance) |
| 314 | if err != nil { |
| 315 | return fmt.Errorf("error while excluding namespaces for gvk: %+v: %w", gvk, err) |
| 316 | } |
| 317 | |
| 318 | if isNamespaceExcluded { |
| 319 | c.tracker.ForData(instance.GroupVersionKind()).CancelExpect(instance) |
| 320 | return nil |
| 321 | } |
| 322 | |
| 323 | syncKey := syncutil.GetKeyForSyncMetrics(instance.GetNamespace(), instance.GetName()) |
| 324 | if c.watchesGVK(gvk) { |
| 325 | _, err = c.cfClient.AddData(ctx, instance) |
| 326 | if err != nil { |
| 327 | c.syncMetricsCache.AddObject( |
| 328 | syncKey, |
| 329 | syncutil.Tags{ |
| 330 | Kind: instance.GetKind(), |
| 331 | Status: metrics.ErrorStatus, |
| 332 | }, |
| 333 | ) |
| 334 | |
| 335 | return err |
| 336 | } |
| 337 | |
| 338 | c.syncMetricsCache.AddObject(syncKey, syncutil.Tags{ |
| 339 | Kind: instance.GetKind(), |
| 340 | Status: metrics.ActiveStatus, |
| 341 | }) |
| 342 | c.syncMetricsCache.AddKind(instance.GetKind()) |
| 343 | } |
| 344 | |
| 345 | c.tracker.ForData(instance.GroupVersionKind()).Observe(instance) |
| 346 | |
| 347 | return nil |
| 348 | } |
| 349 | |
| 350 | func (c *CacheManager) RemoveObject(ctx context.Context, instance *unstructured.Unstructured) error { |
| 351 | if _, err := c.cfClient.RemoveData(ctx, instance); err != nil { |