Skip to content

Commit

Permalink
main, init: wrap setupLog into Context to init components
Browse files Browse the repository at this point in the history
Since it can be not desireable to return fatal error for some init
problems, it is still useful to log them. Wrap the logger into
Context like controller-runtime does [1][2].

[1] https://github.com/kubernetes-sigs/controller-runtime/blob/38546806f2faf5973e3321a7bd5bb3afdbb5767d/pkg/internal/controller/controller.go#L297
[2] https://github.com/kubernetes-sigs/controller-runtime/blob/38546806f2faf5973e3321a7bd5bb3afdbb5767d/pkg/internal/controller/controller.go#L111

Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta committed Sep 17, 2024
1 parent 26c5012 commit 12b61a1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics/server"
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
Expand Down Expand Up @@ -337,7 +338,7 @@ func main() { //nolint:funlen,maintidx
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
if err := initComponents(ctx, platform); err != nil {
if err := initComponents(logf.IntoContext(ctx, setupLog), platform); err != nil {
setupLog.Error(err, "unable to init components")
os.Exit(1)
}
Expand Down

0 comments on commit 12b61a1

Please sign in to comment.