@@ -24,6 +24,7 @@ import (
24
24
"testing"
25
25
"time"
26
26
27
+ "github.com/go-logr/logr"
27
28
"github.com/google/go-cmp/cmp"
28
29
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
29
30
"golang.org/x/oauth2"
@@ -33,6 +34,7 @@ import (
33
34
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
34
35
"k8s.io/apimachinery/pkg/runtime/schema"
35
36
"k8s.io/apimachinery/pkg/types"
37
+ "k8s.io/apimachinery/pkg/util/sets"
36
38
"k8s.io/apimachinery/pkg/util/wait"
37
39
"k8s.io/client-go/rest"
38
40
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -344,6 +346,8 @@ func NewHarness(t *testing.T, ctx context.Context) *Harness {
344
346
ctrlManagerShutdown .Wait ()
345
347
t .Log ("controller-runtime manager is shutdown" )
346
348
})
349
+ kccConfig .ManagerOptions .Logger = filterLogs (log )
350
+
347
351
mgr , err := kccmanager .New (mgrContext , h .restConfig , kccConfig )
348
352
if err != nil {
349
353
t .Fatalf ("error creating new manager: %v" , err )
@@ -545,3 +549,53 @@ func (h *Harness) ReplaceString(from, to string) func(string) string {
545
549
return strings .ReplaceAll (s , from , to )
546
550
}
547
551
}
552
+
553
+ func filterLogs (log logr.Logger ) logr.Logger {
554
+ f := & filterSink {sink : log .GetSink ()}
555
+ f .IgnoreMessages = sets .New [string ]()
556
+ f .IgnoreMessages .Insert ("Registered controller" )
557
+ f .IgnoreMessages .Insert ("Starting Controller" )
558
+ f .IgnoreMessages .Insert ("Starting EventSource" )
559
+ f .IgnoreMessages .Insert ("Starting workers" )
560
+ f .IgnoreMessages .Insert ("Shutdown signal received, waiting for all workers to finish" )
561
+ f .IgnoreMessages .Insert ("All workers finished" )
562
+ return log .WithSink (f )
563
+ }
564
+
565
+ type filterSink struct {
566
+ IgnoreMessages sets.Set [string ]
567
+ sink logr.LogSink
568
+ }
569
+
570
+ // Init implements logr.LogSink
571
+ func (s * filterSink ) Init (info logr.RuntimeInfo ) {
572
+ s .sink .Init (info )
573
+ }
574
+
575
+ // Enabled implements logr.LogSink
576
+ func (s * filterSink ) Enabled (level int ) bool {
577
+ return s .sink .Enabled (level )
578
+ }
579
+
580
+ // Info implements logr.LogSink
581
+ func (s * filterSink ) Info (level int , msg string , args ... any ) {
582
+ if s .IgnoreMessages .Has (msg ) {
583
+ return
584
+ }
585
+ s .sink .Info (level , msg , args ... )
586
+ }
587
+
588
+ // WithValues implements logr.LogSink
589
+ func (s * filterSink ) WithValues (keysAndValues ... any ) logr.LogSink {
590
+ return & filterSink {IgnoreMessages : s .IgnoreMessages , sink : s .sink .WithValues (keysAndValues ... )}
591
+ }
592
+
593
+ // WithName implements logr.LogSink
594
+ func (s * filterSink ) WithName (name string ) logr.LogSink {
595
+ return & filterSink {IgnoreMessages : s .IgnoreMessages , sink : s .sink .WithName (name )}
596
+ }
597
+
598
+ // Error implements logr.LogSink
599
+ func (s * filterSink ) Error (err error , msg string , args ... any ) {
600
+ s .sink .Error (err , msg , args ... )
601
+ }
0 commit comments