Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated dependencies, improved timestamps for logging #15

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ format:
docker-images:
@docker build -t $(IMAGE_REPOSITORY):$(IMAGE_TAG) -f Dockerfile .

.PHONY: docker-images-linux-amd64
docker-images-linux-amd64:
@docker buildx build --platform linux/amd64 -t $(IMAGE_REPOSITORY):$(IMAGE_TAG) -f Dockerfile .

$(GOIMPORTS): go.mod
go build -o $(GOIMPORTS) golang.org/x/tools/cmd/goimports

Expand All @@ -71,4 +75,4 @@ update-dependencies:
@make revendor

.PHONY: verify
verify: check format test
verify: check format test
37 changes: 19 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ require (
github.com/go-logr/logr v1.2.3
github.com/golang/mock v1.6.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.24.1
github.com/onsi/gomega v1.27.1
github.com/spf13/pflag v1.0.5
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.8.0
golang.org/x/tools v0.1.12
k8s.io/api v0.25.4
k8s.io/apimachinery v0.25.4
k8s.io/client-go v0.25.4
sigs.k8s.io/controller-runtime v0.13.1
go.uber.org/zap v1.24.0
golang.org/x/tools v0.6.0
k8s.io/api v0.26.4
k8s.io/apimachinery v0.26.4
k8s.io/client-go v0.26.4
sigs.k8s.io/controller-runtime v0.14.5
)

require (
Expand All @@ -25,7 +26,7 @@ require (
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
Expand All @@ -42,36 +43,36 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo/v2 v2.8.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.0.0-20220808172628-8227340efae7 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.25.4 // indirect
k8s.io/component-base v0.25.4 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803164354-a70c9af30aea // indirect
k8s.io/utils v0.0.0-20220810061631-2e139fc3ae1e // indirect
k8s.io/apiextensions-apiserver v0.26.4 // indirect
k8s.io/component-base v0.26.4 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
81 changes: 41 additions & 40 deletions go.sum

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package main

import (
"fmt"
"github.com/gardener/aws-custom-route-controller/pkg/util/logger"
"k8s.io/klog/v2"
"os"
"time"

Expand All @@ -15,7 +17,6 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
"sigs.k8s.io/controller-runtime/pkg/builder"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

Expand Down Expand Up @@ -48,12 +49,16 @@ var (
tickPeriod = pflag.Duration("tick-period", 5*time.Second, "tick period for checking for updates")
leaderElection = pflag.Bool("leader-election", false, "enable leader election")
leaderElectionNamespace = pflag.String("leader-election-namespace", "kube-system", "namespace for the lease resource")
logLevel = pflag.String("log-level", logger.InfoLevel, "LogLevel is the level/severity for the logs. Must be one of [info,debug,error].")
logFormat = pflag.String("log-format", logger.FormatJSON, "output format for the logs. Must be one of [text,json].")
)

func main() {
logf.SetLogger(zap.New())

logf.SetLogger(logger.MustNewZapLogger(*logLevel, *logFormat))

var log = logf.Log.WithName(componentName)
klog.SetLogger(log)
log.Info("version", "version", Version)

pflag.Parse()
Expand Down
26 changes: 26 additions & 0 deletions pkg/util/logger/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package logger

const (
// DebugLevel is the debug log level, i.e. the most verbose.
DebugLevel = "debug"
// InfoLevel is the default log level.
InfoLevel = "info"
// ErrorLevel is a log level where only errors are logged.
ErrorLevel = "error"

// FormatJSON is the output type that produces a JSON object per log line.
FormatJSON = "json"
// FormatText outputs the log as human-readable text.
FormatText = "text"
)

var (
// AllLogLevels is a slice of all available log levels.
AllLogLevels = []string{DebugLevel, InfoLevel, ErrorLevel}
// AllLogFormats is a slice of all available log formats.
AllLogFormats = []string{FormatJSON, FormatText}
)
60 changes: 60 additions & 0 deletions pkg/util/logger/zap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

package logger

import (
"fmt"

"github.com/go-logr/logr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
logzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
)

func setCommonEncoderConfigOptions(encoderConfig *zapcore.EncoderConfig) {
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
encoderConfig.EncodeDuration = zapcore.StringDurationEncoder
}

// MustNewZapLogger is like NewZapLogger but panics on invalid input.
func MustNewZapLogger(level string, format string, additionalOpts ...logzap.Opts) logr.Logger {
logger, err := NewZapLogger(level, format, additionalOpts...)
utilruntime.Must(err)
return logger
}

// NewZapLogger creates a new logr.Logger backed by Zap.
func NewZapLogger(level string, format string, additionalOpts ...logzap.Opts) (logr.Logger, error) {
var opts []logzap.Opts

// map our log levels to zap levels
var zapLevel zapcore.LevelEnabler
switch level {
case DebugLevel:
zapLevel = zap.DebugLevel
case ErrorLevel:
zapLevel = zap.ErrorLevel
case "", InfoLevel:
zapLevel = zap.InfoLevel
default:
return logr.Logger{}, fmt.Errorf("invalid log level %q", level)
}
opts = append(opts, logzap.Level(zapLevel))

// map our log format to encoder
switch format {
case FormatText:
opts = append(opts, logzap.ConsoleEncoder(setCommonEncoderConfigOptions))
case "", FormatJSON:
opts = append(opts, logzap.JSONEncoder(setCommonEncoderConfigOptions))
default:
return logr.Logger{}, fmt.Errorf("invalid log format %q", format)
}

return logzap.New(append(opts, additionalOpts...)...), nil
}
10 changes: 5 additions & 5 deletions vendor/github.com/fsnotify/fsnotify/.gitignore

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

62 changes: 0 additions & 62 deletions vendor/github.com/fsnotify/fsnotify/AUTHORS

This file was deleted.

Loading