@@ -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"
@@ -346,6 +348,8 @@ func NewHarness(ctx context.Context, t *testing.T) *Harness {
346
348
ctrlManagerShutdown .Wait ()
347
349
t .Log ("controller-runtime manager is shutdown" )
348
350
})
351
+ kccConfig .ManagerOptions .Logger = filterLogs (log )
352
+
349
353
mgr , err := kccmanager .New (mgrContext , h .restConfig , kccConfig )
350
354
if err != nil {
351
355
t .Fatalf ("error creating new manager: %v" , err )
@@ -549,3 +553,53 @@ func (h *Harness) ReplaceString(from, to string) func(string) string {
549
553
return strings .ReplaceAll (s , from , to )
550
554
}
551
555
}
556
+
557
+ func filterLogs (log logr.Logger ) logr.Logger {
558
+ f := & filterSink {sink : log .GetSink ()}
559
+ f .IgnoreMessages = sets .New [string ]()
560
+ f .IgnoreMessages .Insert ("Registered controller" )
561
+ f .IgnoreMessages .Insert ("Starting Controller" )
562
+ f .IgnoreMessages .Insert ("Starting EventSource" )
563
+ f .IgnoreMessages .Insert ("Starting workers" )
564
+ f .IgnoreMessages .Insert ("Shutdown signal received, waiting for all workers to finish" )
565
+ f .IgnoreMessages .Insert ("All workers finished" )
566
+ return log .WithSink (f )
567
+ }
568
+
569
+ type filterSink struct {
570
+ IgnoreMessages sets.Set [string ]
571
+ sink logr.LogSink
572
+ }
573
+
574
+ // Init implements logr.LogSink
575
+ func (s * filterSink ) Init (info logr.RuntimeInfo ) {
576
+ s .sink .Init (info )
577
+ }
578
+
579
+ // Enabled implements logr.LogSink
580
+ func (s * filterSink ) Enabled (level int ) bool {
581
+ return s .sink .Enabled (level )
582
+ }
583
+
584
+ // Info implements logr.LogSink
585
+ func (s * filterSink ) Info (level int , msg string , args ... any ) {
586
+ if s .IgnoreMessages .Has (msg ) {
587
+ return
588
+ }
589
+ s .sink .Info (level , msg , args ... )
590
+ }
591
+
592
+ // WithValues implements logr.LogSink
593
+ func (s * filterSink ) WithValues (keysAndValues ... any ) logr.LogSink {
594
+ return & filterSink {IgnoreMessages : s .IgnoreMessages , sink : s .sink .WithValues (keysAndValues ... )}
595
+ }
596
+
597
+ // WithName implements logr.LogSink
598
+ func (s * filterSink ) WithName (name string ) logr.LogSink {
599
+ return & filterSink {IgnoreMessages : s .IgnoreMessages , sink : s .sink .WithName (name )}
600
+ }
601
+
602
+ // Error implements logr.LogSink
603
+ func (s * filterSink ) Error (err error , msg string , args ... any ) {
604
+ s .sink .Error (err , msg , args ... )
605
+ }
0 commit comments