Skip to content

Commit e217ab4

Browse files
kvapsclaude
andcommitted
fix(lint): resolve all golangci-lint issues
- Remove unused code: readFirstLine, kubernetesFlag, pathAutoCompleteLimit - Remove entirely unused track.go file - Replace deprecated io/ioutil with os package - Fix unchecked error returns for Close() methods - Fix ineffectual assignments in init.go - Remove empty branches in age.go Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent c4a867a commit e217ab4

9 files changed

Lines changed: 9 additions & 88 deletions

File tree

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
"strings"
@@ -145,7 +144,7 @@ func initConfig() {
145144
}
146145

147146
func loadConfig(filename string) error {
148-
data, err := ioutil.ReadFile(filename)
147+
data, err := os.ReadFile(filename)
149148
if err != nil {
150149
return fmt.Errorf("error reading configuration file: %w", err)
151150
}

pkg/age/age.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,8 @@ func mergeAndEncryptYAMLValues(plain, encrypted interface{}, identity *age.X2551
420420
// Values are the same, keep existing encrypted value (idempotent)
421421
return encryptedStr, nil
422422
}
423-
// If decryption fails or values differ, encrypt new value
424-
} else if encryptedStr == plainVal {
425-
// Both are plain strings and equal, but we need encrypted version
426-
// Encrypt the plain value
427-
} else {
428-
// Values differ, encrypt new value
429423
}
430-
431-
// Encrypt the new value
424+
// Encrypt the new value (if decryption fails, values differ, or both are plain)
432425
return encryptYAMLValues(plain, identity.Recipient())
433426

434427
default:

pkg/commands/apply.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
package commands
1616

1717
import (
18-
"bufio"
1918
"context"
2019
"errors"
2120
"fmt"
22-
"os"
2321
"time"
2422

2523
"github.com/cozystack/talm/pkg/engine"
@@ -188,33 +186,6 @@ func apply(args []string) error {
188186
return nil
189187
}
190188

191-
// readFirstLine reads and returns the first line of the file specified by the filename.
192-
// It returns an error if opening or reading the file fails.
193-
func readFirstLine(filename string) (string, error) {
194-
// Open the file
195-
file, err := os.Open(filename)
196-
if err != nil {
197-
return "", fmt.Errorf("error opening file: %v", err)
198-
}
199-
defer file.Close() // Ensure the file is closed after reading
200-
201-
// Create a scanner to read the file
202-
scanner := bufio.NewScanner(file)
203-
204-
// Read the first line
205-
if scanner.Scan() {
206-
return scanner.Text(), nil
207-
}
208-
209-
// Check for errors during scanning
210-
if err := scanner.Err(); err != nil {
211-
return "", fmt.Errorf("error reading file: %v", err)
212-
}
213-
214-
// If no lines in the file, return an empty string
215-
return "", nil
216-
}
217-
218189
func init() {
219190
applyCmd.Flags().BoolVarP(&applyCmdFlags.insecure, "insecure", "i", false, "apply using the insecure (encrypted with no auth) maintenance service")
220191
applyCmd.Flags().StringSliceVarP(&applyCmdFlags.configFiles, "file", "f", nil, "specify config files or patches in a YAML file (can specify multiple)")

pkg/commands/init.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,8 @@ var initCmd = &cobra.Command{
324324

325325
// If encrypted file exists, decrypt it (don't require key - will generate if needed)
326326
if encryptedTalosconfigFileExists && !talosconfigFileExists {
327-
_, err := handleTalosconfigEncryption(false)
328-
if err != nil {
329-
// If decryption fails (e.g., no key), continue to generate
330-
}
327+
// If decryption fails (e.g., no key), continue to generate
328+
_, _ = handleTalosconfigEncryption(false)
331329
talosconfigFileExists = fileExists(talosconfigFile)
332330
}
333331

@@ -347,7 +345,6 @@ var initCmd = &cobra.Command{
347345
if err = writeToDestination(data, talosconfigFile, 0o600); err != nil {
348346
return err
349347
}
350-
talosconfigFileExists = true
351348
}
352349

353350
// Encrypt talosconfig if needed
@@ -385,7 +382,6 @@ var initCmd = &cobra.Command{
385382
if err != nil {
386383
return fmt.Errorf("failed to generate key: %w", err)
387384
}
388-
keyFileExists = true // Update flag after creation
389385
keyWasCreated = keyCreated
390386
}
391387

@@ -417,7 +413,7 @@ var initCmd = &cobra.Command{
417413
if chartName == initCmdFlags.preset {
418414
file := filepath.Join(Config.RootDir, filepath.Join(parts[1:]...))
419415
if parts[len(parts)-1] == "Chart.yaml" {
420-
writeToDestination([]byte(fmt.Sprintf(content, clusterName, Config.InitOptions.Version)), file, 0o644)
416+
err = writeToDestination([]byte(fmt.Sprintf(content, clusterName, Config.InitOptions.Version)), file, 0o644)
421417
} else {
422418
err = writeToDestination([]byte(content), file, 0o644)
423419
}
@@ -429,7 +425,7 @@ var initCmd = &cobra.Command{
429425
if chartName == "talm" {
430426
file := filepath.Join(Config.RootDir, filepath.Join("charts", path))
431427
if parts[len(parts)-1] == "Chart.yaml" {
432-
writeToDestination([]byte(fmt.Sprintf(content, "talm", Config.InitOptions.Version)), file, 0o644)
428+
err = writeToDestination([]byte(fmt.Sprintf(content, "talm", Config.InitOptions.Version)), file, 0o644)
433429
} else {
434430
err = writeToDestination([]byte(content), file, 0o644)
435431
}
@@ -856,7 +852,6 @@ func handleTalosconfigEncryption(requireKeyForDecrypt bool) (bool, error) {
856852
if keyCreated {
857853
fmt.Fprintf(os.Stderr, "Generated new encryption key: talm.key\n")
858854
}
859-
keyFileExists = true
860855
}
861856

862857
// Encrypt talosconfig

pkg/commands/root.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import (
3030
"github.com/siderolabs/talos/pkg/machinery/client"
3131
)
3232

33-
var kubernetesFlag bool
34-
3533
// GlobalArgs is the common arguments for the root command.
3634
var GlobalArgs global.Args
3735

@@ -72,8 +70,6 @@ var Config struct {
7270
}
7371
}
7472

75-
const pathAutoCompleteLimit = 500
76-
7773
// WithClientNoNodes wraps common code to initialize Talos client and provide cancellable context.
7874
//
7975
// WithClientNoNodes doesn't set any node information on the request context.

pkg/commands/track.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

pkg/engine/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ func applyPatchesAndRenderConfig(ctx context.Context, opts Options, configPatche
544544
if err := encoder.Encode(&targetNode); err != nil {
545545
return nil, err
546546
}
547-
encoder.Close()
547+
_ = encoder.Close()
548548

549549
// Append extra documents (like UserVolumeConfig) that are not part of Talos config
550550
for _, extraDoc := range extraDocs {

pkg/modeline/modeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func ReadAndParseModeline(filePath string) (*Config, error) {
5656
if err != nil {
5757
return nil, fmt.Errorf("error opening config file: %v", err)
5858
}
59-
defer file.Close()
59+
defer func() { _ = file.Close() }()
6060

6161
scanner := bufio.NewScanner(file)
6262
if scanner.Scan() {

pkg/yamltools/yamltools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func DiffYAMLs(original, modified []byte) ([]byte, error) {
7777
if err := encoder.Encode(diff); err != nil {
7878
return nil, err
7979
}
80-
encoder.Close()
80+
_ = encoder.Close()
8181

8282
return buffer.Bytes(), nil
8383
}

0 commit comments

Comments
 (0)