@@ -54,6 +54,7 @@ import (
5454 "github.com/argoproj/argo-cd/v3/pkg/client/informers/externalversions/application/v1alpha1"
5555 applisters "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1"
5656 "github.com/argoproj/argo-cd/v3/reposerver/apiclient"
57+ applog "github.com/argoproj/argo-cd/v3/util/app/log"
5758 "github.com/argoproj/argo-cd/v3/util/argo"
5859 argodiff "github.com/argoproj/argo-cd/v3/util/argo/diff"
5960 "github.com/argoproj/argo-cd/v3/util/argo/normalizers"
@@ -98,15 +99,6 @@ func (a CompareWith) Pointer() *CompareWith {
9899 return & a
99100}
100101
101- func getAppLog (app * appv1.Application ) * log.Entry {
102- return log .WithFields (log.Fields {
103- "application" : app .Name ,
104- "app-namespace" : app .Namespace ,
105- "app-qualified-name" : app .QualifiedName (),
106- "project" : app .Spec .Project ,
107- })
108- }
109-
110102// ApplicationController is the controller for application resources.
111103type ApplicationController struct {
112104 cache * appstatecache.Cache
@@ -439,7 +431,7 @@ func (ctrl *ApplicationController) handleObjectUpdated(managedByApp map[string]b
439431 continue
440432 }
441433
442- logCtx := getAppLog ( app )
434+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
443435 // Enforce application's permission for the source namespace
444436 _ , err = ctrl .getAppProj (app )
445437 if err != nil {
@@ -475,7 +467,7 @@ func (ctrl *ApplicationController) handleObjectUpdated(managedByApp map[string]b
475467func (ctrl * ApplicationController ) setAppManagedResources (destCluster * appv1.Cluster , a * appv1.Application , comparisonResult * comparisonResult ) (* appv1.ApplicationTree , error ) {
476468 ts := stats .NewTimingStats ()
477469 defer func () {
478- logCtx := getAppLog ( a )
470+ logCtx := log . WithFields ( applog . GetAppLog ( a ) )
479471 for k , v := range ts .Timings () {
480472 logCtx = logCtx .WithField (k , v .Milliseconds ())
481473 }
@@ -532,7 +524,7 @@ func isKnownOrphanedResourceExclusion(key kube.ResourceKey, proj *appv1.AppProje
532524func (ctrl * ApplicationController ) getResourceTree (destCluster * appv1.Cluster , a * appv1.Application , managedResources []* appv1.ResourceDiff ) (* appv1.ApplicationTree , error ) {
533525 ts := stats .NewTimingStats ()
534526 defer func () {
535- logCtx := getAppLog ( a )
527+ logCtx := log . WithFields ( applog . GetAppLog ( a ) )
536528 for k , v := range ts .Timings () {
537529 logCtx = logCtx .WithField (k , v .Milliseconds ())
538530 }
@@ -662,7 +654,7 @@ func (ctrl *ApplicationController) getResourceTree(destCluster *appv1.Cluster, a
662654func (ctrl * ApplicationController ) getAppHosts (destCluster * appv1.Cluster , a * appv1.Application , appNodes []appv1.ResourceNode ) ([]appv1.HostInfo , error ) {
663655 ts := stats .NewTimingStats ()
664656 defer func () {
665- logCtx := getAppLog ( a )
657+ logCtx := log . WithFields ( applog . GetAppLog ( a ) )
666658 for k , v := range ts .Timings () {
667659 logCtx = logCtx .WithField (k , v .Milliseconds ())
668660 }
@@ -990,7 +982,7 @@ func (ctrl *ApplicationController) processAppOperationQueueItem() (processNext b
990982 return
991983 }
992984 app := origApp .DeepCopy ()
993- logCtx := getAppLog ( app )
985+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
994986 ts := stats .NewTimingStats ()
995987 defer func () {
996988 for k , v := range ts .Timings () {
@@ -1154,7 +1146,7 @@ func (ctrl *ApplicationController) getPermittedAppLiveObjects(destCluster *appv1
11541146}
11551147
11561148func (ctrl * ApplicationController ) finalizeApplicationDeletion (app * appv1.Application , projectClusters func (project string ) ([]* appv1.Cluster , error )) error {
1157- logCtx := getAppLog ( app )
1149+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
11581150 // Get refreshed application info, since informer app copy might be stale
11591151 app , err := ctrl .applicationClientset .ArgoprojV1alpha1 ().Applications (app .Namespace ).Get (context .Background (), app .Name , metav1.GetOptions {})
11601152 if err != nil {
@@ -1312,7 +1304,7 @@ func (ctrl *ApplicationController) updateFinalizers(app *appv1.Application) erro
13121304}
13131305
13141306func (ctrl * ApplicationController ) setAppCondition (app * appv1.Application , condition appv1.ApplicationCondition ) {
1315- logCtx := getAppLog ( app )
1307+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
13161308 // do nothing if app already has same condition
13171309 for _ , c := range app .Status .Conditions {
13181310 if c .Message == condition .Message && c .Type == condition .Type {
@@ -1337,7 +1329,7 @@ func (ctrl *ApplicationController) setAppCondition(app *appv1.Application, condi
13371329}
13381330
13391331func (ctrl * ApplicationController ) processRequestedAppOperation (app * appv1.Application ) {
1340- logCtx := getAppLog ( app )
1332+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
13411333 var state * appv1.OperationState
13421334 // Recover from any unexpected panics and automatically set the status to be failed
13431335 defer func () {
@@ -1473,7 +1465,7 @@ func (ctrl *ApplicationController) processRequestedAppOperation(app *appv1.Appli
14731465}
14741466
14751467func (ctrl * ApplicationController ) setOperationState (app * appv1.Application , state * appv1.OperationState ) {
1476- logCtx := getAppLog ( app )
1468+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
14771469 if state .Phase == "" {
14781470 // expose any bugs where we neglect to set phase
14791471 panic ("no phase was set" )
@@ -1551,7 +1543,7 @@ func (ctrl *ApplicationController) setOperationState(app *appv1.Application, sta
15511543// writeBackToInformer writes a just recently updated App back into the informer cache.
15521544// This prevents the situation where the controller operates on a stale app and repeats work
15531545func (ctrl * ApplicationController ) writeBackToInformer (app * appv1.Application ) {
1554- logCtx := getAppLog ( app ).WithField ("informer-writeBack" , true )
1546+ logCtx := log . WithFields ( applog . GetAppLog ( app ) ).WithField ("informer-writeBack" , true )
15551547 err := ctrl .appInformer .GetStore ().Update (app )
15561548 if err != nil {
15571549 logCtx .Errorf ("failed to update informer store: %v" , err )
@@ -1608,7 +1600,7 @@ func (ctrl *ApplicationController) processAppRefreshQueueItem() (processNext boo
16081600 return
16091601 }
16101602 app := origApp .DeepCopy ()
1611- logCtx := getAppLog ( app ).WithFields (log.Fields {
1603+ logCtx := log . WithFields ( applog . GetAppLog ( app ) ).WithFields (log.Fields {
16121604 "comparison-level" : comparisonLevel ,
16131605 "dest-server" : origApp .Spec .Destination .Server ,
16141606 "dest-name" : origApp .Spec .Destination .Name ,
@@ -1814,7 +1806,7 @@ func (ctrl *ApplicationController) processAppHydrateQueueItem() (processNext boo
18141806
18151807 ctrl .hydrator .ProcessAppHydrateQueueItem (origApp )
18161808
1817- getAppLog ( origApp ).Debug ("Successfully processed app hydrate queue item" )
1809+ log . WithFields ( applog . GetAppLog ( origApp ) ).Debug ("Successfully processed app hydrate queue item" )
18181810 return
18191811}
18201812
@@ -1863,7 +1855,7 @@ func currentSourceEqualsSyncedSource(app *appv1.Application) bool {
18631855// Additionally, it returns whether full refresh was requested or not.
18641856// If full refresh is requested then target and live state should be reconciled, else only live state tree should be updated.
18651857func (ctrl * ApplicationController ) needRefreshAppStatus (app * appv1.Application , statusRefreshTimeout , statusHardRefreshTimeout time.Duration ) (bool , appv1.RefreshType , CompareWith ) {
1866- logCtx := getAppLog ( app )
1858+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
18671859 var reason string
18681860 compareWith := CompareWithLatest
18691861 refreshType := appv1 .RefreshTypeNormal
@@ -1941,7 +1933,7 @@ func (ctrl *ApplicationController) refreshAppConditions(app *appv1.Application)
19411933// normalizeApplication normalizes an application.spec and additionally persists updates if it changed
19421934func (ctrl * ApplicationController ) normalizeApplication (orig , app * appv1.Application ) {
19431935 app .Spec = * argo .NormalizeApplicationSpec (& app .Spec )
1944- logCtx := getAppLog ( app )
1936+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
19451937
19461938 patch , modified , err := diff .CreateTwoWayMergePatch (orig , app , appv1.Application {})
19471939
@@ -1975,7 +1967,7 @@ func createMergePatch(orig, new any) ([]byte, bool, error) {
19751967
19761968// persistAppStatus persists updates to application status. If no changes were made, it is a no-op
19771969func (ctrl * ApplicationController ) persistAppStatus (orig * appv1.Application , newStatus * appv1.ApplicationStatus ) (patchMs time.Duration ) {
1978- logCtx := getAppLog ( orig )
1970+ logCtx := log . WithFields ( applog . GetAppLog ( orig ) )
19791971 if orig .Status .Sync .Status != newStatus .Sync .Status {
19801972 message := fmt .Sprintf ("Updated sync status: %s -> %s" , orig .Status .Sync .Status , newStatus .Sync .Status )
19811973 ctrl .logAppEvent (context .TODO (), orig , argo.EventInfo {Reason : argo .EventReasonResourceUpdated , Type : corev1 .EventTypeNormal }, message )
@@ -2020,7 +2012,7 @@ func (ctrl *ApplicationController) persistAppStatus(orig *appv1.Application, new
20202012
20212013// autoSync will initiate a sync operation for an application configured with automated sync
20222014func (ctrl * ApplicationController ) autoSync (app * appv1.Application , syncStatus * appv1.SyncStatus , resources []appv1.ResourceStatus , revisionUpdated bool ) (* appv1.ApplicationCondition , time.Duration ) {
2023- logCtx := getAppLog ( app )
2015+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
20242016 ts := stats .NewTimingStats ()
20252017 defer func () {
20262018 for k , v := range ts .Timings () {
@@ -2181,16 +2173,16 @@ func alreadyAttemptedSync(app *appv1.Application, commitSHA string, commitSHAsMS
21812173 return false , ""
21822174 }
21832175 } else {
2184- log .WithField ( "application" , app . Name ).Debugf ("Skipping auto-sync: commitSHA %s has no changes" , commitSHA )
2176+ log .WithFields ( applog . GetAppLog ( app ) ).Debugf ("Skipping auto-sync: commitSHA %s has no changes" , commitSHA )
21852177 }
21862178 } else {
21872179 if revisionUpdated {
2188- log .WithField ( "application" , app . Name ).Infof ("Executing compare of syncResult.Revision and commitSha because manifest changed: %v" , commitSHA )
2180+ log .WithFields ( applog . GetAppLog ( app ) ).Infof ("Executing compare of syncResult.Revision and commitSha because manifest changed: %v" , commitSHA )
21892181 if app .Status .OperationState .SyncResult .Revision != commitSHA {
21902182 return false , ""
21912183 }
21922184 } else {
2193- log .WithField ( "application" , app . Name ).Debugf ("Skipping auto-sync: commitSHA %s has no changes" , commitSHA )
2185+ log .WithFields ( applog . GetAppLog ( app ) ).Debugf ("Skipping auto-sync: commitSHA %s has no changes" , commitSHA )
21942186 }
21952187 }
21962188
@@ -2249,7 +2241,7 @@ func (ctrl *ApplicationController) canProcessApp(obj any) bool {
22492241
22502242 if annotations := app .GetAnnotations (); annotations != nil {
22512243 if skipVal , ok := annotations [common .AnnotationKeyAppSkipReconcile ]; ok {
2252- logCtx := getAppLog ( app )
2244+ logCtx := log . WithFields ( applog . GetAppLog ( app ) )
22532245 if skipReconcile , err := strconv .ParseBool (skipVal ); err == nil {
22542246 if skipReconcile {
22552247 logCtx .Debugf ("Skipping Application reconcile based on annotation %s" , common .AnnotationKeyAppSkipReconcile )
@@ -2376,7 +2368,7 @@ func (ctrl *ApplicationController) newApplicationInformerAndLister() (cache.Shar
23762368 newApp , newOK := new .(* appv1.Application )
23772369 if oldOK && newOK {
23782370 if automatedSyncEnabled (oldApp , newApp ) {
2379- getAppLog ( newApp ).Info ("Enabled automated sync" )
2371+ log . WithFields ( applog . GetAppLog ( newApp ) ).Info ("Enabled automated sync" )
23802372 compareWith = CompareWithLatest .Pointer ()
23812373 }
23822374 if ctrl .statusRefreshJitter != 0 && oldApp .ResourceVersion == newApp .ResourceVersion {
0 commit comments