Skip to content

Commit

Permalink
Move to controller-util log util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AMecea committed Feb 12, 2019
1 parent ee83b7b commit cc16a5c
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 106 deletions.
7 changes: 4 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ required = [

[[constraint]]
name="github.com/presslabs/controller-util"
version = "v0.1.9"
version = "v0.1.10"

# use wgliang version of cron because provides cron removal
[[override]]
Expand Down
7 changes: 4 additions & 3 deletions cmd/mysql-operator-sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (
"fmt"
"os"

logf "github.com/presslabs/controller-util/log"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

"github.com/presslabs/mysql-operator/pkg/sidecar/appclone"
"github.com/presslabs/mysql-operator/pkg/sidecar/appconf"
"github.com/presslabs/mysql-operator/pkg/sidecar/apphelper"
"github.com/presslabs/mysql-operator/pkg/sidecar/apptakebackup"
customLog "github.com/presslabs/mysql-operator/pkg/util/log"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)

var log = logf.Log.WithName("sidecar")
Expand All @@ -49,14 +48,16 @@ func main() {
}

// add flags and parse them
debug := false
flag.BoolVar(&debug, "debug", false, "Set logger in debug mode")
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
if err := cmd.ParseFlags(os.Args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "failed to parse global flags, see helps, err: %s", err)
os.Exit(1)
}

// setup logging
logf.SetLogger(customLog.ZapLogger())
logf.SetLogger(logf.ZapLogger(debug))

confCmd := &cobra.Command{
Use: "init-configs",
Expand Down
14 changes: 11 additions & 3 deletions cmd/mysql-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
"fmt"
"os"

customLog "github.com/presslabs/mysql-operator/pkg/util/log"
logf "github.com/presslabs/controller-util/log"
"github.com/spf13/pflag"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/klog"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

"github.com/presslabs/mysql-operator/pkg/apis"
Expand All @@ -40,6 +40,9 @@ func main() {
fs := pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)
fs.AddGoFlagSet(flag.CommandLine)

debug := false
fs.BoolVar(&debug, "debug", false, "Set logger in debug mode")

opt := options.GetOptions()
opt.AddFlags(fs)
if err := fs.Parse(os.Args); err != nil {
Expand All @@ -48,7 +51,12 @@ func main() {
}

// set logging
logf.SetLogger(customLog.ZapLogger())
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
klogFlags.Set("logtostderr", "true") // nolint: errcheck
klogFlags.Set("alsologtostderr", "false") // nolint: errcheck

logf.SetLogger(logf.ZapLogger(debug))

if err := opt.Validate(); err != nil {
log.Error(err, "failed to validate command line args, see help.")
Expand Down
1 change: 0 additions & 1 deletion hack/dev-values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extraArgs:
- -v=1
- --debug

installCRDs: false
Expand Down
2 changes: 1 addition & 1 deletion hack/docker/sidecar-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ${GCS_SERVICE_ACCOUNT_JSON_KEY}
EOF

SIDECAR_BIN=mysql-operator-sidecar
VERBOSE="-v 1 --debug"
VERBOSE="--debug"

# exec command
case "$1" in
Expand Down
18 changes: 3 additions & 15 deletions pkg/controller/internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import (

// loggging
"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

utilLog "github.com/presslabs/controller-util/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

Expand All @@ -46,16 +44,6 @@ func DrainChan(requests <-chan reconcile.Request) {
}

// NewTestLogger returns a logger good for tests
func NewTestLogger(w io.Writer, options ...zap.Option) logr.Logger {
encoderCfg := zapcore.EncoderConfig{
MessageKey: "msg",
LevelKey: "level",
NameKey: "logger",
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
}
sink := zapcore.AddSync(w)
core := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderCfg), sink, zap.DebugLevel)
return zapr.NewLogger(zap.New(core).WithOptions(options...))
func NewTestLogger(w io.Writer) logr.Logger {
return utilLog.ZapLoggerTo(w, true)
}
74 changes: 0 additions & 74 deletions pkg/util/log/log.go

This file was deleted.

1 change: 0 additions & 1 deletion test/e2e-values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extraArgs:
- -v=1
- --debug

orchestrator:
Expand Down
4 changes: 0 additions & 4 deletions vendor/github.com/presslabs/controller-util/Gopkg.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc16a5c

Please sign in to comment.