| 430 | } |
| 431 | |
| 432 | func (ctrl *ApplicationController) handleObjectUpdated(managedByApp map[string]bool, ref corev1.ObjectReference) { |
| 433 | // if namespaced resource is not managed by any app it might be orphaned resource of some other apps |
| 434 | if len(managedByApp) == 0 && ref.Namespace != "" { |
| 435 | // retrieve applications which monitor orphaned resources in the same namespace and refresh them unless resource is denied in app project |
| 436 | if objs, err := ctrl.appInformer.GetIndexer().ByIndex(orphanedIndex, ref.Namespace); err == nil { |
| 437 | for i := range objs { |
| 438 | app, ok := objs[i].(*appv1.Application) |
| 439 | if !ok { |
| 440 | continue |
| 441 | } |
| 442 | |
| 443 | managedByApp[app.InstanceName(ctrl.namespace)] = true |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | for appName, isManagedResource := range managedByApp { |
| 448 | // The appName is given as <namespace>_<name>, but the indexer needs it |
| 449 | // format <namespace>/<name> |
| 450 | appKey := ctrl.toAppKey(appName) |
| 451 | obj, exists, err := ctrl.appInformer.GetIndexer().GetByKey(appKey) |
| 452 | app, ok := obj.(*appv1.Application) |
| 453 | if exists && err == nil && ok && isSelfReferencedApp(app, ref) { |
| 454 | // Don't force refresh app if related resource is application itself. This prevents infinite reconciliation loop. |
| 455 | continue |
| 456 | } |
| 457 | |
| 458 | if !ctrl.canProcessApp(obj) { |
| 459 | // Don't force refresh app if app belongs to a different controller shard or is outside the allowed namespaces. |
| 460 | continue |
| 461 | } |
| 462 | |
| 463 | logCtx := log.WithFields(applog.GetAppLogFields(app)) |
| 464 | // Enforce application's permission for the source namespace |
| 465 | _, err = ctrl.getAppProj(app) |
| 466 | if err != nil { |
| 467 | logCtx.WithError(err).Errorf("Unable to determine project for app") |
| 468 | continue |
| 469 | } |
| 470 | |
| 471 | level := ComparisonWithNothing |
| 472 | if isManagedResource { |
| 473 | level = CompareWithRecent |
| 474 | } |
| 475 | |
| 476 | namespace := ref.Namespace |
| 477 | if ref.Namespace == "" { |
| 478 | namespace = "(cluster-scoped)" |
| 479 | } |
| 480 | logCtx.WithFields(log.Fields{ |
| 481 | "comparison-level": level, |
| 482 | "namespace": namespace, |
| 483 | "name": ref.Name, |
| 484 | "api-version": ref.APIVersion, |
| 485 | "kind": ref.Kind, |
| 486 | "server": app.Spec.Destination.Server, |
| 487 | "cluster-name": app.Spec.Destination.Name, |
| 488 | }).Debug("Requesting app refresh caused by object update") |
| 489 | |