Skip to content

Commit be04593

Browse files
committed
Merge commit '127e95bb397809234016b9f062a1bf99ed0dcad2' into feat/dmt-test
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
2 parents d9e19d1 + 127e95b commit be04593

58 files changed

Lines changed: 837 additions & 998 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: lint
3737
uses: golangci/golangci-lint-action@v8
3838
with:
39-
version: v2.1
39+
version: v2.8.0
4040

4141
tests:
4242
needs: golangci-lint

.golangci.yml

Lines changed: 73 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,24 @@ version: "2"
22
linters:
33
default: none
44
enable:
5-
- bodyclose
65
- copyloopvar
7-
- depguard
86
- dogsled
9-
- dupl
107
- errcheck
11-
- errorlint
12-
- funlen
13-
- gocheckcompilerdirectives
14-
- gochecknoinits
158
- gocritic
16-
- gocyclo
17-
- godox
18-
- goprintffuncname
19-
- gosec
209
- govet
2110
- ineffassign
22-
- intrange
2311
- misspell
24-
- mnd
25-
- nakedret
26-
- noctx
27-
- nolintlint
12+
- musttag
2813
- nonamedreturns
14+
- prealloc
2915
- revive
16+
- sloglint
3017
- staticcheck
31-
- testifylint
3218
- unconvert
3319
- unparam
34-
- unused
3520
- whitespace
21+
- unused
22+
- usestdlibvars
3623
settings:
3724
depguard:
3825
rules:
@@ -44,71 +31,57 @@ linters:
4431
desc: Should be replaced by standard lib errors package.
4532
- pkg: github.com/instana/testify
4633
desc: It's a fork of github.com/stretchr/testify.
47-
dupl:
48-
threshold: 100
49-
errorlint:
50-
asserts: false
51-
funlen:
52-
lines: -1
53-
statements: 50
54-
goconst:
55-
min-len: 2
56-
min-occurrences: 3
57-
gocritic:
58-
disabled-checks:
59-
- dupImport
60-
- ifElseChain
61-
- octalLiteral
62-
- whyNoLint
63-
- unnamedResult
64-
enabled-tags:
65-
- diagnostic
66-
- experimental
67-
- opinionated
68-
- performance
69-
- style
70-
godox:
71-
keywords:
72-
- FIXME
73-
govet:
74-
enable:
75-
- nilness
76-
lll:
77-
line-length: 140
78-
misspell:
79-
locale: US
80-
ignore-rules:
81-
- importas
82-
mnd:
83-
checks:
84-
- argument
85-
- case
86-
- condition
87-
- return
88-
ignored-numbers:
89-
- "0"
90-
- "1"
91-
- "2"
92-
- "3"
93-
ignored-functions:
94-
- strings.SplitN
95-
nolintlint:
96-
require-explanation: true
97-
require-specific: true
98-
allow-unused: false
99-
revive:
100-
rules:
101-
- name: indent-error-flow
102-
- name: unexported-return
103-
disabled: true
104-
- name: unused-parameter
105-
- name: unused-receiver
34+
errcheck:
35+
exclude-functions:
36+
- fmt:.*[rR]ead|[wW]rite|[cC]lose
37+
- io:Copy
38+
nonamedreturns:
39+
report-error-in-defer: false
40+
sloglint:
41+
no-mixed-args: true
42+
# Enforce using key-value pairs only (overrides no-mixed-args, incompatible with attr-only).
43+
kv-only: false
44+
# Enforce using attributes only (overrides no-mixed-args, incompatible with kv-only).
45+
attr-only: false
46+
# Enforce not using global loggers.
47+
no-global: ""
48+
# Enforce using methods that accept a context.
49+
context: ""
50+
# Enforce using static values for log messages.
51+
static-msg: false
52+
# Enforce using constants instead of raw keys.
53+
no-raw-keys: false
54+
# Enforce a single key naming convention.
55+
key-naming-case: "snake"
56+
# Enforce not using specific keys.
57+
forbidden-keys:
58+
- level
59+
- msg
60+
- logger
61+
- source
62+
- stacktrace
63+
- time
64+
# Enforce putting arguments on separate lines.
65+
args-on-sep-lines: false
10666
staticcheck:
10767
checks:
10868
- all
109-
- -SA1019
11069
- '-ST1003' # waiting for package name will be fixed (underscores)
11170
- '-QF1008' # not need to fix; we understand how to call nested structs
71+
revive:
72+
rules:
73+
- name: var-naming # waiting for package name will be fixed (incorrect naming)
74+
severity: warning
75+
disabled: false
76+
exclude: [""]
77+
arguments:
78+
- ["ID"] # AllowList
79+
- ["VM"] # DenyList
80+
- - skip-initialism-name-checks: false
81+
upper-case-const: false
82+
skip-package-name-checks: true
83+
skip-package-name-collision-with-go-std: false
84+
extra-bad-package-names: []
11285
exclusions:
11386
generated: lax
11487
presets:
@@ -117,20 +90,38 @@ linters:
11790
- legacy
11891
- std-error-handling
11992
rules:
93+
- path: (.+)\.go$
94+
text: ST1005.*
95+
- path: (.+)\.go$
96+
text: should not use dot imports
97+
- path: (.+)\.go$
98+
text: don't use an underscore in package name
99+
- path: (.+)\.go$
100+
text: 'exported: .*'
101+
- linters:
102+
- staticcheck
103+
path: hooks/purge_orphan_resources.go
104+
text: 'is deprecated: use Warn instead'
120105
- linters:
121-
- dupl
122-
- lll
123-
- mnd
124-
path: (.+)_test\.go
106+
- staticcheck
107+
path: hooks/purge_orphan_resources.go
108+
text: 'is deprecated: use Info instead'
125109
paths:
126110
- third_party$
127111
- builtin$
128112
- examples$
129113
formatters:
130114
enable:
115+
- gci
131116
- gofmt
132117
- goimports
133118
settings:
119+
gci:
120+
sections:
121+
- standard
122+
- default
123+
- prefix(github.com/deckhouse/)
124+
- localmodule
134125
gofmt:
135126
rewrite-rules:
136127
- pattern: interface{}

cmd/dmt/main.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ package main
1919
import (
2020
"context"
2121
"errors"
22+
"log/slog"
2223
"os"
2324
"runtime"
2425
"runtime/pprof"
2526

2627
"github.com/fatih/color"
2728

29+
"github.com/deckhouse/deckhouse/pkg/log"
30+
2831
"github.com/deckhouse/dmt/internal/flags"
2932
"github.com/deckhouse/dmt/internal/fsutils"
30-
"github.com/deckhouse/dmt/internal/logger"
3133
"github.com/deckhouse/dmt/internal/manager"
3234
"github.com/deckhouse/dmt/internal/metrics"
3335
"github.com/deckhouse/dmt/internal/version"
@@ -40,17 +42,17 @@ func main() {
4042

4143
func runLint(dir string) error {
4244
if flags.PprofFile != "" {
43-
logger.InfoF("Profiling enabled. Profile file: %s", flags.PprofFile)
45+
log.Info("Profiling enabled", slog.String("file", flags.PprofFile))
4446
defer func() {
4547
pproFile, err := fsutils.ExpandDir(flags.PprofFile)
4648
if err != nil {
47-
logger.ErrorF("could not get current working directory: %s", err)
49+
log.Error("could not get current working directory", log.Err(err))
4850
return
4951
}
50-
logger.InfoF("Writing memory profile to %s", pproFile)
52+
log.Info("Writing memory profile", slog.String("file", pproFile))
5153
f, err := os.Create(pproFile)
5254
if err != nil {
53-
logger.ErrorF("could not create memory profile: %s", err)
55+
log.Error("could not create memory profile", log.Err(err))
5456
return
5557
}
5658
defer f.Close()
@@ -59,17 +61,19 @@ func runLint(dir string) error {
5961
// Alternatively, use Lookup("heap") for a profile
6062
// that has inuse_space as the default index.
6163
if err := pprof.Lookup("allocs").WriteTo(f, 0); err != nil {
62-
logger.ErrorF("could not write memory profile: %s", err)
64+
log.Error("could not write memory profile", log.Err(err))
6365
return
6466
}
6567
}()
6668
}
6769
// enable color output for Github actions, do not remove it
6870
color.NoColor = false
69-
logger.InfoF("DMT version: %s, Commit: %s, Date: %s", version.Version, version.Commit, version.Date)
71+
log.Info("DMT version", slog.String("version", version.Version), slog.String("commit", version.Commit), slog.String("date", version.Date))
7072

7173
cfg, err := config.NewDefaultRootConfig(dir)
72-
logger.CheckErr(err)
74+
if err != nil {
75+
log.Fatal("default root config", log.Err(err)) //nolint:gocritic
76+
}
7377

7478
// init metrics storage, should be done before running manager
7579
metrics.GetClient(dir)

cmd/dmt/root.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"errors"
2222
"fmt"
23+
"log/slog"
2324
"os"
2425
"regexp"
2526
"strings"
@@ -28,6 +29,8 @@ import (
2829
"github.com/fatih/color"
2930
"github.com/spf13/cobra"
3031

32+
"github.com/deckhouse/deckhouse/pkg/log"
33+
3134
"github.com/deckhouse/dmt/internal/bootstrap"
3235
"github.com/deckhouse/dmt/internal/flags"
3336
"github.com/deckhouse/dmt/internal/fsutils"
@@ -51,7 +54,12 @@ func execute() {
5154
PersistentPreRun: func(_ *cobra.Command, _ []string) {
5255
// TODO: move to separate package
5356
flags.Version = version.Version
54-
logger.InitLogger(os.Stdout, flags.LogLevel)
57+
lvl := log.LogLevelFromStr(flags.LogLevel)
58+
logger := log.NewLogger(
59+
log.WithLevel(slog.Level(lvl)),
60+
log.WithHandlerType(log.TextHandlerType),
61+
)
62+
log.SetDefault(logger)
5563
},
5664
}
5765

@@ -192,15 +200,15 @@ func runLintMultiple(dirs []string) error {
192200
for _, dir := range dirs {
193201
expandedDir, err := fsutils.ExpandDir(dir)
194202
if err != nil {
195-
logger.ErrorF("Error expanding directory %s: %v", dir, err)
203+
log.Error("Error expanding directory", slog.String("dir", dir), log.Err(err))
196204
continue
197205
}
198206

199-
logger.InfoF("Processing directory: %s", expandedDir)
207+
log.Info("Processing directory", slog.String("directory", expandedDir))
200208

201209
// Run lint for this directory as a separate execution
202210
if err := runLint(expandedDir); err != nil {
203-
logger.ErrorF("Error processing directory %s: %v", expandedDir, err)
211+
log.Error("Error processing directory", slog.String("directory", expandedDir), log.Err(err))
204212
hasErrors = true
205213
// Continue processing other directories even if one fails
206214
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/Masterminds/semver/v3 v3.3.1
99
github.com/Masterminds/sprig/v3 v3.3.0
1010
github.com/bmatcuk/doublestar v1.3.4
11+
github.com/deckhouse/deckhouse/pkg/log v0.1.1
1112
github.com/fatih/color v1.16.0
1213
github.com/flant/addon-operator v1.5.0
1314
github.com/go-openapi/spec v0.21.0
@@ -51,6 +52,7 @@ require (
5152
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.1 // indirect
5253
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
5354
github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2 // indirect
55+
github.com/DataDog/gostackparse v0.7.0 // indirect
5456
github.com/Masterminds/goutils v1.1.1 // indirect
5557
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
5658
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg
2828
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
2929
github.com/Code-Hex/go-generics-cache v1.5.1 h1:6vhZGc5M7Y/YD8cIUcY8kcuQLB4cHR7U+0KMqAA0KcU=
3030
github.com/Code-Hex/go-generics-cache v1.5.1/go.mod h1:qxcC9kRVrct9rHeiYpFWSoW1vxyillCVzX13KZG8dl4=
31+
github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/IGQh4=
32+
github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM=
3133
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
3234
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
3335
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
@@ -63,6 +65,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
6365
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6466
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
6567
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
68+
github.com/deckhouse/deckhouse/pkg/log v0.1.1 h1:qHpMyj9coob+VfP3Qv+eIBa0pXFLn1FFRJztyryILB0=
69+
github.com/deckhouse/deckhouse/pkg/log v0.1.1/go.mod h1:pbAxTSDcPmwyl3wwKDcEB3qdxHnRxqTV+J0K+sha8bw=
6670
github.com/dennwc/varint v1.0.0 h1:kGNFFSSw8ToIy3obO/kKr8U9GZYUAxQEVuix4zfDWzE=
6771
github.com/dennwc/varint v1.0.0/go.mod h1:hnItb35rvZvJrbTALZtY/iQfDs48JKRG1RPpgziApxA=
6872
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=

0 commit comments

Comments
 (0)