Skip to content

Commit

Permalink
sidecar: Use zap as logger for controller-runtime
Browse files Browse the repository at this point in the history
This commit sets zap as logger for controller runtime
and klog.

Setting a logger on controller runtime also fixes the error
due to logger being unset when creating a new ctrl client
in `newCSIAddonsNode`.

Signed-off-by: Niraj Yadav <[email protected]>
  • Loading branch information
black-dragon74 committed Feb 14, 2025
1 parent a10afd9 commit 35e0993
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ import (
sideutil "github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/util"

"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
"go.uber.org/zap/zapcore"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

func main() {
Expand Down Expand Up @@ -65,8 +68,17 @@ func main() {
klog.Exitf("failed to set logtostderr flag: %v", err)
}

opts := zap.Options{
Development: true,
TimeEncoder: zapcore.ISO8601TimeEncoder,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()

logger := zap.New(zap.UseFlagOptions(&opts))
klog.SetLogger(logger)
ctrl.SetLogger(logger)

if *showVersion {
version.PrintVersion()
return
Expand Down

0 comments on commit 35e0993

Please sign in to comment.