@@ -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
@@ -465,7 +457,7 @@ func (ctrl *ApplicationController) handleObjectUpdated(managedByApp map[string]b
465457 continue
466458 }
467459
468- logCtx := getAppLog ( app )
460+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
469461 // Enforce application's permission for the source namespace
470462 _ , err = ctrl .getAppProj (app )
471463 if err != nil {
@@ -501,7 +493,7 @@ func (ctrl *ApplicationController) handleObjectUpdated(managedByApp map[string]b
501493func (ctrl * ApplicationController ) setAppManagedResources (destCluster * appv1.Cluster , a * appv1.Application , comparisonResult * comparisonResult ) (* appv1.ApplicationTree , error ) {
502494 ts := stats .NewTimingStats ()
503495 defer func () {
504- logCtx := getAppLog ( a )
496+ logCtx := log . WithFields ( applog . GetAppLogFields ( a ) )
505497 for k , v := range ts .Timings () {
506498 logCtx = logCtx .WithField (k , v .Milliseconds ())
507499 }
@@ -558,7 +550,7 @@ func isKnownOrphanedResourceExclusion(key kube.ResourceKey, proj *appv1.AppProje
558550func (ctrl * ApplicationController ) getResourceTree (destCluster * appv1.Cluster , a * appv1.Application , managedResources []* appv1.ResourceDiff ) (* appv1.ApplicationTree , error ) {
559551 ts := stats .NewTimingStats ()
560552 defer func () {
561- logCtx := getAppLog ( a )
553+ logCtx := log . WithFields ( applog . GetAppLogFields ( a ) )
562554 for k , v := range ts .Timings () {
563555 logCtx = logCtx .WithField (k , v .Milliseconds ())
564556 }
@@ -688,7 +680,7 @@ func (ctrl *ApplicationController) getResourceTree(destCluster *appv1.Cluster, a
688680func (ctrl * ApplicationController ) getAppHosts (destCluster * appv1.Cluster , a * appv1.Application , appNodes []appv1.ResourceNode ) ([]appv1.HostInfo , error ) {
689681 ts := stats .NewTimingStats ()
690682 defer func () {
691- logCtx := getAppLog ( a )
683+ logCtx := log . WithFields ( applog . GetAppLogFields ( a ) )
692684 for k , v := range ts .Timings () {
693685 logCtx = logCtx .WithField (k , v .Milliseconds ())
694686 }
@@ -1016,7 +1008,7 @@ func (ctrl *ApplicationController) processAppOperationQueueItem() (processNext b
10161008 return
10171009 }
10181010 app := origApp .DeepCopy ()
1019- logCtx := getAppLog ( app )
1011+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
10201012 ts := stats .NewTimingStats ()
10211013 defer func () {
10221014 for k , v := range ts .Timings () {
@@ -1180,7 +1172,7 @@ func (ctrl *ApplicationController) getPermittedAppLiveObjects(destCluster *appv1
11801172}
11811173
11821174func (ctrl * ApplicationController ) finalizeApplicationDeletion (app * appv1.Application , projectClusters func (project string ) ([]* appv1.Cluster , error )) error {
1183- logCtx := getAppLog ( app )
1175+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
11841176 // Get refreshed application info, since informer app copy might be stale
11851177 app , err := ctrl .applicationClientset .ArgoprojV1alpha1 ().Applications (app .Namespace ).Get (context .Background (), app .Name , metav1.GetOptions {})
11861178 if err != nil {
@@ -1338,7 +1330,7 @@ func (ctrl *ApplicationController) updateFinalizers(app *appv1.Application) erro
13381330}
13391331
13401332func (ctrl * ApplicationController ) setAppCondition (app * appv1.Application , condition appv1.ApplicationCondition ) {
1341- logCtx := getAppLog ( app )
1333+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
13421334 // do nothing if app already has same condition
13431335 for _ , c := range app .Status .Conditions {
13441336 if c .Message == condition .Message && c .Type == condition .Type {
@@ -1363,7 +1355,7 @@ func (ctrl *ApplicationController) setAppCondition(app *appv1.Application, condi
13631355}
13641356
13651357func (ctrl * ApplicationController ) processRequestedAppOperation (app * appv1.Application ) {
1366- logCtx := getAppLog ( app )
1358+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
13671359 var state * appv1.OperationState
13681360 // Recover from any unexpected panics and automatically set the status to be failed
13691361 defer func () {
@@ -1501,7 +1493,7 @@ func (ctrl *ApplicationController) processRequestedAppOperation(app *appv1.Appli
15011493}
15021494
15031495func (ctrl * ApplicationController ) setOperationState (app * appv1.Application , state * appv1.OperationState ) {
1504- logCtx := getAppLog ( app )
1496+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
15051497 if state .Phase == "" {
15061498 // expose any bugs where we neglect to set phase
15071499 panic ("no phase was set" )
@@ -1579,7 +1571,7 @@ func (ctrl *ApplicationController) setOperationState(app *appv1.Application, sta
15791571// writeBackToInformer writes a just recently updated App back into the informer cache.
15801572// This prevents the situation where the controller operates on a stale app and repeats work
15811573func (ctrl * ApplicationController ) writeBackToInformer (app * appv1.Application ) {
1582- logCtx := getAppLog ( app ).WithField ("informer-writeBack" , true )
1574+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) ).WithField ("informer-writeBack" , true )
15831575 err := ctrl .appInformer .GetStore ().Update (app )
15841576 if err != nil {
15851577 logCtx .Errorf ("failed to update informer store: %v" , err )
@@ -1636,7 +1628,7 @@ func (ctrl *ApplicationController) processAppRefreshQueueItem() (processNext boo
16361628 return
16371629 }
16381630 app := origApp .DeepCopy ()
1639- logCtx := getAppLog ( app ).WithFields (log.Fields {
1631+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) ).WithFields (log.Fields {
16401632 "comparison-level" : comparisonLevel ,
16411633 "dest-server" : origApp .Spec .Destination .Server ,
16421634 "dest-name" : origApp .Spec .Destination .Name ,
@@ -1845,7 +1837,7 @@ func (ctrl *ApplicationController) processAppHydrateQueueItem() (processNext boo
18451837
18461838 ctrl .hydrator .ProcessAppHydrateQueueItem (origApp )
18471839
1848- getAppLog ( origApp ).Debug ("Successfully processed app hydrate queue item" )
1840+ log . WithFields ( applog . GetAppLogFields ( origApp ) ).Debug ("Successfully processed app hydrate queue item" )
18491841 return
18501842}
18511843
@@ -1894,7 +1886,7 @@ func currentSourceEqualsSyncedSource(app *appv1.Application) bool {
18941886// Additionally, it returns whether full refresh was requested or not.
18951887// If full refresh is requested then target and live state should be reconciled, else only live state tree should be updated.
18961888func (ctrl * ApplicationController ) needRefreshAppStatus (app * appv1.Application , statusRefreshTimeout , statusHardRefreshTimeout time.Duration ) (bool , appv1.RefreshType , CompareWith ) {
1897- logCtx := getAppLog ( app )
1889+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
18981890 var reason string
18991891 compareWith := CompareWithLatest
19001892 refreshType := appv1 .RefreshTypeNormal
@@ -1972,7 +1964,7 @@ func (ctrl *ApplicationController) refreshAppConditions(app *appv1.Application)
19721964// normalizeApplication normalizes an application.spec and additionally persists updates if it changed
19731965func (ctrl * ApplicationController ) normalizeApplication (orig , app * appv1.Application ) {
19741966 app .Spec = * argo .NormalizeApplicationSpec (& app .Spec )
1975- logCtx := getAppLog ( app )
1967+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
19761968
19771969 patch , modified , err := diff .CreateTwoWayMergePatch (orig , app , appv1.Application {})
19781970
@@ -2006,7 +1998,7 @@ func createMergePatch(orig, new any) ([]byte, bool, error) {
20061998
20071999// persistAppStatus persists updates to application status. If no changes were made, it is a no-op
20082000func (ctrl * ApplicationController ) persistAppStatus (orig * appv1.Application , newStatus * appv1.ApplicationStatus ) (patchDuration time.Duration ) {
2009- logCtx := getAppLog ( orig )
2001+ logCtx := log . WithFields ( applog . GetAppLogFields ( orig ) )
20102002 if orig .Status .Sync .Status != newStatus .Sync .Status {
20112003 message := fmt .Sprintf ("Updated sync status: %s -> %s" , orig .Status .Sync .Status , newStatus .Sync .Status )
20122004 ctrl .logAppEvent (context .TODO (), orig , argo.EventInfo {Reason : argo .EventReasonResourceUpdated , Type : corev1 .EventTypeNormal }, message )
@@ -2059,7 +2051,7 @@ func (ctrl *ApplicationController) persistAppStatus(orig *appv1.Application, new
20592051
20602052// autoSync will initiate a sync operation for an application configured with automated sync
20612053func (ctrl * ApplicationController ) autoSync (app * appv1.Application , syncStatus * appv1.SyncStatus , resources []appv1.ResourceStatus , revisionUpdated bool ) (* appv1.ApplicationCondition , time.Duration ) {
2062- logCtx := getAppLog ( app )
2054+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
20632055 ts := stats .NewTimingStats ()
20642056 defer func () {
20652057 for k , v := range ts .Timings () {
@@ -2224,16 +2216,16 @@ func alreadyAttemptedSync(app *appv1.Application, commitSHA string, commitSHAsMS
22242216 return false , ""
22252217 }
22262218 } else {
2227- log .WithField ( "application" , app . Name ).Debugf ("Skipping auto-sync: commitSHA %s has no changes" , commitSHA )
2219+ log .WithFields ( applog . GetAppLogFields ( app ) ).Debugf ("Skipping auto-sync: commitSHA %s has no changes" , commitSHA )
22282220 }
22292221 } else {
22302222 if revisionUpdated {
2231- log .WithField ( "application" , app . Name ).Infof ("Executing compare of syncResult.Revision and commitSha because manifest changed: %v" , commitSHA )
2223+ log .WithFields ( applog . GetAppLogFields ( app ) ).Infof ("Executing compare of syncResult.Revision and commitSha because manifest changed: %v" , commitSHA )
22322224 if app .Status .OperationState .SyncResult .Revision != commitSHA {
22332225 return false , ""
22342226 }
22352227 } else {
2236- log .WithField ( "application" , app . Name ).Debugf ("Skipping auto-sync: commitSHA %s has no changes" , commitSHA )
2228+ log .WithFields ( applog . GetAppLogFields ( app ) ).Debugf ("Skipping auto-sync: commitSHA %s has no changes" , commitSHA )
22372229 }
22382230 }
22392231
@@ -2297,7 +2289,7 @@ func (ctrl *ApplicationController) canProcessApp(obj any) bool {
22972289
22982290 if annotations := app .GetAnnotations (); annotations != nil {
22992291 if skipVal , ok := annotations [common .AnnotationKeyAppSkipReconcile ]; ok {
2300- logCtx := getAppLog ( app )
2292+ logCtx := log . WithFields ( applog . GetAppLogFields ( app ) )
23012293 if skipReconcile , err := strconv .ParseBool (skipVal ); err == nil {
23022294 if skipReconcile {
23032295 logCtx .Debugf ("Skipping Application reconcile based on annotation %s" , common .AnnotationKeyAppSkipReconcile )
@@ -2424,7 +2416,7 @@ func (ctrl *ApplicationController) newApplicationInformerAndLister() (cache.Shar
24242416 newApp , newOK := new .(* appv1.Application )
24252417 if oldOK && newOK {
24262418 if automatedSyncEnabled (oldApp , newApp ) {
2427- getAppLog ( newApp ).Info ("Enabled automated sync" )
2419+ log . WithFields ( applog . GetAppLogFields ( newApp ) ).Info ("Enabled automated sync" )
24282420 compareWith = CompareWithLatest .Pointer ()
24292421 }
24302422 if ctrl .statusRefreshJitter != 0 && oldApp .ResourceVersion == newApp .ResourceVersion {
0 commit comments