Skip to content

Commit c05fb37

Browse files
authored
[deckhouse-cli] lint (#216)
Signed-off-by: Pavel Okhlopkov <[email protected]>
1 parent c99d24d commit c05fb37

File tree

57 files changed

+296
-260
lines changed

Some content is hidden

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

57 files changed

+296
-260
lines changed

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ linters:
8888
- builtin$
8989
- examples$
9090
- _test\.go$
91+
- deepcopy\.go$
9192
formatters:
9293
enable:
9394
- gci

cmd/commands/delivery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewDeliveryCommand() (*cobra.Command, context.Context) {
4040
werfRootCmd = ReplaceCommandName("werf", "d8 dk", werfRootCmd)
4141
werfRootCmd.Short = "A set of tools for building, distributing, and deploying containerized applications"
4242
werfRootCmd.Long = werfRootCmd.Short + "."
43-
werfRootCmd.Long = werfRootCmd.Long + `
43+
werfRootCmd.Long += `
4444
4545
LICENSE NOTE: The Deckhouse Delivery Kit functionality is exclusively available to users holding a valid license for any commercial version of the Deckhouse Kubernetes Platform.
4646

cmd/commands/helpjson.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func NewHelpJSONCommand(rootCmd *cobra.Command) *cobra.Command {
5252
return helpJSONCmd
5353
}
5454

55-
func helpJSON(rootCmd *cobra.Command) func(cmd *cobra.Command, _ []string) error {
56-
return func(cmd *cobra.Command, _ []string) error {
55+
func helpJSON(rootCmd *cobra.Command) func(_ *cobra.Command, _ []string) error {
56+
return func(_ *cobra.Command, _ []string) error {
5757
commandsData := extractCommands(rootCmd.Root())
5858
jsonData, err := json.MarshalIndent(commandsData, "", " ")
5959
if err != nil {

cmd/commands/kubectl.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ func NewKubectlCommand() *cobra.Command {
159159
fmt.Fprintf(os.Stderr, "Continuing with default kubectl behavior...\n")
160160
} else {
161161
fmt.Fprintf(os.Stderr, "Using debug container image: %s\n", debugImage)
162-
cmd.Flags().Set("image", debugImage)
162+
if err := cmd.Flags().Set("image", debugImage); err != nil {
163+
fmt.Fprintf(os.Stderr, "Warning: cannot set debug image flag: %v\n", err)
164+
}
163165
}
164166
}
165167
}
@@ -190,7 +192,7 @@ func NewKubectlCommand() *cobra.Command {
190192
return pre(cmd, args)
191193
}
192194
default:
193-
kubectlCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
195+
kubectlCmd.PersistentPreRun = func(_ *cobra.Command, _ []string) {
194196
logs.InitLogs()
195197
}
196198
}

cmd/commands/stronghold.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func NewStrongholdCommand() *cobra.Command {
8282
DisableFlagParsing: true,
8383
SilenceErrors: true,
8484
SilenceUsage: true,
85-
Run: func(cmd *cobra.Command, args []string) {
85+
Run: func(_ *cobra.Command, args []string) {
8686
vaultcommand.Run(append(strongholdCommand, args...))
8787
},
8888
}

cmd/d8/root.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import (
2121
"fmt"
2222
"log"
2323
"log/slog"
24-
"math/rand"
2524
"os"
26-
"time"
2725

2826
"github.com/sirupsen/logrus"
2927
"github.com/spf13/cobra"
@@ -74,8 +72,8 @@ func NewRootCommand() *RootCommand {
7472
Version: version.Version,
7573
SilenceUsage: true,
7674
SilenceErrors: true,
77-
Run: func(cmd *cobra.Command, args []string) {
78-
cmd.Help()
75+
Run: func(cmd *cobra.Command, _ []string) {
76+
_ = cmd.Help()
7977
},
8078
}
8179

@@ -105,12 +103,9 @@ func (r *RootCommand) registerCommands() {
105103
r.cmd.AddCommand(plugins.NewPluginsCommand(r.logger.Named("plugins-command")))
106104
}
107105

108-
func (r *RootCommand) Execute() error {
106+
func (r *RootCommand) Execute() error { //nolint:unparam
109107
ctx := r.cmd.Context()
110108

111-
rand.Seed(time.Now().UnixNano())
112-
defer logs.FlushLogs()
113-
114109
if shouldTerminate, err := werfcommon.ContainerBackendProcessStartupHook(); err != nil {
115110
werfcommon.TerminateWithError(err.Error(), 1)
116111
} else if shouldTerminate {
@@ -126,23 +121,29 @@ func (r *RootCommand) Execute() error {
126121
}
127122

128123
if err := r.cmd.Execute(); err != nil {
129-
if helm_v3.IsPluginError(err) {
124+
switch {
125+
case helm_v3.IsPluginError(err):
130126
werfcommon.ShutdownTelemetry(ctx, helm_v3.PluginErrorCode(err))
131127
werfcommon.TerminateWithError(err.Error(), helm_v3.PluginErrorCode(err))
132-
} else if errors.Is(err, resrcchangcalc.ErrChangesPlanned) {
128+
case errors.Is(err, resrcchangcalc.ErrChangesPlanned):
133129
werfcommon.ShutdownTelemetry(ctx, 2)
130+
logs.FlushLogs()
134131
os.Exit(2)
135-
} else {
132+
default:
136133
werfcommon.ShutdownTelemetry(ctx, 1)
137134
werfcommon.TerminateWithError(err.Error(), 1)
138135
}
139136
}
140137

141138
werfcommon.ShutdownTelemetry(ctx, 0)
139+
logs.FlushLogs()
142140
return nil
143141
}
144142

145143
func execute() {
146144
rootCmd := NewRootCommand()
147-
rootCmd.Execute()
145+
if err := rootCmd.Execute(); err != nil {
146+
fmt.Fprintf(os.Stderr, "Error executing command: %v\n", err)
147+
os.Exit(1)
148+
}
148149
}

cmd/plugins/init.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
"github.com/deckhouse/deckhouse-cli/pkg/registry/service"
3131
)
3232

33-
func (r *PluginsCommand) initPluginServices() {
34-
r.logger.Debug("Initializing plugin services")
33+
func (pc *PluginsCommand) initPluginServices() {
34+
pc.logger.Debug("Initializing plugin services")
3535

3636
// Extract registry host from the source registry repo
3737
// SourceRegistryRepo can be:
@@ -48,22 +48,22 @@ func (r *PluginsCommand) initPluginServices() {
4848
testRef := registryHost
4949
if !containsSlash(registryHost) {
5050
// Just a hostname, use it as-is
51-
r.logger.Debug("Using hostname as registry", slog.String("host", registryHost))
51+
pc.logger.Debug("Using hostname as registry", slog.String("host", registryHost))
5252
} else {
5353
// Has path components, parse to extract registry
5454
ref, err := name.ParseReference(registryHost)
5555
if err == nil {
5656
registryHost = ref.Context().RegistryStr()
57-
r.logger.Debug("Extracted registry from path",
57+
pc.logger.Debug("Extracted registry from path",
5858
slog.String("original", testRef),
5959
slog.String("extracted", registryHost))
6060
}
6161
}
6262
}
6363

64-
auth := getPluginRegistryAuthProvider(registryHost, r.logger)
64+
auth := getPluginRegistryAuthProvider(registryHost, pc.logger)
6565

66-
r.logger.Debug("Creating plugin registry client",
66+
pc.logger.Debug("Creating plugin registry client",
6767
slog.String("registry_host", registryHost),
6868
slog.Bool("insecure", d8flags.Insecure),
6969
slog.Bool("tls_skip_verify", d8flags.TLSSkipVerify))
@@ -73,24 +73,24 @@ func (r *PluginsCommand) initPluginServices() {
7373
Auth: auth,
7474
Insecure: d8flags.Insecure,
7575
TLSSkipVerify: d8flags.TLSSkipVerify,
76-
Logger: r.logger.Named("registry-client"),
76+
Logger: pc.logger.Named("registry-client"),
7777
})
7878

7979
// Build scoped client using chained WithSegment calls
8080
// Example: registry.deckhouse.io -> deckhouse -> ee -> modules
81-
r.pluginRegistryClient = baseClient
81+
pc.pluginRegistryClient = baseClient
8282

83-
r.logger.Debug("Creating plugin service with scoped client",
83+
pc.logger.Debug("Creating plugin service with scoped client",
8484
slog.String("scope_path", strings.TrimPrefix(sourceRepo, sourceRepo)))
8585

8686
registryService := service.NewService(
87-
r.pluginRegistryClient,
88-
r.logger.Named("registry-service"),
87+
pc.pluginRegistryClient,
88+
pc.logger.Named("registry-service"),
8989
)
9090

91-
r.service = registryService.PluginService()
91+
pc.service = registryService.PluginService()
9292

93-
r.logger.Debug("Plugin services initialized successfully")
93+
pc.logger.Debug("Plugin services initialized successfully")
9494
}
9595

9696
// containsSlash checks if a string contains a forward slash

cmd/plugins/plugins.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewPluginsCommand(logger *dkplog.Logger) *cobra.Command {
6767
Use: "plugins",
6868
Short: "Manage Deckhouse CLI plugins",
6969
Hidden: true,
70-
PersistentPreRun: func(cmd *cobra.Command, args []string) {
70+
PersistentPreRun: func(_ *cobra.Command, _ []string) {
7171
// init plugin services for subcommands after flags are parsed
7272
pc.initPluginServices()
7373
},
@@ -92,7 +92,7 @@ func (pc *PluginsCommand) pluginsListCommand() *cobra.Command {
9292
Use: "list",
9393
Short: "List Deckhouse CLI plugins",
9494
Long: "Display detailed information about installed plugins and available plugins from the registry",
95-
RunE: func(cmd *cobra.Command, args []string) error {
95+
RunE: func(cmd *cobra.Command, _ []string) error {
9696
ctx := cmd.Context()
9797

9898
// Prepare all data before printing
@@ -549,7 +549,7 @@ func (pc *PluginsCommand) pluginsUpdateAllCommand() *cobra.Command {
549549
Use: "all",
550550
Short: "Update all installed plugins",
551551
Long: "Update all installed plugins to their latest available versions",
552-
RunE: func(cmd *cobra.Command, args []string) error {
552+
RunE: func(_ *cobra.Command, _ []string) error {
553553
// TODO: Implement updating all installed plugins from filesystem
554554
fmt.Println("Updating all installed plugins...")
555555
fmt.Println("Checking for updates...")
@@ -570,7 +570,7 @@ func (pc *PluginsCommand) pluginsRemoveCommand() *cobra.Command {
570570
Short: "Remove an installed plugin",
571571
Long: "Remove a specific plugin from the Deckhouse CLI",
572572
Args: cobra.ExactArgs(1),
573-
RunE: func(cmd *cobra.Command, args []string) error {
573+
RunE: func(_ *cobra.Command, args []string) error {
574574
pluginName := args[0]
575575
fmt.Printf("Removing plugin: %s\n", pluginName)
576576

@@ -596,7 +596,7 @@ func (pc *PluginsCommand) pluginsRemoveAllCommand() *cobra.Command {
596596
Use: "all",
597597
Short: "Remove all installed plugins",
598598
Long: "Remove all plugins from the Deckhouse CLI at once",
599-
RunE: func(cmd *cobra.Command, args []string) error {
599+
RunE: func(_ *cobra.Command, _ []string) error {
600600
// TODO: Implement removing all installed plugins from filesystem
601601
fmt.Println("Removing all installed plugins...")
602602

internal/mirror/chunked/chunk_reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Open(baseDir, baseFileName string) (*FileReader, error) {
5151
}
5252

5353
chunks = append(chunks, chunk)
54-
chunkIndex += 1
54+
chunkIndex++
5555
}
5656
}
5757

internal/mirror/chunked/chunk_writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (c *FileWriter) swapActiveChunk() error {
9696
if err := c.closeActiveChunk(); err != nil {
9797
return fmt.Errorf("Close active chunk file: %w", err)
9898
}
99-
c.chunkIndex += 1
99+
c.chunkIndex++
100100
}
101101

102102
newChunk, err := os.Create(filepath.Join(c.workingDir, fmt.Sprintf("%s.%04d.chunk", c.baseFileName, c.chunkIndex)))

0 commit comments

Comments
 (0)