Skip to content

Commit

Permalink
feat: replace deprecated logger methods (#546)
Browse files Browse the repository at this point in the history
Signed-off-by: Evsyukov Denis <[email protected]>
  • Loading branch information
juev authored Dec 28, 2024
1 parent 804d234 commit 7c39f50
Show file tree
Hide file tree
Showing 33 changed files with 644 additions and 317 deletions.
5 changes: 0 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ linters-settings:
- prefix(github.com/flant/)
goimports:
local-prefixes: github.com/flant/
# TODO: replace deprecated methods
# ignore deprecated
# https://staticcheck.dev/docs/checks/#SA1019
staticcheck:
checks: ["all","-SA1019"]
sloglint:
# Enforce not mixing key-value pairs and attributes.
no-mixed-args: true
Expand Down
4 changes: 2 additions & 2 deletions cmd/addon-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ func run(ctx context.Context, operator *addon_operator.AddonOperator) error {
operator.SetupKubeConfigManager(bk)

if err := operator.Setup(); err != nil {
operator.Logger.Fatalf("setup failed: %s\n", err)
operator.Logger.Fatal("setup failed", log.Err(err))
}

if err := operator.Start(ctx); err != nil {
operator.Logger.Fatalf("start failed: %s\n", err)
operator.Logger.Fatal("start failed", log.Err(err))
}

// Block action by waiting signals from OS.
Expand Down
2 changes: 1 addition & 1 deletion examples/700-go-hook/global-hooks/global-go-hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ var _ = sdk.RegisterFunc(&gohook.HookConfig{
}, handler)

func handler(input *gohook.HookInput) error {
input.Logger.Infof("Start Global Go hook")
input.Logger.Info("Start Global Go hook")
return nil
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package hooks

import (
"fmt"
"log/slog"
"time"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -54,11 +56,12 @@ func ObjFilter(obj *unstructured.Unstructured) (gohook.FilterResult, error) {
func run(input *gohook.HookInput) error {
for _, o := range input.Snapshots["pods"] {
podSpec := o.(*podSpecFilteredObj)
input.Logger.Infof("Got podSpec: %+v", podSpec)
input.Logger.Info("Got podSpec",
slog.String("spec", fmt.Sprintf("%+v", podSpec)))
}

input.Logger.Infof("Hello from on_kube.pods2! I have %d snapshots\n",
len(input.Snapshots))
input.Logger.Info("Hello from on_kube.pods2! I have snapshots",
slog.Int("count", len(input.Snapshots)))

input.MetricsCollector.Add("addon_go_hooks_total", 1.0, nil)

Expand Down
9 changes: 6 additions & 3 deletions pkg/addon-operator/admission_http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package addon_operator
import (
"context"
"fmt"
"log/slog"
"net/http"
"path"
"time"
Expand All @@ -27,7 +28,8 @@ func NewAdmissionServer(listenPort, certsDir string) *AdmissionServer {

func (as *AdmissionServer) RegisterHandler(route string, handler http.Handler) {
if _, ok := as.routes[route]; ok {
log.Fatalf("Route %q is already registered", route)
log.Fatal("Route is already registered",
slog.String("route", route))
}

as.routes[route] = handler
Expand All @@ -41,7 +43,8 @@ func (as *AdmissionServer) start(ctx context.Context) {
mux.Handle(route, handler)
}

log.Debugf("Registered admission routes: %v", as.routes)
log.Debug("Registered admission routes",
slog.String("routes", fmt.Sprintf("%v", as.routes)))

srv := &http.Server{
Addr: fmt.Sprintf(":%s", as.listenPort),
Expand All @@ -67,7 +70,7 @@ func (as *AdmissionServer) start(ctx context.Context) {
cancel()
}()
if err := srv.Shutdown(ctx); err != nil {
log.Fatalf("Server Shutdown Failed:%+v", err)
log.Fatal("Server Shutdown Failed", log.Err(err))
}
}()
}
13 changes: 8 additions & 5 deletions pkg/addon-operator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package addon_operator

import (
"fmt"
"log/slog"

"github.com/deckhouse/deckhouse/pkg/log"

Expand All @@ -18,22 +19,24 @@ import (
func (op *AddonOperator) bootstrap() error {
log.Info(shapp.AppStartMessage)

log.Infof("Search modules in: %s", app.ModulesDir)
log.Info("Search modules",
slog.String("path", app.ModulesDir))

log.Infof("Addon-operator namespace: %s", op.DefaultNamespace)
log.Info("Addon-operator namespace",
slog.String("namespace", op.DefaultNamespace))

// Debug server.
// TODO: rewrite shapp global variables to the addon-operator ones
var err error
op.DebugServer, err = shell_operator.RunDefaultDebugServer(shapp.DebugUnixSocket, shapp.DebugHttpServerAddr, op.Logger.Named("debug-server"))
if err != nil {
log.Errorf("Fatal: start Debug server: %s", err)
log.Error("Fatal: start Debug server", log.Err(err))
return fmt.Errorf("start Debug server: %w", err)
}

err = op.Assemble(op.DebugServer)
if err != nil {
log.Errorf("Fatal: %s", err)
log.Error("Fatal", log.Err(err))
return fmt.Errorf("assemble Debug server: %w", err)
}

Expand Down Expand Up @@ -68,7 +71,7 @@ func (op *AddonOperator) Assemble(debugServer *debug.Server) (err error) {
// SetupKubeConfigManager sets manager, which reads configuration for Modules from a cluster
func (op *AddonOperator) SetupKubeConfigManager(bk backend.ConfigHandler) {
if op.KubeConfigManager != nil {
log.Warnf("KubeConfigManager is already set")
log.Warn("KubeConfigManager is already set")
// return if kube config manager is already set
return
}
Expand Down
Loading

0 comments on commit 7c39f50

Please sign in to comment.