From d35ffd749e59edc6771a6345f06d466766cbe236 Mon Sep 17 00:00:00 2001 From: Pavel Okhlopkov Date: Tue, 10 Feb 2026 19:40:47 +0300 Subject: [PATCH 1/5] fix Signed-off-by: Pavel Okhlopkov --- .golangci.yml | 1 + internal/logger/logger.go | 4 + pkg/linters/module/rules/license.go | 17 ++- pkg/linters/module/rules/license_parser.go | 32 ++-- .../module/rules/license_parser_test.go | 144 +++++++----------- 5 files changed, 84 insertions(+), 114 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a52f62a7..9cd559d7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -68,6 +68,7 @@ linters: - all - '-ST1003' # waiting for package name will be fixed (underscores) - '-QF1008' # not need to fix; we understand how to call nested structs + - '-SA1019' # remove when fix logger revive: rules: - name: var-naming # waiting for package name will be fixed (incorrect naming) diff --git a/internal/logger/logger.go b/internal/logger/logger.go index edc329d8..1fa40e28 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -52,21 +52,25 @@ func InitLogger(w io.Writer, logLevel string) { log.SetOutput(io.Discard) } +// Deprecated: use slog directly instead of these wrapper functions func DebugF(format string, a ...any) { slog.Debug( fmt.Sprintf(format, a...)) } +// Deprecated: use slog directly instead of these wrapper functions func InfoF(format string, a ...any) { slog.Info( fmt.Sprintf(format, a...)) } +// Deprecated: use slog directly instead of these wrapper functions func WarnF(format string, a ...any) { slog.Warn( fmt.Sprintf(format, a...)) } +// Deprecated: use slog directly instead of these wrapper functions func ErrorF(format string, a ...any) { slog.Error( fmt.Sprintf(format, a...)) diff --git a/pkg/linters/module/rules/license.go b/pkg/linters/module/rules/license.go index 591ae3aa..56e48daf 100644 --- a/pkg/linters/module/rules/license.go +++ b/pkg/linters/module/rules/license.go @@ -17,6 +17,7 @@ limitations under the License. package rules import ( + "errors" "os" "regexp" @@ -24,7 +25,7 @@ import ( "github.com/deckhouse/dmt/internal/logger" "github.com/deckhouse/dmt/internal/module" "github.com/deckhouse/dmt/pkg" - "github.com/deckhouse/dmt/pkg/errors" + pkgerrors "github.com/deckhouse/dmt/pkg/errors" ) const ( @@ -59,7 +60,7 @@ type LicenseRule struct { pkg.PathRule } -func (r *LicenseRule) CheckFiles(mod *module.Module, errorList *errors.LintRuleErrorsList) { +func (r *LicenseRule) CheckFiles(mod *module.Module, errorList *pkgerrors.LintRuleErrorsList) { errorList = errorList.WithRule(r.GetName()) // Use new parser if available @@ -74,15 +75,15 @@ func (r *LicenseRule) CheckFiles(mod *module.Module, errorList *errors.LintRuleE continue } - licenseInfo, parseErr := parser.ParseFile(fileName) - if parseErr != nil { - errorList.WithFilePath(name).Error(parseErr.Error()) + _, parseErr := parser.ParseFile(fileName) + if errors.Is(parseErr, ErrUnsupportedFileType) { + logger.DebugF("Skipping unsupported file type: %s", name) continue } - // Handle parsed license info - if !licenseInfo.Valid { - errorList.WithFilePath(name).Error(licenseInfo.Error) + if parseErr != nil { + errorList.WithFilePath(name).Error(parseErr.Error()) + continue } } } diff --git a/pkg/linters/module/rules/license_parser.go b/pkg/linters/module/rules/license_parser.go index bd38c3ba..f2592589 100644 --- a/pkg/linters/module/rules/license_parser.go +++ b/pkg/linters/module/rules/license_parser.go @@ -18,6 +18,7 @@ package rules import ( "bufio" + "errors" "fmt" "os" "path/filepath" @@ -49,10 +50,8 @@ type FileTypeConfig struct { // LicenseInfo contains information about parsed license type LicenseInfo struct { - Type string // "CE", "EE", or empty - Year string // Extracted year - Valid bool // Whether license is valid - Error string // Error message if invalid + Type string // "CE", "EE", or empty + Year string // Extracted year } // LicenseParser handles license parsing and validation @@ -198,15 +197,14 @@ func initFileConfigs() map[string]FileTypeConfig { return configs } +var ErrUnsupportedFileType = fmt.Errorf("unsupported file type") + // ParseFile parses a file and extracts license information func (p *LicenseParser) ParseFile(filename string) (*LicenseInfo, error) { // Get file type configuration config := p.getFileConfig(filename) if config == nil { - return &LicenseInfo{ - Valid: false, - Error: fmt.Sprintf("unsupported file type: %s", filename), - }, nil + return nil, ErrUnsupportedFileType } // Read file header @@ -215,35 +213,29 @@ func (p *LicenseParser) ParseFile(filename string) (*LicenseInfo, error) { if err != nil { return nil, fmt.Errorf("failed to read file: %w", err) } + // Check for generated file markers if isHeaderMarkedAsGenerated(header) { - return &LicenseInfo{Valid: true}, nil + return &LicenseInfo{}, nil } // Try to extract license text from header licenseText := p.extractLicenseText(header, config) if licenseText == "" { - return &LicenseInfo{ - Valid: false, - Error: "no license header found", - }, nil + return nil, errors.New("no license header found") } // Match against known licenses for _, license := range p.licenses { if matched, year := p.matchLicense(licenseText, license); matched { return &LicenseInfo{ - Type: license.Type, - Year: year, - Valid: true, + Type: license.Type, + Year: year, }, nil } } - return &LicenseInfo{ - Valid: false, - Error: "license header does not match any known license", - }, nil + return nil, errors.New("license header does not match any known license") } // getFileConfig returns the configuration for a given file diff --git a/pkg/linters/module/rules/license_parser_test.go b/pkg/linters/module/rules/license_parser_test.go index a14d35b8..213a19dd 100644 --- a/pkg/linters/module/rules/license_parser_test.go +++ b/pkg/linters/module/rules/license_parser_test.go @@ -29,7 +29,8 @@ func TestLicenseParser_ParseFile(t *testing.T) { name string content string filename string - want LicenseInfo + want *LicenseInfo + wantErr bool }{ { name: "Generated Go file is skipped (block comment)", @@ -40,9 +41,7 @@ Code Generated by some-tool v1.2.3. DO NOT EDIT. package main `, - want: LicenseInfo{ - Valid: true, - }, + want: &LicenseInfo{}, }, { name: "Generated Go file is skipped", @@ -51,25 +50,19 @@ package main package main `, - want: LicenseInfo{ - Valid: true, - }, + want: &LicenseInfo{}, }, { name: "Generated YAML file is skipped", filename: "values.yaml", content: "# This file was generated automatically. Do not edit by hand.\nkey: value\n", - want: LicenseInfo{ - Valid: true, - }, + want: &LicenseInfo{}, }, { name: "Generated block comment is skipped", filename: "script.sh", content: "# AUTO-GENERATED FILE - DO NOT modify\necho hello\n", - want: LicenseInfo{ - Valid: true, - }, + want: &LicenseInfo{}, }, { name: "Go file with CE license (block comment)", @@ -94,10 +87,9 @@ package main func main() {} `, - want: LicenseInfo{ - Type: "CE", - Year: "2024", - Valid: true, + want: &LicenseInfo{ + Type: "CE", + Year: "2024", }, }, { @@ -110,10 +102,9 @@ Licensed under the Deckhouse Platform Enterprise Edition (EE) license. See https package main `, - want: LicenseInfo{ - Type: "EE", - Year: "2023", - Valid: true, + want: &LicenseInfo{ + Type: "EE", + Year: "2023", }, }, { @@ -137,10 +128,9 @@ package main echo "Hello" `, - want: LicenseInfo{ - Type: "CE", - Year: "2025", - Valid: true, + want: &LicenseInfo{ + Type: "CE", + Year: "2025", }, }, { @@ -153,10 +143,9 @@ echo "Hello" def main(): pass `, - want: LicenseInfo{ - Type: "EE", - Year: "2023", - Valid: true, + want: &LicenseInfo{ + Type: "EE", + Year: "2023", }, }, { @@ -166,10 +155,8 @@ def main(): func main() {} `, - want: LicenseInfo{ - Valid: false, - Error: "no license header found", - }, + want: nil, + wantErr: true, }, { name: "File with invalid license", @@ -179,10 +166,8 @@ func main() {} package main `, - want: LicenseInfo{ - Valid: false, - Error: "license header does not match any known license", - }, + want: nil, + wantErr: true, }, { name: "Lua file with CE license", @@ -206,10 +191,9 @@ limitations under the License. local function test() end `, - want: LicenseInfo{ - Type: "CE", - Year: "2024", - Valid: true, + want: &LicenseInfo{ + Type: "CE", + Year: "2024", }, }, { @@ -221,10 +205,9 @@ end apiVersion: v1 kind: ConfigMap `, - want: LicenseInfo{ - Type: "EE", - Year: "2023", - Valid: true, + want: &LicenseInfo{ + Type: "EE", + Year: "2023", }, }, { @@ -246,10 +229,9 @@ kind: ConfigMap function main() {} `, - want: LicenseInfo{ - Type: "CE", - Year: "2024", - Valid: true, + want: &LicenseInfo{ + Type: "CE", + Year: "2024", }, }, } @@ -267,8 +249,12 @@ function main() {} // Parse file got, err := parser.ParseFile(tmpFile) - if err != nil { - t.Fatalf("ParseFile returned error: %v", err) + if (err != nil) != tt.wantErr { + t.Errorf("ParseFile() error = %v, wantErr %v", err, tt.wantErr) + return + } + if tt.wantErr { + return } // Compare results @@ -278,12 +264,6 @@ function main() {} if got.Year != tt.want.Year { t.Errorf("Year = %v, want %v", got.Year, tt.want.Year) } - if got.Valid != tt.want.Valid { - t.Errorf("Valid = %v, want %v", got.Valid, tt.want.Valid) - } - if got.Error != tt.want.Error { - t.Errorf("Error = %v, want %v", got.Error, tt.want.Error) - } }) } } @@ -389,34 +369,30 @@ func TestLicenseParser_EdgeCases(t *testing.T) { name string content string filename string - want LicenseInfo + want *LicenseInfo + wantErr bool }{ { name: "Empty file", filename: "empty.go", content: "", - want: LicenseInfo{ - Valid: false, - Error: "no license header found", - }, + want: nil, + wantErr: true, }, { name: "File with only whitespace", filename: "whitespace.go", content: " \n\n\t\t \n ", - want: LicenseInfo{ - Valid: false, - Error: "no license header found", - }, + want: nil, + wantErr: true, }, { name: "License with Windows line endings", filename: "windows.go", content: "/*\r\nCopyright 2024 Flant JSC\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\n\r\npackage main\r\n", - want: LicenseInfo{ - Type: "CE", - Year: "2024", - Valid: true, + want: &LicenseInfo{ + Type: "CE", + Year: "2024", }, }, { @@ -429,10 +405,9 @@ Licensed under the Deckhouse Platform Enterprise Edition (EE) license. See https export function main() {} `, - want: LicenseInfo{ - Type: "EE", - Year: "2023", - Valid: true, + want: &LicenseInfo{ + Type: "EE", + Year: "2023", }, }, { @@ -454,10 +429,9 @@ export function main() {} #pragma once `, - want: LicenseInfo{ - Type: "CE", - Year: "2024", - Valid: true, + want: &LicenseInfo{ + Type: "CE", + Year: "2024", }, }, } @@ -475,8 +449,12 @@ export function main() {} // Parse file got, err := parser.ParseFile(tmpFile) - if err != nil { - t.Fatalf("ParseFile returned error: %v", err) + if (err != nil) != tt.wantErr { + t.Errorf("ParseFile() error = %v, wantErr %v", err, tt.wantErr) + return + } + if tt.wantErr { + return } // Compare results @@ -486,12 +464,6 @@ export function main() {} if got.Year != tt.want.Year { t.Errorf("Year = %v, want %v", got.Year, tt.want.Year) } - if got.Valid != tt.want.Valid { - t.Errorf("Valid = %v, want %v", got.Valid, tt.want.Valid) - } - if got.Error != tt.want.Error { - t.Errorf("Error = %v, want %v", got.Error, tt.want.Error) - } }) } } From 60d5dff48232419f5e5caf79cccd9d1aa8314043 Mon Sep 17 00:00:00 2001 From: Pavel Okhlopkov Date: Tue, 10 Feb 2026 20:06:41 +0300 Subject: [PATCH 2/5] change logger to deckhouse Signed-off-by: Pavel Okhlopkov --- .golangci.yml | 1 - cmd/dmt/main.go | 19 +++--- cmd/dmt/root.go | 16 +++-- go.mod | 2 + go.sum | 4 ++ internal/bootstrap/bootstrap.go | 21 +++--- internal/engine/engine.go | 11 ++-- internal/flags/flags.go | 10 +-- internal/logger/logger.go | 85 ------------------------- internal/logger/logger_test.go | 79 ----------------------- internal/manager/manager.go | 17 ++--- internal/metrics/repository.go | 6 +- internal/metrics/service.go | 4 +- internal/values/values.go | 5 +- internal/werf/werf.go | 5 +- pkg/config/loader.go | 13 ++-- pkg/linters/module/rules/license.go | 7 +- pkg/linters/module/rules/module_yaml.go | 6 +- pkg/linters/templates/rules/ingress.go | 5 +- pkg/linters/templates/rules/registry.go | 6 +- 20 files changed, 90 insertions(+), 232 deletions(-) delete mode 100644 internal/logger/logger.go delete mode 100644 internal/logger/logger_test.go diff --git a/.golangci.yml b/.golangci.yml index 9cd559d7..a52f62a7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -68,7 +68,6 @@ linters: - all - '-ST1003' # waiting for package name will be fixed (underscores) - '-QF1008' # not need to fix; we understand how to call nested structs - - '-SA1019' # remove when fix logger revive: rules: - name: var-naming # waiting for package name will be fixed (incorrect naming) diff --git a/cmd/dmt/main.go b/cmd/dmt/main.go index e7d7e42e..6fc610c3 100644 --- a/cmd/dmt/main.go +++ b/cmd/dmt/main.go @@ -19,15 +19,16 @@ package main import ( "context" "errors" + "log/slog" "os" "runtime" "runtime/pprof" "github.com/fatih/color" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/flags" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" "github.com/deckhouse/dmt/internal/manager" "github.com/deckhouse/dmt/internal/metrics" "github.com/deckhouse/dmt/internal/version" @@ -40,17 +41,17 @@ func main() { func runLint(dir string) error { if flags.PprofFile != "" { - logger.InfoF("Profiling enabled. Profile file: %s", flags.PprofFile) + log.Info("Profiling enabled", slog.String("file", flags.PprofFile)) defer func() { pproFile, err := fsutils.ExpandDir(flags.PprofFile) if err != nil { - logger.ErrorF("could not get current working directory: %s", err) + log.Error("could not get current working directory", log.Err(err)) return } - logger.InfoF("Writing memory profile to %s", pproFile) + log.Info("Writing memory profile", slog.String("file", pproFile)) f, err := os.Create(pproFile) if err != nil { - logger.ErrorF("could not create memory profile: %s", err) + log.Error("could not create memory profile", log.Err(err)) return } defer f.Close() @@ -59,17 +60,19 @@ func runLint(dir string) error { // Alternatively, use Lookup("heap") for a profile // that has inuse_space as the default index. if err := pprof.Lookup("allocs").WriteTo(f, 0); err != nil { - logger.ErrorF("could not write memory profile: %s", err) + log.Error("could not write memory profile", log.Err(err)) return } }() } // enable color output for Github actions, do not remove it color.NoColor = false - logger.InfoF("DMT version: %s, Commit: %s, Date: %s", version.Version, version.Commit, version.Date) + log.Info("DMT version", slog.String("version", version.Version), slog.String("commit", version.Commit), slog.String("date", version.Date)) cfg, err := config.NewDefaultRootConfig(dir) - logger.CheckErr(err) + if err != nil { + log.Fatal("default root config", log.Err(err)) + } // init metrics storage, should be done before running manager metrics.GetClient(dir) diff --git a/cmd/dmt/root.go b/cmd/dmt/root.go index 664c03da..53fd6899 100644 --- a/cmd/dmt/root.go +++ b/cmd/dmt/root.go @@ -20,6 +20,7 @@ import ( "bytes" "errors" "fmt" + "log/slog" "os" "regexp" "strings" @@ -28,10 +29,10 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/bootstrap" "github.com/deckhouse/dmt/internal/flags" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" "github.com/deckhouse/dmt/internal/version" ) @@ -49,7 +50,12 @@ func execute() { PersistentPreRun: func(_ *cobra.Command, _ []string) { // TODO: move to separate package flags.Version = version.Version - logger.InitLogger(os.Stdout, flags.LogLevel) + lvl := log.LogLevelFromStr(flags.LogLevel) + logger := log.NewLogger( + log.WithLevel(slog.Level(lvl)), + log.WithHandlerType(log.TextHandlerType), + ) + log.SetDefault(logger) }, } @@ -170,15 +176,15 @@ func runLintMultiple(dirs []string) error { for _, dir := range dirs { expandedDir, err := fsutils.ExpandDir(dir) if err != nil { - logger.ErrorF("Error expanding directory %s: %v", dir, err) + log.Error("Error expanding directory", slog.String("dir", dir), log.Err(err)) continue } - logger.InfoF("Processing directory: %s", expandedDir) + log.Info("Processing directory", slog.String("directory", expandedDir)) // Run lint for this directory as a separate execution if err := runLint(expandedDir); err != nil { - logger.ErrorF("Error processing directory %s: %v", expandedDir, err) + log.Error("Error processing directory", slog.String("directory", expandedDir), log.Err(err)) hasErrors = true // Continue processing other directories even if one fails } diff --git a/go.mod b/go.mod index b9554c23..0365f3d4 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/Masterminds/semver/v3 v3.3.1 github.com/Masterminds/sprig/v3 v3.3.0 github.com/bmatcuk/doublestar v1.3.4 + github.com/deckhouse/deckhouse/pkg/log v0.1.1 github.com/fatih/color v1.16.0 github.com/flant/addon-operator v1.5.0 github.com/go-openapi/spec v0.21.0 @@ -50,6 +51,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2 // indirect + github.com/DataDog/gostackparse v0.7.0 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect diff --git a/go.sum b/go.sum index 6d788894..1f4a6e45 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,8 @@ github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/Code-Hex/go-generics-cache v1.5.1 h1:6vhZGc5M7Y/YD8cIUcY8kcuQLB4cHR7U+0KMqAA0KcU= github.com/Code-Hex/go-generics-cache v1.5.1/go.mod h1:qxcC9kRVrct9rHeiYpFWSoW1vxyillCVzX13KZG8dl4= +github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/IGQh4= +github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= 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 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/deckhouse/deckhouse/pkg/log v0.1.1 h1:qHpMyj9coob+VfP3Qv+eIBa0pXFLn1FFRJztyryILB0= +github.com/deckhouse/deckhouse/pkg/log v0.1.1/go.mod h1:pbAxTSDcPmwyl3wwKDcEB3qdxHnRxqTV+J0K+sha8bw= github.com/dennwc/varint v1.0.0 h1:kGNFFSSw8ToIy3obO/kKr8U9GZYUAxQEVuix4zfDWzE= github.com/dennwc/varint v1.0.0/go.mod h1:hnItb35rvZvJrbTALZtY/iQfDs48JKRG1RPpgziApxA= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go index 642be69f..e37dd1e8 100644 --- a/internal/bootstrap/bootstrap.go +++ b/internal/bootstrap/bootstrap.go @@ -21,6 +21,7 @@ import ( "context" "fmt" "io" + "log/slog" "net/http" "os" "path/filepath" @@ -30,8 +31,8 @@ import ( "github.com/iancoleman/strcase" "gopkg.in/yaml.v3" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" ) const ( @@ -61,7 +62,7 @@ type BootstrapConfig struct { // RunBootstrap initializes a new module with the given configuration func RunBootstrap(config BootstrapConfig) error { - logger.InfoF("Bootstrap type: %s", config.RepositoryType) + log.Info("Bootstrap type", slog.String("type", config.RepositoryType)) // if config.Directory does not exist, create it if _, err := os.Stat(config.Directory); os.IsNotExist(err) { @@ -75,7 +76,7 @@ func RunBootstrap(config BootstrapConfig) error { return fmt.Errorf("failed to get absolute directory path: %w", err) } - logger.InfoF("Using directory: %s", absDirectory) + log.Info("Using directory", slog.String("directory", absDirectory)) // Check if directory is empty if err := checkDirectoryEmpty(absDirectory); err != nil { @@ -114,7 +115,7 @@ func RunBootstrap(config BootstrapConfig) error { } } - logger.InfoF("Bootstrap completed successfully") + log.Info("Bootstrap completed successfully") return nil } @@ -145,7 +146,7 @@ func checkDirectoryEmpty(absDirectory string) error { return fmt.Errorf("directory is not empty. Please run bootstrap in an empty directory") } - logger.DebugF("Directory is empty, proceeding with bootstrap") + log.Debug("Directory is empty, proceeding with bootstrap") return nil } @@ -266,7 +267,7 @@ func downloadAndExtractTemplate(repositoryURL, directory string) error { // downloadFile downloads a file from URL to local path with timeout func downloadFile(url, targetPath string) error { - logger.InfoF("Downloading template from: %s", url) + log.Info("Downloading template", slog.String("url", url)) ctx, cancel := context.WithTimeout(context.Background(), downloadTimeout) defer cancel() @@ -299,13 +300,13 @@ func downloadFile(url, targetPath string) error { return fmt.Errorf("failed to write file: %w", err) } - logger.InfoF("Template downloaded successfully") + log.Info("Template downloaded successfully") return nil } // extractZip extracts a zip file to the specified directory func extractZip(zipPath, extractDir string) error { - logger.DebugF("Extracting template archive") + log.Debug("Extracting template archive") reader, err := zip.OpenReader(zipPath) if err != nil { @@ -380,7 +381,7 @@ func extractZip(zipPath, extractDir string) error { } } - logger.DebugF("Template extracted successfully") + log.Debug("Template extracted successfully") return nil } @@ -418,7 +419,7 @@ func moveExtractedContent(tempDir, directory string) error { } } - logger.DebugF("Template files moved to current directory") + log.Debug("Template files moved to current directory") return nil } diff --git a/internal/engine/engine.go b/internal/engine/engine.go index 1298191e..9ff010d9 100644 --- a/internal/engine/engine.go +++ b/internal/engine/engine.go @@ -19,6 +19,7 @@ package engine import ( "errors" "fmt" + "log/slog" "path" "path/filepath" "regexp" @@ -29,7 +30,7 @@ import ( "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chartutil" - "github.com/deckhouse/dmt/internal/logger" + "github.com/deckhouse/deckhouse/pkg/log" ) // Engine is an implementation of the Helm rendering implementation for templates. @@ -177,7 +178,7 @@ func (e Engine) initFuncMap(t *template.Template) { if val == nil { if e.LintMode { // Don't fail on missing required values when linting - logger.WarnF("[WARNING] Missing required value: %s", warn) + log.Warn("[WARNING] Missing required value", slog.String("value", warn)) return "", nil } return val, errors.New(warnWrap(warn)) @@ -185,7 +186,7 @@ func (e Engine) initFuncMap(t *template.Template) { if val == "" { if e.LintMode { // Don't fail on missing required values when linting - logger.ErrorF("[ERROR] Missing required value: %s", warn) + log.Error("[ERROR] Missing required value", slog.String("value", warn)) return "", nil } return val, errors.New(warnWrap(warn)) @@ -198,7 +199,7 @@ func (e Engine) initFuncMap(t *template.Template) { funcMap["fail"] = func(msg string) (string, error) { if e.LintMode { // Don't fail when linting - logger.WarnF("[WARNING] Fail: %s", msg) + log.Warn("[WARNING] Fail", slog.String("message", msg)) return "", nil } return "", errors.New(warnWrap(msg)) @@ -287,7 +288,7 @@ func (e Engine) render(tpls map[string]renderable) (rendered map[string]string, } if e.LintMode && isRecoverableNilError { - logger.ErrorF("[LINT] Template %s encountered a nil pointer access during execution: %v. Using partially rendered output.", filename, executeErr) + log.Error("[LINT] Template encountered a nil pointer access during execution. Using partially rendered output", slog.String("template", filename), slog.Any("error", executeErr)) rendered[filename] = getRenderedContent(&buf) } else { // For other errors, or if not in LintMode, this is a hard error. diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 055a53f8..4f2b53c3 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -19,7 +19,7 @@ package flags import ( "github.com/spf13/pflag" - "github.com/deckhouse/dmt/internal/logger" + "github.com/deckhouse/deckhouse/pkg/log" ) const ( @@ -72,27 +72,27 @@ func InitLintFlagSet() *pflag.FlagSet { lint.BoolVarP(&HideWarnings, "hide-warnings", "", false, "hide warnings") err := lint.MarkHidden("hide-warnings") if err != nil { - logger.ErrorF("mark hidden flag 'hide-warnings' is failed") + log.Error("mark hidden flag 'hide-warnings' is failed") } // make path absolute lint.BoolVarP(&AbsPath, "abs-path", "", false, "make paths absolute") err = lint.MarkHidden("abs-path") if err != nil { - logger.ErrorF("mark hidden flag 'abs-path' is failed") + log.Error("mark hidden flag 'abs-path' is failed") } // show ignored errors lint.BoolVarP(&ShowIgnored, "show-ignored", "", false, "show ignored errors") err = lint.MarkHidden("show-ignored") if err != nil { - logger.ErrorF("mark hidden flag 'show-ignored' is failed") + log.Error("mark hidden flag 'show-ignored' is failed") } lint.BoolVarP(&ShowDocumentation, "doc", "", false, "show documentation links") err = lint.MarkHidden("doc") if err != nil { - logger.ErrorF("mark hidden flag 'doc' is failed") + log.Error("mark hidden flag 'doc' is failed") } return lint diff --git a/internal/logger/logger.go b/internal/logger/logger.go deleted file mode 100644 index 1fa40e28..00000000 --- a/internal/logger/logger.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2025 Flant JSC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package logger - -import ( - "fmt" - "io" - "log" - "log/slog" - "os" -) - -const ( - DebugLogLevel = "DEBUG" - InfoLogLevel = "INFO" - WarnLogLevel = "WARN" - ErrorLogLevel = "ERROR" -) - -func InitLogger(w io.Writer, logLevel string) { - lvl := new(slog.LevelVar) - lvl.Set(slog.LevelInfo) - - logger := slog.New(slog.NewTextHandler(w, &slog.HandlerOptions{Level: lvl})) - - switch logLevel { - case DebugLogLevel: - lvl.Set(slog.LevelDebug) - case InfoLogLevel: - lvl.Set(slog.LevelInfo) - case WarnLogLevel: - lvl.Set(slog.LevelWarn) - case ErrorLogLevel: - lvl.Set(slog.LevelError) - } - - slog.SetDefault(logger) - log.SetOutput(io.Discard) -} - -// Deprecated: use slog directly instead of these wrapper functions -func DebugF(format string, a ...any) { - slog.Debug( - fmt.Sprintf(format, a...)) -} - -// Deprecated: use slog directly instead of these wrapper functions -func InfoF(format string, a ...any) { - slog.Info( - fmt.Sprintf(format, a...)) -} - -// Deprecated: use slog directly instead of these wrapper functions -func WarnF(format string, a ...any) { - slog.Warn( - fmt.Sprintf(format, a...)) -} - -// Deprecated: use slog directly instead of these wrapper functions -func ErrorF(format string, a ...any) { - slog.Error( - fmt.Sprintf(format, a...)) -} - -func CheckErr(msg any) { - if msg != nil { - slog.Error( - fmt.Sprintf("Error: %s", msg)) - os.Exit(1) - } -} diff --git a/internal/logger/logger_test.go b/internal/logger/logger_test.go deleted file mode 100644 index c3f3669d..00000000 --- a/internal/logger/logger_test.go +++ /dev/null @@ -1,79 +0,0 @@ -/* -Copyright 2025 Flant JSC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package logger - -import ( - "bytes" - "log/slog" - "testing" -) - -func TestInitLogger(t *testing.T) { - tests := []struct { - name string - logLevel string - expected string - }{ - {"DebugLevel", DebugLogLevel, "DEBUG"}, - {"InfoLevel", InfoLogLevel, "INFO"}, - {"WarnLevel", WarnLogLevel, "WARN"}, - {"ErrorLevel", ErrorLogLevel, "ERROR"}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - buf := bytes.Buffer{} - InitLogger(&buf, tt.logLevel) - slog.Debug("test debug") - slog.Info("test info") - slog.Warn("test warn") - slog.Error("test error") - - if !bytes.Contains(buf.Bytes(), []byte(tt.expected)) { - t.Errorf("expected log level %s not found in output", tt.expected) - } - buf.Reset() - }) - } -} - -func TestLogFunctions(t *testing.T) { - var buf bytes.Buffer - InitLogger(&buf, DebugLogLevel) - - DebugF("Debug message: %d", 1) - InfoF("Info message: %s", "test") - WarnF("Warn message") - ErrorF("Error message") - - logOutput := buf.String() - tests := []struct { - name string - expected string - }{ - {"DebugMessage", "Debug message: 1"}, - {"InfoMessage", "Info message: test"}, - {"WarnMessage", "Warn message"}, - {"ErrorMessage", "Error message"}, - } - - for _, tt := range tests { - if !bytes.Contains([]byte(logOutput), []byte(tt.expected)) { - t.Errorf("expected log message %q not found in output", tt.expected) - } - } -} diff --git a/internal/manager/manager.go b/internal/manager/manager.go index edf8121b..64546e28 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -20,6 +20,7 @@ import ( "bytes" "cmp" "fmt" + "log/slog" "os" "path/filepath" "slices" @@ -32,9 +33,9 @@ import ( "github.com/mitchellh/go-wordwrap" "helm.sh/helm/v3/pkg/chartutil" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/flags" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" "github.com/deckhouse/dmt/internal/metrics" "github.com/deckhouse/dmt/internal/module" "github.com/deckhouse/dmt/internal/values" @@ -94,24 +95,24 @@ func NewManager(dir string, rootConfig *config.RootConfig) *Manager { func (m *Manager) initManager(dir string) *Manager { paths, err := getModulePaths(dir) if err != nil { - logger.ErrorF("Error getting module paths: %v", err) + log.Error("Error getting module paths", log.Err(err)) return m } vals, err := decodeValuesFile(flags.ValuesFile) if err != nil { - logger.ErrorF("Failed to decode values file: %v", err) + log.Error("Failed to decode values file", log.Err(err)) } globalValues, err := values.GetGlobalValues(getRootDirectory(dir)) if err != nil { - logger.ErrorF("Failed to get global values: %v", err) + log.Error("Failed to get global values", log.Err(err)) return m } errorList := m.errors.WithLinterID("manager") for i := range paths { moduleName := filepath.Base(paths[i]) - logger.DebugF("Found `%s` module", moduleName) + log.Debug("Found module", slog.String("module", moduleName)) if err := m.validateModule(paths[i]); err != nil { // linting errors are already logged continue @@ -128,7 +129,7 @@ func (m *Manager) initManager(dir string) *Manager { m.Modules = append(m.Modules, mdl) } - logger.InfoF("Found %d modules", len(m.Modules)) + log.Info("Found modules", slog.Int("count", len(m.Modules))) return m } @@ -160,14 +161,14 @@ func (m *Manager) Run() { wg.Done() }() - logger.InfoF("Run linters for `%s` module", module.GetName()) + log.Info("Run linters for module", slog.String("module", module.GetName())) for _, linter := range getLintersForModule(module.GetModuleConfig(), m.errors) { if flags.LinterName != "" && linter.Name() != flags.LinterName { continue } - logger.DebugF("Running linter `%s` on module `%s`", linter.Name(), module.GetName()) + log.Debug("Running linter", slog.String("linter", linter.Name()), slog.String("module", module.GetName())) linter.Run(module) } diff --git a/internal/metrics/repository.go b/internal/metrics/repository.go index f950d2ba..a4afdcb1 100644 --- a/internal/metrics/repository.go +++ b/internal/metrics/repository.go @@ -22,8 +22,8 @@ import ( "gopkg.in/ini.v1" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" ) func getRepositoryAddress(dir string) string { @@ -34,13 +34,13 @@ func getRepositoryAddress(dir string) string { cfg, err := ini.Load(configFile) if err != nil { - logger.ErrorF("Failed to load config file: %v", err) + log.Error("Failed to load config file", log.Err(err)) return "" } sec, err := cfg.GetSection("remote \"origin\"") if err != nil { - logger.ErrorF("Failed to get remote \"origin\": %v", err) + log.Error("Failed to get remote origin", log.Err(err)) return "" } diff --git a/internal/metrics/service.go b/internal/metrics/service.go index 16deee30..9b345ec4 100644 --- a/internal/metrics/service.go +++ b/internal/metrics/service.go @@ -19,7 +19,7 @@ package metrics import ( "context" - "github.com/deckhouse/dmt/internal/logger" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/promremote" ) @@ -61,6 +61,6 @@ func (p *PrometheusMetricsService) Send(ctx context.Context) { promremote.WriteOptions{}, ) if err != nil { - logger.ErrorF("error in sending metrics: %v", err) + log.Error("error in sending metrics", log.Err(err)) } } diff --git a/internal/values/values.go b/internal/values/values.go index 92158dee..b8f4b903 100644 --- a/internal/values/values.go +++ b/internal/values/values.go @@ -3,6 +3,7 @@ package values import ( _ "embed" "fmt" + "log/slog" "os" "path/filepath" @@ -12,7 +13,7 @@ import ( "helm.sh/helm/v3/pkg/chartutil" "sigs.k8s.io/yaml" - "github.com/deckhouse/dmt/internal/logger" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/module/schema" ) @@ -92,7 +93,7 @@ func GetGlobalValues(rootDir string) (*spec.Schema, error) { if err != nil { return nil, err } - logger.InfoF("Using global values from `%s` directory", rootDir) + log.Info("Using global values", slog.String("directory", rootDir)) configBytes = configBytesT valuesBytes = valuesBytesT } diff --git a/internal/werf/werf.go b/internal/werf/werf.go index f5a586a6..9cfc00ae 100644 --- a/internal/werf/werf.go +++ b/internal/werf/werf.go @@ -22,6 +22,7 @@ import ( "crypto/rand" "errors" "fmt" + "log/slog" "math/big" "os" "path/filepath" @@ -32,8 +33,8 @@ import ( "github.com/Masterminds/sprig/v3" "sigs.k8s.io/yaml" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" ) const ( @@ -84,7 +85,7 @@ func GetWerfConfig(dir string) (string, error) { func getRootWerfFile(dir string) string { absPath, err := filepath.Abs(dir) if err != nil { - logger.WarnF("Can't make abs path for %q: %s", dir, err) + log.Warn("Can't make abs path", slog.String("path", dir), log.Err(err)) absPath = filepath.Clean(dir) } diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 499e3a45..4c822481 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -19,6 +19,7 @@ package config import ( "errors" "fmt" + "log/slog" "os" "path/filepath" "slices" @@ -27,8 +28,8 @@ import ( "github.com/mitchellh/mapstructure" "github.com/spf13/viper" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" ) type LoaderOptions struct { @@ -69,7 +70,7 @@ func (l *Loader) setConfigFile() error { configSearchPaths := l.getConfigSearchPaths() - logger.DebugF("Config search paths: %s", configSearchPaths) + log.Debug("Config search paths", slog.Any("paths", configSearchPaths)) for _, p := range configSearchPaths { l.viper.AddConfigPath(p) @@ -86,7 +87,7 @@ func (l *Loader) getConfigSearchPaths() []string { absPath, err := filepath.Abs(firstArg) if err != nil { - logger.WarnF("Can't make abs path for %q: %s", firstArg, err) + log.Warn("Can't make abs path", slog.String("path", firstArg), log.Err(err)) absPath = filepath.Clean(firstArg) } @@ -114,7 +115,7 @@ func (l *Loader) getConfigSearchPaths() []string { // find home directory for global config if home, err := homedir.Dir(); err != nil { - logger.WarnF("Can't get user's home directory: %v", err) + log.Warn("Can't get user's home directory", log.Err(err)) } else if !slices.Contains(searchPaths, home) { searchPaths = append(searchPaths, home) } @@ -159,10 +160,10 @@ func (l *Loader) setConfigDir() error { if usedConfigFile == os.Stdin.Name() { usedConfigFile = "" - logger.InfoF("Reading config file stdin") + log.Info("Reading config file stdin") } - logger.DebugF("Used config file %s", usedConfigFile) + log.Debug("Used config file", slog.String("file", usedConfigFile)) return nil } diff --git a/pkg/linters/module/rules/license.go b/pkg/linters/module/rules/license.go index 56e48daf..d83eae52 100644 --- a/pkg/linters/module/rules/license.go +++ b/pkg/linters/module/rules/license.go @@ -18,11 +18,12 @@ package rules import ( "errors" + "log/slog" "os" "regexp" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" "github.com/deckhouse/dmt/internal/module" "github.com/deckhouse/dmt/pkg" pkgerrors "github.com/deckhouse/dmt/pkg/errors" @@ -77,7 +78,7 @@ func (r *LicenseRule) CheckFiles(mod *module.Module, errorList *pkgerrors.LintRu _, parseErr := parser.ParseFile(fileName) if errors.Is(parseErr, ErrUnsupportedFileType) { - logger.DebugF("Skipping unsupported file type: %s", name) + log.Debug("Skipping unsupported file type", slog.String("file", name)) continue } @@ -91,7 +92,7 @@ func (r *LicenseRule) CheckFiles(mod *module.Module, errorList *pkgerrors.LintRu func filterFiles(rootPath, path string) bool { f, err := os.Stat(path) if err != nil { - logger.DebugF("Error getting file info: %v", err) + log.Debug("Error getting file info", log.Err(err)) return false } if f.IsDir() { diff --git a/pkg/linters/module/rules/module_yaml.go b/pkg/linters/module/rules/module_yaml.go index b0419832..ec1abbe2 100644 --- a/pkg/linters/module/rules/module_yaml.go +++ b/pkg/linters/module/rules/module_yaml.go @@ -30,8 +30,8 @@ import ( "k8s.io/utils/ptr" "sigs.k8s.io/yaml" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" "github.com/deckhouse/dmt/pkg" "github.com/deckhouse/dmt/pkg/errors" ) @@ -135,13 +135,13 @@ func getModuleNameFromRepository(dir string) string { cfg, err := ini.Load(configFile) if err != nil { - logger.ErrorF("Failed to load config file: %v", err) + log.Error("Failed to load config file", log.Err(err)) return "" } sec, err := cfg.GetSection("remote \"origin\"") if err != nil { - logger.ErrorF("Failed to get remote \"origin\": %v", err) + log.Error("Failed to get remote origin", log.Err(err)) return "" } diff --git a/pkg/linters/templates/rules/ingress.go b/pkg/linters/templates/rules/ingress.go index b305c172..cc3fc5b3 100644 --- a/pkg/linters/templates/rules/ingress.go +++ b/pkg/linters/templates/rules/ingress.go @@ -17,12 +17,13 @@ limitations under the License. package rules import ( + "log/slog" "strings" v1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/runtime" - "github.com/deckhouse/dmt/internal/logger" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/storage" "github.com/deckhouse/dmt/pkg" "github.com/deckhouse/dmt/pkg/errors" @@ -57,7 +58,7 @@ func (r *IngressRule) CheckSnippetsRule(object storage.StoreObject, errorList *e } if !r.Enabled(object.Unstructured.GetKind(), object.Unstructured.GetName()) { - logger.InfoF("⚠️ Skip Ingress %q due to exclusion rule.\n", object.Unstructured.GetName()) + log.Info("⚠️ Skip Ingress due to exclusion rule", slog.String("name", object.Unstructured.GetName())) return } diff --git a/pkg/linters/templates/rules/registry.go b/pkg/linters/templates/rules/registry.go index 7d7c6d63..9b5f8e90 100644 --- a/pkg/linters/templates/rules/registry.go +++ b/pkg/linters/templates/rules/registry.go @@ -25,8 +25,8 @@ import ( "gopkg.in/ini.v1" + "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/dmt/internal/fsutils" - "github.com/deckhouse/dmt/internal/logger" "github.com/deckhouse/dmt/internal/module" "github.com/deckhouse/dmt/pkg" "github.com/deckhouse/dmt/pkg/errors" @@ -95,13 +95,13 @@ func getModuleNameFromRepository(dir string) string { cfg, err := ini.Load(configFile) if err != nil { - logger.ErrorF("Failed to load config file: %v", err) + log.Error("Failed to load config file", log.Err(err)) return "" } sec, err := cfg.GetSection("remote \"origin\"") if err != nil { - logger.ErrorF("Failed to get remote \"origin\": %v", err) + log.Error("Failed to get remote origin", log.Err(err)) return "" } From d9f69a94a4953f6e11b58ee0783d0acb665530fd Mon Sep 17 00:00:00 2001 From: Pavel Okhlopkov Date: Tue, 10 Feb 2026 20:07:05 +0300 Subject: [PATCH 3/5] lint Signed-off-by: Pavel Okhlopkov --- cmd/dmt/main.go | 1 + cmd/dmt/root.go | 1 + internal/bootstrap/bootstrap.go | 1 + internal/manager/manager.go | 1 + internal/metrics/repository.go | 1 + internal/metrics/service.go | 1 + internal/values/values.go | 1 + internal/werf/werf.go | 1 + pkg/config/loader.go | 1 + pkg/linters/module/rules/license.go | 1 + pkg/linters/module/rules/module_yaml.go | 1 + pkg/linters/templates/rules/ingress.go | 1 + pkg/linters/templates/rules/registry.go | 1 + 13 files changed, 13 insertions(+) diff --git a/cmd/dmt/main.go b/cmd/dmt/main.go index 6fc610c3..5eedadc6 100644 --- a/cmd/dmt/main.go +++ b/cmd/dmt/main.go @@ -27,6 +27,7 @@ import ( "github.com/fatih/color" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/flags" "github.com/deckhouse/dmt/internal/fsutils" "github.com/deckhouse/dmt/internal/manager" diff --git a/cmd/dmt/root.go b/cmd/dmt/root.go index 53fd6899..9e2e8c1b 100644 --- a/cmd/dmt/root.go +++ b/cmd/dmt/root.go @@ -30,6 +30,7 @@ import ( "github.com/spf13/cobra" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/bootstrap" "github.com/deckhouse/dmt/internal/flags" "github.com/deckhouse/dmt/internal/fsutils" diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go index e37dd1e8..b27855fa 100644 --- a/internal/bootstrap/bootstrap.go +++ b/internal/bootstrap/bootstrap.go @@ -32,6 +32,7 @@ import ( "gopkg.in/yaml.v3" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/fsutils" ) diff --git a/internal/manager/manager.go b/internal/manager/manager.go index 64546e28..8038c941 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -34,6 +34,7 @@ import ( "helm.sh/helm/v3/pkg/chartutil" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/flags" "github.com/deckhouse/dmt/internal/fsutils" "github.com/deckhouse/dmt/internal/metrics" diff --git a/internal/metrics/repository.go b/internal/metrics/repository.go index a4afdcb1..865af618 100644 --- a/internal/metrics/repository.go +++ b/internal/metrics/repository.go @@ -23,6 +23,7 @@ import ( "gopkg.in/ini.v1" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/fsutils" ) diff --git a/internal/metrics/service.go b/internal/metrics/service.go index 9b345ec4..0d7c86ef 100644 --- a/internal/metrics/service.go +++ b/internal/metrics/service.go @@ -20,6 +20,7 @@ import ( "context" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/promremote" ) diff --git a/internal/values/values.go b/internal/values/values.go index b8f4b903..24b181b1 100644 --- a/internal/values/values.go +++ b/internal/values/values.go @@ -14,6 +14,7 @@ import ( "sigs.k8s.io/yaml" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/module/schema" ) diff --git a/internal/werf/werf.go b/internal/werf/werf.go index 9cfc00ae..6450bb6a 100644 --- a/internal/werf/werf.go +++ b/internal/werf/werf.go @@ -34,6 +34,7 @@ import ( "sigs.k8s.io/yaml" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/fsutils" ) diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 4c822481..7043dd45 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -29,6 +29,7 @@ import ( "github.com/spf13/viper" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/fsutils" ) diff --git a/pkg/linters/module/rules/license.go b/pkg/linters/module/rules/license.go index d83eae52..bc718371 100644 --- a/pkg/linters/module/rules/license.go +++ b/pkg/linters/module/rules/license.go @@ -23,6 +23,7 @@ import ( "regexp" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/fsutils" "github.com/deckhouse/dmt/internal/module" "github.com/deckhouse/dmt/pkg" diff --git a/pkg/linters/module/rules/module_yaml.go b/pkg/linters/module/rules/module_yaml.go index ec1abbe2..5b218a6a 100644 --- a/pkg/linters/module/rules/module_yaml.go +++ b/pkg/linters/module/rules/module_yaml.go @@ -31,6 +31,7 @@ import ( "sigs.k8s.io/yaml" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/fsutils" "github.com/deckhouse/dmt/pkg" "github.com/deckhouse/dmt/pkg/errors" diff --git a/pkg/linters/templates/rules/ingress.go b/pkg/linters/templates/rules/ingress.go index cc3fc5b3..27afce29 100644 --- a/pkg/linters/templates/rules/ingress.go +++ b/pkg/linters/templates/rules/ingress.go @@ -24,6 +24,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/storage" "github.com/deckhouse/dmt/pkg" "github.com/deckhouse/dmt/pkg/errors" diff --git a/pkg/linters/templates/rules/registry.go b/pkg/linters/templates/rules/registry.go index 9b5f8e90..74c815bc 100644 --- a/pkg/linters/templates/rules/registry.go +++ b/pkg/linters/templates/rules/registry.go @@ -26,6 +26,7 @@ import ( "gopkg.in/ini.v1" "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/dmt/internal/fsutils" "github.com/deckhouse/dmt/internal/module" "github.com/deckhouse/dmt/pkg" From 67d35deb2fcafb7a41f20a10b3208797f83bf689 Mon Sep 17 00:00:00 2001 From: Pavel Okhlopkov Date: Tue, 10 Feb 2026 20:08:02 +0300 Subject: [PATCH 4/5] lint Signed-off-by: Pavel Okhlopkov --- cmd/dmt/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/dmt/main.go b/cmd/dmt/main.go index 5eedadc6..46233668 100644 --- a/cmd/dmt/main.go +++ b/cmd/dmt/main.go @@ -72,7 +72,7 @@ func runLint(dir string) error { cfg, err := config.NewDefaultRootConfig(dir) if err != nil { - log.Fatal("default root config", log.Err(err)) + log.Fatal("default root config", log.Err(err)) //nolint:gocritic } // init metrics storage, should be done before running manager From e6f2fc6cb33feaabdba0962ce1f43e598d03d046 Mon Sep 17 00:00:00 2001 From: Pavel Okhlopkov <36456348+ldmonster@users.noreply.github.com> Date: Tue, 10 Feb 2026 20:14:17 +0300 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Pavel Okhlopkov <36456348+ldmonster@users.noreply.github.com> --- pkg/linters/module/rules/license_parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/linters/module/rules/license_parser.go b/pkg/linters/module/rules/license_parser.go index f2592589..337be22d 100644 --- a/pkg/linters/module/rules/license_parser.go +++ b/pkg/linters/module/rules/license_parser.go @@ -204,7 +204,7 @@ func (p *LicenseParser) ParseFile(filename string) (*LicenseInfo, error) { // Get file type configuration config := p.getFileConfig(filename) if config == nil { - return nil, ErrUnsupportedFileType + return nil, fmt.Errorf("%w: %s", ErrUnsupportedFileType, filename) } // Read file header