Skip to content

Commit

Permalink
add CLI options for tuning logging and remove -development option
Browse files Browse the repository at this point in the history
This commit adds the following CLI options to tune logging:

- `-zap-devel`
- `-zap-encoder`
- `-zap-log-level`
- `-zap-stacktrace-level`
- `-zap-time-encoding`

This commit also removes the `-development` option, which is now
replaced with `-zap-devel`.

See also: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/log/zap#Options.BindFlags

Signed-off-by: Ryotaro Banno <[email protected]>
  • Loading branch information
ushitora-anqou committed Jun 10, 2024
1 parent 767261b commit 93e9e45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package main

import (
"flag"
"fmt"
"os"
"time"

"github.com/spf13/cobra"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
//+kubebuilder:scaffold:imports
)

Expand All @@ -20,7 +22,7 @@ var config struct {
prometheusURL string
useK8sMetricsApi bool
skipAnnotation bool
development bool
zapOpts zap.Options
}

// rootCmd represents the base command when called without any subcommands
Expand Down Expand Up @@ -54,5 +56,8 @@ func init() {
fs.StringVar(&config.prometheusURL, "prometheus-url", "", "Prometheus URL to query volume stats.")
fs.BoolVar(&config.useK8sMetricsApi, "use-k8s-metrics-api", false, "Use Kubernetes metrics API instead of Prometheus")
fs.BoolVar(&config.skipAnnotation, "no-annotation-check", false, "Skip annotation check for StorageClass")
fs.BoolVar(&config.development, "development", false, "Use development logger config")

goflags := flag.NewFlagSet("zap", flag.ExitOnError)
config.zapOpts.BindFlags(goflags)
fs.AddGoFlagSet(goflags)
}
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
}

func subMain() error {
ctrl.SetLogger(zap.New(zap.UseDevMode(config.development)))
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&config.zapOpts)))

hookHost, portStr, err := net.SplitHostPort(config.webhookAddr)
if err != nil {
Expand Down

0 comments on commit 93e9e45

Please sign in to comment.