MCPcopy
hub / github.com/open-policy-agent/gatekeeper / AddObject

Method AddObject

pkg/cachemanager/cachemanager.go:310–348  ·  view source on GitHub ↗
(ctx context.Context, instance *unstructured.Unstructured)

Source from the content-addressed store, hash-verified

308}
309
310func (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
350func (c *CacheManager) RemoveObject(ctx context.Context, instance *unstructured.Unstructured) error {
351 if _, err := c.cfClient.RemoveData(ctx, instance); err != nil {

Callers 4

TestReconcileFunction · 0.95
syncGVKMethod · 0.95
ReconcileMethod · 0.45

Calls 11

watchesGVKMethod · 0.95
GetKeyForSyncMetricsFunction · 0.92
IsNamespaceExcludedMethod · 0.80
ForDataMethod · 0.80
GetKindMethod · 0.80
AddKindMethod · 0.80
CancelExpectMethod · 0.65
GetNamespaceMethod · 0.65
GetNameMethod · 0.65
AddDataMethod · 0.65
ObserveMethod · 0.65

Tested by 2

TestReconcileFunction · 0.76