handleObject will take any resource implementing metav1.Object and attempt to find the Foo resource that 'owns' it. It does this by looking at the objects metadata.ownerReferences field for an appropriate OwnerReference. It then enqueues that Foo resource to be processed. If the object does not have
(obj interface{})
| 343 | // It then enqueues that Foo resource to be processed. If the object does not |
| 344 | // have an appropriate OwnerReference, it will simply be skipped. |
| 345 | func (c *Controller) handleObject(obj interface{}) { |
| 346 | var object metav1.Object |
| 347 | var ok bool |
| 348 | logger := klog.FromContext(context.Background()) |
| 349 | if object, ok = obj.(metav1.Object); !ok { |
| 350 | tombstone, ok := obj.(cache.DeletedFinalStateUnknown) |
| 351 | if !ok { |
| 352 | // If the object value is not too big and does not contain sensitive information then |
| 353 | // it may be useful to include it. |
| 354 | utilruntime.HandleErrorWithContext(context.Background(), nil, "Error decoding object, invalid type", "type", fmt.Sprintf("%T", obj)) |
| 355 | return |
| 356 | } |
| 357 | object, ok = tombstone.Obj.(metav1.Object) |
| 358 | if !ok { |
| 359 | // If the object value is not too big and does not contain sensitive information then |
| 360 | // it may be useful to include it. |
| 361 | utilruntime.HandleErrorWithContext(context.Background(), nil, "Error decoding object tombstone, invalid type", "type", fmt.Sprintf("%T", tombstone.Obj)) |
| 362 | return |
| 363 | } |
| 364 | logger.V(4).Info("Recovered deleted object", "resourceName", object.GetName()) |
| 365 | } |
| 366 | logger.V(4).Info("Processing object", "object", klog.KObj(object)) |
| 367 | if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { |
| 368 | // If this object is not owned by a Foo, we should not do anything more |
| 369 | // with it. |
| 370 | if ownerRef.Kind != "Foo" { |
| 371 | return |
| 372 | } |
| 373 | |
| 374 | foo, err := c.foosLister.Foos(object.GetNamespace()).Get(ownerRef.Name) |
| 375 | if err != nil { |
| 376 | logger.V(4).Info("Ignore orphaned object", "object", klog.KObj(object), "foo", ownerRef.Name) |
| 377 | return |
| 378 | } |
| 379 | |
| 380 | c.enqueueFoo(foo) |
| 381 | return |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | // newDeployment creates a new Deployment for a Foo resource. It also sets |
| 386 | // the appropriate OwnerReferences on the resource so handleObject can discover |
no test coverage detected