@@ -51,9 +51,9 @@ const schemaVersion string = "v2.0.0"
5151
5252// Run starts the agent process
5353func Run (cmd * cobra.Command , args []string ) (returnErr error ) {
54- ctx , cancel := context .WithCancel (cmd .Context ())
54+ baseCtx , cancel := context .WithCancel (cmd .Context ())
5555 defer cancel ()
56- log := klog .FromContext (ctx ).WithName ("Run" )
56+ log := klog .FromContext (baseCtx ).WithName ("Run" )
5757
5858 log .Info ("Starting" , "version" , version .PreflightVersion , "commit" , version .Commit )
5959
@@ -78,7 +78,7 @@ func Run(cmd *cobra.Command, args []string) (returnErr error) {
7878 return fmt .Errorf ("While evaluating configuration: %v" , err )
7979 }
8080
81- group , gctx := errgroup .WithContext (ctx )
81+ group , gctx := errgroup .WithContext (baseCtx )
8282 defer func () {
8383 cancel ()
8484 if groupErr := group .Wait (); groupErr != nil {
@@ -123,13 +123,14 @@ func Run(cmd *cobra.Command, args []string) (returnErr error) {
123123 })
124124
125125 group .Go (func () error {
126+ listenCtx := klog .NewContext (gctx , log )
126127 err := listenAndServe (
127- klog . NewContext ( gctx , log ) ,
128+ listenCtx ,
128129 & http.Server {
129130 Addr : serverAddress ,
130131 Handler : server ,
131132 BaseContext : func (_ net.Listener ) context.Context {
132- return gctx
133+ return listenCtx
133134 },
134135 },
135136 )
@@ -239,7 +240,7 @@ func Run(cmd *cobra.Command, args []string) (returnErr error) {
239240 // be cancelled, which will cause this blocking loop to exit
240241 // instead of waiting for the time period.
241242 for {
242- if err := gatherAndOutputData (klog . NewContext ( ctx , log ) , eventf , config , preflightClient , dataGatherers ); err != nil {
243+ if err := gatherAndOutputData (gctx , eventf , config , preflightClient , dataGatherers ); err != nil {
243244 return err
244245 }
245246
@@ -316,7 +317,7 @@ func gatherAndOutputData(ctx context.Context, eventf Eventf, config CombinedConf
316317 }
317318 } else {
318319 var err error
319- readings , err = gatherData (klog . NewContext ( ctx , log ) , config , dataGatherers )
320+ readings , err = gatherData (ctx , config , dataGatherers )
320321 if err != nil {
321322 return err
322323 }
@@ -338,7 +339,7 @@ func gatherAndOutputData(ctx context.Context, eventf Eventf, config CombinedConf
338339 postCtx , cancel := context .WithTimeout (ctx , config .BackoffMaxTime )
339340 defer cancel ()
340341
341- return struct {}{}, postData (klog . NewContext ( postCtx , log ) , config , preflightClient , readings )
342+ return struct {}{}, postData (postCtx , config , preflightClient , readings )
342343 }
343344
344345 group .Go (func () error {
@@ -361,7 +362,7 @@ func gatherData(ctx context.Context, config CombinedConfig, dataGatherers map[st
361362
362363 var dgError * multierror.Error
363364 for k , dg := range dataGatherers {
364- dgData , count , err := dg .Fetch ()
365+ dgData , count , err := dg .Fetch (ctx )
365366 if err != nil {
366367 dgError = multierror .Append (dgError , fmt .Errorf ("error in datagatherer %s: %w" , k , err ))
367368
@@ -406,7 +407,6 @@ func gatherData(ctx context.Context, config CombinedConfig, dataGatherers map[st
406407
407408func postData (ctx context.Context , config CombinedConfig , preflightClient client.Client , readings []* api.DataReading ) error {
408409 log := klog .FromContext (ctx ).WithName ("postData" )
409- ctx = klog .NewContext (ctx , log )
410410 err := preflightClient .PostDataReadingsWithOptions (ctx , readings , client.Options {
411411 ClusterName : config .ClusterName ,
412412 ClusterDescription : config .ClusterDescription ,
0 commit comments