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

Update logLevel setting for operators logs #147

Merged
merged 2 commits into from
May 24, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/tests-and-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ jobs:
image: [casskop, multi-casskop]

steps:
- id: lower-repo
shell: pwsh
run: |
"::set-output name=repository::$($env:GITHUB_REPOSITORY.ToLowerInvariant())"
cscetbon marked this conversation as resolved.
Show resolved Hide resolved
- name: Checkout repository
uses: actions/checkout@v3
with:
Expand All @@ -120,7 +124,7 @@ jobs:
with:
context: .
file: docker/${{ matrix.image }}/Dockerfile
tags: ghcr.io/cscetbon/${{ matrix.image }}:${{ env.IMAGE }}
tags: ghcr.io/${{ steps.lower-repo.outputs.repository }}/${{ matrix.image }}:${{ env.IMAGE }}
build-args: |
COMPILED_DATE=${{ env.COMPILED_DATE }}
VERSION=${{ env.VERSION }}
Expand All @@ -132,7 +136,7 @@ jobs:
with:
context: .
file: docker/${{ matrix.image }}/Dockerfile
tags: ghcr.io/cscetbon/${{ matrix.image }}:latest
tags: ghcr.io/${{ steps.lower-repo.outputs.repository }}/${{ matrix.image }}:latest
build-args: |
COMPILED_DATE=${{ env.COMPILED_DATE }}
VERSION=${{ env.VERSION }}
Expand Down
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
36 changes: 25 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 @@ -91,6 +92,19 @@ func getLogLevel() logrus.Level {
return logrus.InfoLevel
}

func zapLogLevel(level logrus.Level) zapcore.Level {
switch level {
case logrus.DebugLevel:
return zapcore.DebugLevel
case logrus.WarnLevel:
return zapcore.WarnLevel
case logrus.ErrorLevel:
return zapcore.ErrorLevel
default:
return zapcore.InfoLevel
}
}

func getResyncPeriod() int {
var resyncPeriod int
var err error
Expand All @@ -116,6 +130,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(zapLogLevel(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 +149,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 +163,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
Loading