@@ -83,6 +83,17 @@ func TestMain(m *testing.M) {
8383 ctx , cancel = context .WithCancel (context .Background ())
8484 defer cancel ()
8585
86+ // Logger needs to be configured before anything else happens.
87+ // This is because the controller manager has a timeout for
88+ // logger initialization, and if the logger isn't configured
89+ // after 30s from the start of controller manager package init function,
90+ // the controller manager will set up a no op logger and continue.
91+ // The logger cannot be configured after that point.
92+ logger , _ , err := testutils .SetupLoggers ("trace" , "text" , false )
93+ if err != nil {
94+ exitOnErrWithCode (fmt .Errorf ("failed to setup loggers: %w" , err ), ExitCodeCantCreateLogger )
95+ }
96+
8697 fmt .Println ("INFO: setting up test environment" )
8798 kongbuilder , extraControllerArgs := generateKongBuilder ()
8899 kongAddon := kongbuilder .Build ()
@@ -129,7 +140,6 @@ func TestMain(m *testing.M) {
129140 }
130141
131142 fmt .Println ("INFO: building test environment" )
132- var err error
133143 env , err = builder .Build (ctx )
134144 exitOnErr (err )
135145 k8sClient = env .Cluster ().Client ()
@@ -200,14 +210,14 @@ func TestMain(m *testing.M) {
200210 fmt .Sprintf ("--admission-webhook-listen=0.0.0.0:%d" , testutils .AdmissionWebhookListenPort ),
201211 "--profiling" ,
202212 "--dump-config" ,
203- "--log-level=trace" ,
204- "--debug-log-reduce-redundancy" ,
213+ "--log-level=trace" , // not used, as controller logger is configured separately
214+ "--debug-log-reduce-redundancy" , // not used, as controller logger is configured separately
205215 "--anonymous-reports=false" ,
206216 fmt .Sprintf ("--feature-gates=%s" , controllerFeatureGates ),
207217 fmt .Sprintf ("--election-namespace=%s" , kongAddon .Namespace ()),
208218 }
209219 allControllerArgs := append (standardControllerArgs , extraControllerArgs ... )
210- exitOnErr (testutils .DeployControllerManagerForCluster (ctx , env .Cluster (), allControllerArgs ... ))
220+ exitOnErr (testutils .DeployControllerManagerForCluster (ctx , logger , env .Cluster (), allControllerArgs ... ))
211221 }
212222
213223 gatewayClient , err := gatewayclient .NewForConfig (env .Cluster ().Config ())
0 commit comments