Skip to content

Commit

Permalink
Use flag to define log timestamp format
Browse files Browse the repository at this point in the history
Since v0.11 controller-runtime supports the zap-time-encoding flag to
specify the time encoding of log timestamps. This flag is used to give
the user the possibilty to specify the required format.
By default nmstate-kubernetes uses the ISO8601 format.

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
  • Loading branch information
creydr committed Jan 18, 2022
1 parent 6d50805 commit e8ec1a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
12 changes: 1 addition & 11 deletions cmd/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"os"
"time"

"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -91,7 +90,7 @@ func main() {
flag.CommandLine.Set("zap-devel", "true")
}

setupLogger(opt)
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opt)))

// Lock only for handler, we can run old and new version of
// webhook without problems, policy status will be updated
Expand Down Expand Up @@ -249,15 +248,6 @@ func main() {
}
}

func setupLogger(opts zap.Options) {
opts.EncoderConfigOptions = append(opts.EncoderConfigOptions, func(ec *zapcore.EncoderConfig) {
ec.EncodeTime = zapcore.ISO8601TimeEncoder
})

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

// Start profiler on given port if ENABLE_PROFILER is True
func setProfiler() {
cfg := ProfilerConfig{}
Expand Down
12 changes: 1 addition & 11 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
_ "net/http/pprof"
"os"

"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -76,7 +75,7 @@ func main() {
flag.CommandLine.Set("zap-devel", "true")
}

setupLogger(opt)
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opt)))

ctrlOptions := ctrl.Options{
Scheme: scheme,
Expand Down Expand Up @@ -107,15 +106,6 @@ func main() {
}
}

func setupLogger(opts zap.Options) {
opts.EncoderConfigOptions = append(opts.EncoderConfigOptions, func(ec *zapcore.EncoderConfig) {
ec.EncodeTime = zapcore.ISO8601TimeEncoder
})

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

// Start profiler on given port if ENABLE_PROFILER is True
func setProfiler() {
cfg := ProfilerConfig{}
Expand Down
6 changes: 6 additions & 0 deletions deploy/handler/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ spec:
priorityClassName: system-cluster-critical
containers:
- name: nmstate-webhook
args:
- --zap-time-encoding=iso8601
# Replace this with the built image name
image: {{ .HandlerImage }}
imagePullPolicy: {{ .HandlerPullPolicy }}
Expand Down Expand Up @@ -113,6 +115,8 @@ spec:
priorityClassName: system-cluster-critical
containers:
- name: nmstate-cert-manager
args:
- --zap-time-encoding=iso8601
# Replace this with the built image name
image: {{ .HandlerImage }}
imagePullPolicy: {{ .HandlerPullPolicy }}
Expand Down Expand Up @@ -205,6 +209,8 @@ spec:
priorityClassName: system-node-critical
containers:
- name: nmstate-handler
args:
- --zap-time-encoding=iso8601
# Replace this with the built image name
image: {{ .HandlerImage }}
imagePullPolicy: {{ .HandlerPullPolicy }}
Expand Down
2 changes: 2 additions & 0 deletions deploy/operator/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ spec:
effect: NoSchedule
containers:
- name: nmstate-operator
args:
- --zap-time-encoding=iso8601
# Replace this with the built image name
image: {{ .OperatorImage }}
imagePullPolicy: {{ .OperatorPullPolicy }}
Expand Down

0 comments on commit e8ec1a0

Please sign in to comment.