99 "sync"
1010 "time"
1111
12- log "github.com/sirupsen/logrus "
12+ "github.com/go-logr/logr "
1313 "golang.org/x/sync/semaphore"
1414 "k8s.io/apimachinery/pkg/api/errors"
1515 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -23,8 +23,10 @@ import (
2323 "k8s.io/client-go/tools/cache"
2424 "k8s.io/client-go/tools/pager"
2525 watchutil "k8s.io/client-go/tools/watch"
26+ "k8s.io/klog/v2/klogr"
2627
2728 "github.com/argoproj/gitops-engine/pkg/utils/kube"
29+ "github.com/argoproj/gitops-engine/pkg/utils/tracing"
2830)
2931
3032const (
@@ -110,21 +112,25 @@ type WeightedSemaphore interface {
110112
111113// NewClusterCache creates new instance of cluster cache
112114func NewClusterCache (config * rest.Config , opts ... UpdateSettingsFunc ) * clusterCache {
115+ log := klogr .New ()
113116 cache := & clusterCache {
114- resyncTimeout : clusterResyncTimeout ,
115- settings : Settings {ResourceHealthOverride : & noopSettings {}, ResourcesFilter : & noopSettings {}},
116- apisMeta : make (map [schema.GroupKind ]* apiMeta ),
117- listPageSize : defaultListPageSize ,
118- listPageBufferSize : defaultListPageBufferSize ,
119- listSemaphore : semaphore .NewWeighted (defaultListSemaphoreWeight ),
120- resources : make (map [kube.ResourceKey ]* Resource ),
121- nsIndex : make (map [string ]map [kube.ResourceKey ]* Resource ),
122- config : config ,
123- kubectl : & kube.KubectlCmd {},
117+ resyncTimeout : clusterResyncTimeout ,
118+ settings : Settings {ResourceHealthOverride : & noopSettings {}, ResourcesFilter : & noopSettings {}},
119+ apisMeta : make (map [schema.GroupKind ]* apiMeta ),
120+ listPageSize : defaultListPageSize ,
121+ listPageBufferSize : defaultListPageBufferSize ,
122+ listSemaphore : semaphore .NewWeighted (defaultListSemaphoreWeight ),
123+ resources : make (map [kube.ResourceKey ]* Resource ),
124+ nsIndex : make (map [string ]map [kube.ResourceKey ]* Resource ),
125+ config : config ,
126+ kubectl : & kube.KubectlCmd {
127+ Log : log ,
128+ Tracer : tracing.NopTracer {},
129+ },
124130 syncTime : nil ,
125131 resourceUpdatedHandlers : map [uint64 ]OnResourceUpdatedHandler {},
126132 eventHandlers : map [uint64 ]OnEventHandler {},
127- log : log . WithField ( "server" , config . Host ) ,
133+ log : log ,
128134 }
129135 for i := range opts {
130136 opts [i ](cache )
@@ -154,7 +160,7 @@ type clusterCache struct {
154160 nsIndex map [string ]map [kube.ResourceKey ]* Resource
155161
156162 kubectl kube.Kubectl
157- log * log. Entry
163+ log logr. Logger
158164 config * rest.Config
159165 namespaces []string
160166 settings Settings
@@ -315,7 +321,7 @@ func (c *clusterCache) Invalidate(opts ...UpdateSettingsFunc) {
315321 }
316322 c .apisMeta = nil
317323 c .namespacedResources = nil
318- c .log .Warnf ( "invalidated cluster" )
324+ c .log .Info ( "Invalidated cluster" )
319325}
320326
321327func (c * clusterCache ) synced () bool {
@@ -336,7 +342,7 @@ func (c *clusterCache) stopWatching(gk schema.GroupKind, ns string) {
336342 info .watchCancel ()
337343 delete (c .apisMeta , gk )
338344 c .replaceResourceCache (gk , nil , ns )
339- c .log .Warnf ( "Stop watching: %s not found" , gk )
345+ c .log .Info ( fmt . Sprintf ( "Stop watching: %s not found" , gk ) )
340346 }
341347}
342348
@@ -398,7 +404,7 @@ func (c *clusterCache) listResources(ctx context.Context, resClient dynamic.Reso
398404}
399405
400406func (c * clusterCache ) watchEvents (ctx context.Context , api kube.APIResourceInfo , resClient dynamic.ResourceInterface , ns string , resourceVersion string ) {
401- kube .RetryUntilSucceed (ctx , watchResourcesRetryTimeout , fmt .Sprintf ("watch %s on %s" , api .GroupKind , c .config .Host ), func () (err error ) {
407+ kube .RetryUntilSucceed (ctx , watchResourcesRetryTimeout , fmt .Sprintf ("watch %s on %s" , api .GroupKind , c .config .Host ), c . log , func () (err error ) {
402408 defer func () {
403409 if r := recover (); r != nil {
404410 err = fmt .Errorf ("Recovered from panic: %+v\n %s" , r , debug .Stack ())
@@ -493,7 +499,7 @@ func (c *clusterCache) watchEvents(ctx context.Context, api kube.APIResourceInfo
493499 return c .startMissingWatches ()
494500 })
495501 if err != nil {
496- c .log .Warnf ( "Failed to start missing watch: %v" , err )
502+ c .log .Error ( err , "Failed to start missing watch" )
497503 }
498504 }
499505 }
@@ -586,8 +592,7 @@ func (c *clusterCache) sync() error {
586592 })
587593
588594 if err != nil {
589- log .Errorf ("Failed to sync cluster %s: %v" , c .config .Host , err )
590- return err
595+ return fmt .Errorf ("failed to sync cluster %s: %v" , c .config .Host , err )
591596 }
592597
593598 c .log .Info ("Cluster successfully synced" )
@@ -653,7 +658,13 @@ func (c *clusterCache) IterateHierarchy(key kube.ResourceKey, action func(resour
653658 })
654659 child := children [0 ]
655660 action (child , nsNodes )
656- child .iterateChildren (nsNodes , map [kube.ResourceKey ]bool {res .ResourceKey (): true }, action )
661+ child .iterateChildren (nsNodes , map [kube.ResourceKey ]bool {res .ResourceKey (): true }, func (err error , child * Resource , namespaceResources map [kube.ResourceKey ]* Resource ) {
662+ if err != nil {
663+ c .log .V (2 ).Info (err .Error ())
664+ return
665+ }
666+ action (child , namespaceResources )
667+ })
657668 }
658669 }
659670 }
@@ -744,7 +755,7 @@ func (c *clusterCache) GetManagedLiveObjs(targetObjs []*unstructured.Unstructure
744755 converted , err := c .kubectl .ConvertToVersion (managedObj , targetObj .GroupVersionKind ().Group , targetObj .GroupVersionKind ().Version )
745756 if err != nil {
746757 // fallback to loading resource from kubernetes if conversion fails
747- log .Debugf ( "Failed to convert resource: %v" , err )
758+ c . log .V ( 1 ). Info ( fmt . Sprintf ( "Failed to convert resource: %v" , err ) )
748759 managedObj , err = c .kubectl .GetResource (context .TODO (), c .config , targetObj .GroupVersionKind (), managedObj .GetName (), managedObj .GetNamespace ())
749760 if err != nil {
750761 if errors .IsNotFound (err ) {
0 commit comments