Skip to content

Commit

Permalink
Update golangci-lint to support go version 1.23
Browse files Browse the repository at this point in the history
Some linters got inactivated leading to an error
when running the linter. Thus, they are now removed
from the config file's enable list.
  • Loading branch information
zolug committed Dec 12, 2024
1 parent 31901d7 commit 2fb97cf
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 28 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ run:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ output-dir:

.PHONY: golangci-lint
golangci-lint:
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2)
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2)

.PHONY: proto-compiler
proto-compiler: protoc protoc-gen-go protoc-gen-go-grpc
Expand Down
2 changes: 1 addition & 1 deletion api/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var _ = BeforeSuite(func() {
if err != nil {
return err
}
conn.Close()
_ = conn.Close()
return nil
}).Should(Succeed())

Expand Down
4 changes: 3 additions & 1 deletion cmd/frontend/internal/bird/bird.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ func (b *RoutingService) Run(ctx context.Context, monitorLogs bool) error {
return
}
// when context is done, close File thus signalling EOF to bufio Scan()
defer w.Close()
defer func() {
_ = w.Close()
}()
<-ctx.Done()
b.logger.Info("Context closed, terminate log monitoring")
}()
Expand Down
4 changes: 3 additions & 1 deletion cmd/frontend/internal/bird/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func (r *routingConfig) Apply() error {
if err != nil {
return fmt.Errorf("create %v, err: %v", r.path, err)
}
defer file.Close()
defer func() {
_ = file.Close()
}()

_, err = file.WriteString(r.config)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions cmd/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ func main() {
if err != nil {
log.Fatal(logger, "Dial NSP", "error", err)
}
defer conn.Close()
defer func() {
_ = conn.Close()
}()

// monitor status of NSP connection and adjust probe status accordingly
if err := connection.Monitor(ctx, health.NSPCliSvc, conn); err != nil {
Expand All @@ -131,7 +133,9 @@ func main() {
if err != nil {
log.Fatal(logger, "Dial loadbalancer", "error", err)
}
defer lbConn.Close()
defer func() {
_ = lbConn.Close()
}()

// create and start frontend service
c := &feConfig.Config{
Expand Down
4 changes: 3 additions & 1 deletion cmd/ipam/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ func main() {
if err != nil {
log.Fatal(logger, "Dial NSP err", "error", err)
}
defer conn.Close()
defer func() {
_ = conn.Close()
}()

// monitor status of NSP connection and adjust probe status accordingly
if err := connection.Monitor(ctx, health.NSPCliSvc, conn); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func setupTLSCert(socket string) error {
certDir := "/tmp/k8s-webhook-server/serving-certs"

go func() {
defer client.Close()
defer func() {
_ = client.Close()
}()
err := client.WatchX509Context(ctx, &x509Watcher{CertDir: certDir})
if err != nil && status.Code(err) != codes.Canceled {
log.Fatal(setupLog, "error watching X.509 context", "error", err)
Expand Down Expand Up @@ -132,7 +134,7 @@ func main() {
"Enabling this will ensure there is only one active controller manager.")

if os.Getenv(common.LogLevelEnv) == "" { // trace as default value
os.Setenv(common.LogLevelEnv, "trace")
_ = os.Setenv(common.LogLevelEnv, "trace")
}

ver := flag.Bool("version", false, "Print version and quit")
Expand Down
16 changes: 12 additions & 4 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ func main() {
if err != nil {
log.Fatal(logger, "Dialing IPAM", "error", err)
}
defer conn.Close()
defer func() {
_ = conn.Close()
}()

// monitor status of IPAM connection and adjust probe status accordingly
if err := connection.Monitor(signalCtx, health.IPAMCliSvc, conn); err != nil {
Expand Down Expand Up @@ -193,7 +195,9 @@ func main() {
if err != nil {
log.Fatal(logger, "Dialing NSP", "error", err)
}
defer nspConn.Close()
defer func() {
_ = nspConn.Close()
}()

// monitor status of NSP connection and adjust probe status accordingly
if err := connection.Monitor(signalCtx, health.NSPCliSvc, nspConn); err != nil {
Expand Down Expand Up @@ -234,14 +238,18 @@ func main() {
cancelSignalCtx()
return
}
defer cc.Close()
defer func() {
_ = cc.Close()
}()
monitorClient := networkservice.NewMonitorConnectionClient(cc)
go nsmmonitor.ConnectionMonitor(ctx, config.Name, monitorClient)

// create and start NSC that connects all remote NSE belonging to the right service
interfaceMonitorClient := interfacemonitor.NewClient(interfaceMonitor, p, netUtils)
nsmClient := service.GetNSC(ctx, &config, nsmAPIClient, p, interfaceMonitorClient, monitorClient)
defer nsmClient.Close()
defer func() {
_ = nsmClient.Close()
}()
go func() {
service.StartNSC(nsmClient, config.NetworkServiceName)
cancelSignalCtx() // let others with proper clean-up gracefully terminate
Expand Down
8 changes: 6 additions & 2 deletions cmd/stateless-lb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ func main() {
if err != nil {
log.Fatal(logger, "Dial NSP", "error", err)
}
defer conn.Close()
defer func() {
_ = conn.Close()
}()

// Monitor status of NSP connection and adjust probe status accordingly
if err := connection.Monitor(ctx, health.NSPCliSvc, conn); err != nil {
Expand Down Expand Up @@ -329,7 +331,9 @@ func main() {
cancel()
return
}
defer cc.Close()
defer func() {
_ = cc.Close()
}()
// Start monitoring NSM connections the LB is part of
monitorClient := networkservice.NewMonitorConnectionClient(cc)
go nsmmonitor.ConnectionMonitor(ctx, config.Name, monitorClient)
Expand Down
4 changes: 3 additions & 1 deletion cmd/tapa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ func main() {
if err != nil {
log.Fatal(logger, "dial to NSMgr", "error", err)
}
defer cc.Close()
defer func() {
_ = cc.Close()
}()
monitorClient := networkservice.NewMonitorConnectionClient(cc)

if err := os.RemoveAll(config.Socket); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/health/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func (hp *HealthProbe) Request(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to connect service %q, %w", hp.addr, err)
}
defer conn.Close()
defer func() {
_ = conn.Close()
}()

rpcCtx, rpcCancel := context.WithTimeout(ctx, hp.rpcTimeout)
defer rpcCancel()
Expand Down
12 changes: 9 additions & 3 deletions pkg/ipam/storage/sqlite/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const dbFileName = "test.db"

func Test_Add_Get(t *testing.T) {
_ = os.Remove(dbFileName)
defer os.Remove(dbFileName)
defer func() {
_ = os.Remove(dbFileName)
}()

store, err := sqlite.New(dbFileName)
assert.Nil(t, err)
Expand Down Expand Up @@ -74,7 +76,9 @@ func Test_Add_Get(t *testing.T) {

func Test_GetChilds(t *testing.T) {
_ = os.Remove(dbFileName)
defer os.Remove(dbFileName)
defer func() {
_ = os.Remove(dbFileName)
}()

store, err := sqlite.New(dbFileName)
assert.Nil(t, err)
Expand Down Expand Up @@ -106,7 +110,9 @@ func Test_GetChilds(t *testing.T) {

func Test_Delete(t *testing.T) {
_ = os.Remove(dbFileName)
defer os.Remove(dbFileName)
defer func() {
_ = os.Remove(dbFileName)
}()

store, err := sqlite.New(dbFileName)
assert.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/nsm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (apiClient *APIClient) Delete() {
apiClient.cancel()
}
if apiClient.GRPCClient != nil {
apiClient.GRPCClient.Close()
_ = apiClient.GRPCClient.Close()
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/nsp/registry/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (trsql *TargetRegistrySQLite) Close() error {
if err != nil {
return fmt.Errorf("failed to close db connection: %w", err)
}
sqlDB.Close()
_ = sqlDB.Close()
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/nsp/registry/sqlite/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func TestTargetRegistrySQLite_Set(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

dbFile := "test.db"
os.Remove(dbFile)
_ = os.Remove(dbFile)
db, err := sqlite.New(dbFile)
assert.Nil(t, err)
defer func() {
db.Close()
os.Remove(dbFile)
_ = db.Close()
_ = os.Remove(dbFile)
}()

ctx := context.Background()
Expand Down

0 comments on commit 2fb97cf

Please sign in to comment.