Skip to content

Commit

Permalink
chore(logger): replace to Deckhouse logger (#520)
Browse files Browse the repository at this point in the history
Changing the logger to the new Deckhouse standard

Why do we need it, and what problem does it solve?
Unification of the logger in all Deckhouse modules

What is the expected result?
New logging format, no panics or errors
---------

Signed-off-by: Daniil Antoshin <[email protected]>
  • Loading branch information
danilrwx authored Nov 18, 2024
1 parent ed9244e commit bf36dc7
Show file tree
Hide file tree
Showing 58 changed files with 189 additions and 221 deletions.
2 changes: 1 addition & 1 deletion base-images/image_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ REGISTRY_PATH: "docker.io/"
# Virtualization images
BASE_DEBIAN_BOOKWORM_SLIM: "debian:bookworm-slim@sha256:a629e796d77a7b2ff82186ed15d01a493801c020eed5ce6adaa2704356f15a1c"
BASE_CONTAINER_REGISTRY: "registry:2.8.3@sha256:ac0192b549007e22998eb74e8d8488dcfe70f1489520c3b144a6047ac5efbe90"
BASE_GOLANG_22_BOOKWORM: "golang:1.22.7-bookworm@sha256:027bd04b1d3b4529bf8ccebf62eb7eeeae7b7bef134a68bd419824e929ad93ad"
BASE_GOLANG_22_BOOKWORM: "golang:1.22.8-bookworm@sha256:3f0457a0a56a926d93c2baf4cf0057a645e8ff69ff31314080fcc62389643b8e"

BASE_ALT_P10: "alt:p10@sha256:4fab03b8d23eb16147397b0bc41a5025ba59f4e834f7fb4b933ac5206431d740"
# Digest for image created at 2024-09-20.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/common"
appconfig "github.com/deckhouse/virtualization-controller/pkg/config"
"github.com/deckhouse/virtualization-controller/pkg/controller/cvi"
Expand Down Expand Up @@ -81,9 +82,6 @@ func main() {
var logDebugVerbosity int
flag.IntVar(&logDebugVerbosity, "log-debug-verbosity", int(defaultDebugVerbosity), "log debug verbosity")

var logFormat string
flag.StringVar(&logFormat, "log-format", os.Getenv(logFormatEnv), "log format")

var logOutput string
flag.StringVar(&logOutput, "log-output", os.Getenv(logOutputEnv), "log output")

Expand All @@ -92,13 +90,7 @@ func main() {

flag.Parse()

log := logger.New(logger.Options{
Level: logLevel,
DebugVerbosity: logDebugVerbosity,
Format: logFormat,
Output: logOutput,
})

log := logger.NewLogger(logLevel, logOutput, logDebugVerbosity)
logger.SetDefaultLogger(log)

printVersion(log)
Expand Down Expand Up @@ -291,7 +283,7 @@ func main() {
}
}

func printVersion(log *slog.Logger) {
func printVersion(log *log.Logger) {
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
}
13 changes: 8 additions & 5 deletions images/virtualization-artifact/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/deckhouse/virtualization-controller

go 1.22.7
go 1.22.8

require (
github.com/deckhouse/virtualization/api v0.0.0-00010101000000-000000000000
Expand All @@ -14,7 +14,7 @@ require (
github.com/prometheus/client_golang v1.18.0
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.26.0
k8s.io/api v0.30.2
k8s.io/apiextensions-apiserver v0.30.0
Expand All @@ -33,6 +33,8 @@ require (
sigs.k8s.io/yaml v1.4.0
)

require github.com/DataDog/gostackparse v0.7.0 // indirect

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
Expand All @@ -45,6 +47,7 @@ require (
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241113072037-8825f2588d0f
github.com/docker/docker v25.0.6+incompatible // indirect
github.com/docker/docker-credential-helpers v0.8.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
Expand All @@ -57,7 +60,7 @@ require (
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/protobuf v1.3.2
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/cel-go v0.17.8 // indirect
Expand All @@ -84,7 +87,7 @@ require (
github.com/openshift/custom-resource-status v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/client_model v0.5.0
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
Expand Down Expand Up @@ -120,7 +123,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.34.2
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
7 changes: 6 additions & 1 deletion images/virtualization-artifact/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGB
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/IGQh4=
github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
Expand Down Expand Up @@ -39,6 +41,8 @@ github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241113072037-8825f2588d0f h1:2imDVTm2VlLCQVj5ZqxaSWHg59mPG2EZecdd6cwkBBw=
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241113072037-8825f2588d0f/go.mod h1:Mk5HRzkc5pIcDIZ2JJ6DPuuqnwhXVkb3you8M8Mg+4w=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v23.0.5+incompatible h1:ufWmAOuD3Vmr7JP2G5K3cyuNC4YZWiAsuDEvFVVDafE=
Expand Down Expand Up @@ -298,8 +302,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE=
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75/go.mod h1:KO6IkyS8Y3j8OdNO85qEYBsRPuteD+YciPomcXdrMnk=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.7-bookworm@sha256:027bd04b1d3b4529bf8ccebf62eb7eeeae7b7bef134a68bd419824e929ad93ad AS builder
FROM golang:1.22.8-bookworm@sha256:3f0457a0a56a926d93c2baf4cf0057a645e8ff69ff31314080fcc62389643b8e AS builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package cvi

import (
"context"
"log/slog"
"time"

corev1 "k8s.io/api/core/v1"
Expand All @@ -27,6 +26,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/controller/cvi/internal"
"github.com/deckhouse/virtualization-controller/pkg/controller/cvi/internal/source"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
Expand All @@ -49,7 +49,7 @@ type Condition interface {
func NewController(
ctx context.Context,
mgr manager.Manager,
log *slog.Logger,
log *log.Logger,
importerImage string,
uploaderImage string,
requirements corev1.ResourceRequirements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ package cvi
import (
"context"
"fmt"
"log/slog"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
)

type Validator struct {
logger *slog.Logger
logger *log.Logger
}

func NewValidator(logger *slog.Logger) *Validator {
func NewValidator(logger *log.Logger) *Validator {
return &Validator{
logger: logger.With("webhook", "validator"),
}
Expand Down
10 changes: 5 additions & 5 deletions images/virtualization-artifact/pkg/controller/gc/cron_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"cmp"
"context"
"fmt"
"log/slog"
"slices"
"time"

Expand All @@ -36,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/logger"
"github.com/deckhouse/virtualization-controller/pkg/sdk/framework/helper"
)
Expand All @@ -48,7 +48,7 @@ func NewCronSource(c client.Client,
standardSpec string,
objList client.ObjectList,
option CronSourceOption,
log *slog.Logger,
log *log.Logger,
) *CronSource {
return &CronSource{
Client: c,
Expand All @@ -64,20 +64,20 @@ type CronSource struct {
standardSpec string
objList client.ObjectList
option CronSourceOption
log *slog.Logger
log *log.Logger
}

type CronSourceOption struct {
GetOlder func(objList client.ObjectList) client.ObjectList
}

func NewDefaultCronSourceOption(objs client.ObjectList, ttl time.Duration, log *slog.Logger) CronSourceOption {
func NewDefaultCronSourceOption(objs client.ObjectList, ttl time.Duration, log *log.Logger) CronSourceOption {
return CronSourceOption{
GetOlder: DefaultGetOlder(objs, ttl, 10, log),
}
}

func DefaultGetOlder(objs client.ObjectList, ttl time.Duration, maxCount int, log *slog.Logger) func(objList client.ObjectList) client.ObjectList {
func DefaultGetOlder(objs client.ObjectList, ttl time.Duration, maxCount int, log *log.Logger) func(objList client.ObjectList) client.ObjectList {
return func(objList client.ObjectList) client.ObjectList {
var expiredItems []runtime.Object
var notExpiredItems []runtime.Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ limitations under the License.
package gc

import (
"log/slog"

"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/logger"
)

func SetupGcController(
controllerName string,
mgr manager.Manager,
log *slog.Logger,
log *log.Logger,
watchSource source.Source,
newObject NewObject,
isNeedDelete IsNeedDelete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package gc

import (
"context"
"log/slog"
"time"

"k8s.io/client-go/tools/record"
Expand All @@ -32,6 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/logger"
)

Expand Down Expand Up @@ -77,7 +77,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
return reconcile.Result{}, nil
}

func (r *Reconciler) SetupWithManager(controllerName string, mgr ctrl.Manager, log *slog.Logger) error {
func (r *Reconciler) SetupWithManager(controllerName string, mgr ctrl.Manager, log *log.Logger) error {
return ctrl.NewControllerManagedBy(mgr).
Named(controllerName).
For(r.newObject(), builder.WithPredicates(predicate.Funcs{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package service
import (
"errors"
"fmt"
"log/slog"
"net"
"net/netip"

k8snet "k8s.io/utils/net"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/controller/common"
)

Expand All @@ -33,7 +33,7 @@ type IpAddressService struct {
}

func NewIpAddressService(
logger *slog.Logger,
logger *log.Logger,
virtualMachineCIDRs []string,
) *IpAddressService {
parsedCIDRs := make([]netip.Prefix, len(virtualMachineCIDRs))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
package service

import (
"log/slog"
"net/netip"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/controller/common"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
)
Expand All @@ -31,7 +31,7 @@ var _ = Describe("IpAddressService", func() {
var (
ipService *IpAddressService
allocatedIPs common.AllocatedIPs
logger *slog.Logger
logger *log.Logger
)

BeforeEach(func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package service
import (
"errors"
"fmt"
"log/slog"
"strconv"
"time"

Expand All @@ -28,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/common"
cc "github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/monitoring"
Expand All @@ -37,10 +37,10 @@ import (
)

type StatService struct {
logger *slog.Logger
logger *log.Logger
}

func NewStatService(logger *slog.Logger) *StatService {
func NewStatService(logger *log.Logger) *StatService {
return &StatService{
logger: logger.With("svc", "stat"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package watcher
import (
"context"
"fmt"
"log/slog"
"strings"

"k8s.io/apimachinery/pkg/fields"
Expand All @@ -33,19 +32,20 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/controller/indexer"
"github.com/deckhouse/virtualization-controller/pkg/sdk/framework/helper"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
)

type VirtualDiskSnapshotWatcher struct {
logger *slog.Logger
logger *log.Logger
client client.Client
}

func NewVirtualDiskSnapshotWatcher(client client.Client) *VirtualDiskSnapshotWatcher {
return &VirtualDiskSnapshotWatcher{
logger: slog.Default().With("watcher", strings.ToLower(virtv2.VirtualDiskSnapshotKind)),
logger: log.Default().With("watcher", strings.ToLower(virtv2.VirtualDiskSnapshotKind)),
client: client,
}
}
Expand Down
Loading

0 comments on commit bf36dc7

Please sign in to comment.