Skip to content

Commit

Permalink
Update logLevel setting for operators logs
Browse files Browse the repository at this point in the history
Fixes: #138
  • Loading branch information
AKamyshnikova committed May 21, 2024
1 parent 6c81368 commit ecbdc11
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
4 changes: 1 addition & 3 deletions charts/casskop/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,5 @@ spec:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "casskop"
{{- if .Values.debug.enabled }}
- name: LOG_LEVEL
value: Debug
{{- end }}
value: .Values.logLevel
3 changes: 1 addition & 2 deletions charts/casskop/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ rbacCreateClusterRole: true
## if true deploy service for metrics access
metricService: false

debug:
enabled: false
logLevel: INFO

##
clusterServiceAccountsName:
Expand Down
4 changes: 1 addition & 3 deletions charts/multi-casskop/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ spec:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "multi-casskop"
{{- if .Values.debug.enabled }}
- name: LOG_LEVEL
value: Debug
{{- end }}
value: .Values.logLevel
volumeMounts:
{{- range .Values.k8s.remote }}
- mountPath: /var/run/secrets/admiralty.io/serviceaccountimports/{{ . }}
Expand Down
3 changes: 1 addition & 2 deletions charts/multi-casskop/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ rbacEnable: true
## if true deploy service for metrics access
metricService: false

debug:
enabled: false
logLevel: INFO

command: /usr/local/bin/multi-casskop

Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/swarvanusg/go_jolokia v0.0.0-20190213021437-3cd2b3fc4f36
github.com/thoas/go-funk v0.4.0
github.com/zput/zxcTool v1.3.6
go.uber.org/zap v1.24.0
go.uber.org/zap v1.27.0
golang.org/x/text v0.14.0
k8s.io/api v0.27.5
k8s.io/apimachinery v0.27.5
Expand Down Expand Up @@ -67,8 +67,7 @@ require (
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.18.0 // indirect
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ github.com/banzaicloud/k8s-objectmatcher v1.8.0 h1:Nugn25elKtPMTA2br+JgHNeSQ04sc
github.com/banzaicloud/k8s-objectmatcher v1.8.0/go.mod h1:p2LSNAjlECf07fbhDyebTkPUIYnU05G+WfGgkTmgeMg=
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down Expand Up @@ -253,14 +252,15 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zput/zxcTool v1.3.6 h1:Hw5TgcK38cksD75MLONLaopTq7DFVjXesntWxFvNkFs=
github.com/zput/zxcTool v1.3.6/go.mod h1:NHt1JCRdJDSFZlWYNUR9onDo9IJai9ID4bsFOGH6Qjs=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
23 changes: 12 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"flag"
"fmt"
gozap "go.uber.org/zap"
"go.uber.org/zap/zapcore"
"os"
"path"
Expand Down Expand Up @@ -116,6 +117,16 @@ func init() {
func main() {
logLevel := getLogLevel()
logrus.SetLevel(logLevel)
var metricsAddr string
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
opts := zap.Options{
Level: gozap.NewAtomicLevelAt(zapcore.Level(logLevel)),
TimeEncoder: zapcore.TimeEncoderOfLayout(time.RFC3339),
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
if logLevel == logrus.DebugLevel {
ztFormatter := &zt_formatter.ZtFormatter{
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
Expand All @@ -125,6 +136,7 @@ func main() {
}
logrus.SetReportCaller(true)
logrus.SetFormatter(ztFormatter)
opts.Development = true
}
if logType, _ := os.LookupEnv("LOG_TYPE"); logType == "json" {
logrus.SetFormatter(&logrus.JSONFormatter{})
Expand All @@ -138,17 +150,6 @@ func main() {
"the manager will watch and manage resources in all namespaces")
}

var metricsAddr string
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
opts := zap.Options{
Development: true,
TimeEncoder: zapcore.TimeEncoderOfLayout(time.RFC3339),
}
opts.BindFlags(flag.CommandLine)
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

ctx := context.TODO()
Expand Down

0 comments on commit ecbdc11

Please sign in to comment.