Skip to content

Commit

Permalink
defer ctxCancel
Browse files Browse the repository at this point in the history
Signed-off-by: Yi Rae Kim <[email protected]>
  • Loading branch information
yiraeChristineKim committed Nov 9, 2023
1 parent 621ea3a commit af4c716
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ func watchGatekeeperInstall(mainCtx context.Context, dynamicClient *dynamic.Dyna
continue
}

// Override ctx, ctxCancel
ctx, ctxCancel = context.WithCancel(mainCtx)
isInstalled = true

go func() {
Expand All @@ -337,9 +335,13 @@ func watchGatekeeperInstall(mainCtx context.Context, dynamicClient *dynamic.Dyna
isInstalled = false
ctxCancel()
setupLog.Info("Gatekeeper deleted")
// Override ctx, ctxCancel
ctx, ctxCancel = context.WithCancel(mainCtx)
defer ctxCancel()
}
case <-mainCtx.Done():
// When parents ctx close, then child should be closed
ctxCancel()
return
}
}
Expand Down

0 comments on commit af4c716

Please sign in to comment.