Skip to content

Commit

Permalink
chore: re-enable nolintlint and typecheck linters
Browse files Browse the repository at this point in the history
Drop startup/rand.go, as since Go 1.20 `rand.Seed` is done
automatically.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Aug 24, 2023
1 parent c51e2c9 commit 3c9f7a7
Show file tree
Hide file tree
Showing 135 changed files with 72 additions and 265 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ linters:
- nestif
- nilnil # we return "nil, nil"
- nonamedreturns
- nolintlint
- nosnakecase
- paralleltest
- promlinter # https://github.com/golangci/golangci-lint/issues/2222
- tagliatelle # we have many different conventions
- thelper
- typecheck
- varnamelen # too annoying
- wrapcheck
- contextcheck # enable once golangci-lint 1.50.1 or 1.51 lands
Expand Down
1 change: 0 additions & 1 deletion cmd/installer/pkg/install/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/siderolabs/talos/pkg/machinery/constants"
)

// nolint:gocyclo
func (i *Installer) installExtensions() error {
builder := extensions.Builder{
InitramfsPath: fmt.Sprintf(constants.InitramfsAssetPath, i.options.Arch),
Expand Down
1 change: 0 additions & 1 deletion cmd/talosctl/cmd/mgmt/gen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func validateFlags() error {
return err
}

// nolint:gocyclo
func writeConfigBundle(configBundle *bundle.Bundle, outputPaths configOutputPaths, commentsFlags encoder.CommentsFlags) error {
outputTypesSet := slices.ToSet(genConfigCmdFlags.outputTypes)

Expand Down
4 changes: 0 additions & 4 deletions cmd/talosctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ import (
"os"

"github.com/siderolabs/talos/cmd/talosctl/cmd"
"github.com/siderolabs/talos/pkg/cli"
"github.com/siderolabs/talos/pkg/startup"
)

func main() {
cli.Should(startup.RandSeed())

if err := cmd.Execute(); err != nil {
os.Exit(1)
}
Expand Down
4 changes: 0 additions & 4 deletions hack/cloud-image-uploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ package main
import (
"context"
cryptorand "crypto/rand"
"encoding/binary"
"encoding/json"
"fmt"
"io"
"log"
"math/rand"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -77,8 +75,6 @@ func run() error {
log.Fatalf("error seeding rand: %s", err)
}

rand.Seed(int64(binary.LittleEndian.Uint64(seed))) //nolint:staticcheck

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
4 changes: 0 additions & 4 deletions internal/app/apid/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ func apidMain() error {

startup.LimitMaxProcs(constants.ApidMaxProcs)

if err := startup.RandSeed(); err != nil {
return fmt.Errorf("failed to seed RNG: %w", err)
}

runtimeConn, err := grpc.Dial("unix://"+constants.APIRuntimeSocketPath, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("failed to dial runtime connection: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (cl *clusterState) String() string {
}))
}

//nolint:gocyclo,cyclop
//nolint:gocyclo
func buildClusterInfo(ctx context.Context,
req *clusterapi.HealthCheckRequest,
r runtime.Runtime,
Expand Down
16 changes: 5 additions & 11 deletions internal/app/machined/internal/server/v1alpha1/v1alpha1_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ func (s *Server) GenerateConfiguration(ctx context.Context, in *machine.Generate
}

// Reboot implements the machine.MachineServer interface.
//
//nolint:dupl
func (s *Server) Reboot(ctx context.Context, in *machine.RebootRequest) (reply *machine.RebootResponse, err error) {
actorID := uuid.New().String()

Expand Down Expand Up @@ -330,8 +328,6 @@ func (s *Server) Reboot(ctx context.Context, in *machine.RebootRequest) (reply *
}

// Rollback implements the machine.MachineServer interface.
//
//nolint:gocyclo
func (s *Server) Rollback(ctx context.Context, in *machine.RollbackRequest) (*machine.RollbackResponse, error) {
log.Printf("rollback via API received")

Expand Down Expand Up @@ -407,8 +403,6 @@ func (s *Server) Bootstrap(ctx context.Context, in *machine.BootstrapRequest) (r
}

// Shutdown implements the machine.MachineServer interface.
//
//nolint:dupl
func (s *Server) Shutdown(ctx context.Context, in *machine.ShutdownRequest) (reply *machine.ShutdownResponse, err error) {
actorID := uuid.New().String()

Expand Down Expand Up @@ -563,7 +557,7 @@ func (opt *ResetOptions) GetSystemDiskTargets() []runtime.PartitionTarget {

// Reset resets the node.
//
//nolint:gocyclo,cyclop
//nolint:gocyclo
func (s *Server) Reset(ctx context.Context, in *machine.ResetRequest) (reply *machine.ResetResponse, err error) {
actorID := uuid.New().String()

Expand Down Expand Up @@ -2229,7 +2223,7 @@ func (s *Server) PacketCapture(in *machine.PacketCaptureRequest, srv machine.Mac
if err = srv.SendMsg(&common.Data{Bytes: data}); err != nil {
cancel()

pr.CloseWithError(err) //nolint:errcheck
pr.CloseWithError(err)
}
}

Expand All @@ -2244,7 +2238,7 @@ func capturePackets(pw *io.PipeWriter, handle *pcapgo.EthernetHandle, snapLen ui
pcapw := pcapgo.NewWriterNanos(pw)

if err := pcapw.WriteFileHeader(snapLen, linkType); err != nil {
pw.CloseWithError(err) //nolint:errcheck
pw.CloseWithError(err)

return
}
Expand All @@ -2263,7 +2257,7 @@ func capturePackets(pw *io.PipeWriter, handle *pcapgo.EthernetHandle, snapLen ui
packet, err := pkgsrc.NextPacket()
if err == nil {
if err = pcapw.WritePacket(packet.Metadata().CaptureInfo, packet.Data()); err != nil {
pw.CloseWithError(err) //nolint:errcheck
pw.CloseWithError(err)

return
}
Expand All @@ -2286,7 +2280,7 @@ func capturePackets(pw *io.PipeWriter, handle *pcapgo.EthernetHandle, snapLen ui
errors.Is(err, io.ErrNoProgress) || errors.Is(err, io.ErrClosedPipe) || errors.Is(err, io.ErrShortBuffer) ||
errors.Is(err, syscall.EBADF) ||
strings.Contains(err.Error(), "use of closed file") {
pw.CloseWithError(err) //nolint:errcheck
pw.CloseWithError(err)

return
}
Expand Down
5 changes: 0 additions & 5 deletions internal/app/machined/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ func run() error {
// Limit GOMAXPROCS.
startup.LimitMaxProcs(constants.MachinedMaxProcs)

// Ensure RNG is seeded.
if err := startup.RandSeed(); err != nil {
return err
}

// Set the PATH env var.
if err := os.Setenv("PATH", constants.PATH); err != nil {
return errors.New("error setting PATH")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (ctrl *DiscoveryServiceController) Run(ctx context.Context, r controller.Ru
Affiliate: localData,
Endpoints: localEndpoints,
}, otherEndpoints); err != nil {
return fmt.Errorf("error setting local affiliate data: %w", err) //nolint:govet
return fmt.Errorf("error setting local affiliate data: %w", err)
}

prevLocalData = localData
Expand Down Expand Up @@ -312,7 +312,7 @@ func (ctrl *DiscoveryServiceController) Run(ctx context.Context, r controller.Ru

return nil
}); err != nil {
return err //nolint:govet
return err
}

touchedIDs[id] = struct{}{}
Expand Down
2 changes: 0 additions & 2 deletions internal/app/machined/pkg/controllers/cri/seccomp_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func (ctrl *SeccompProfileController) Outputs() []controller.Output {
}

// Run implements controller.StatsController interface.
//
//nolint:gocyclo,cyclop
func (ctrl *SeccompProfileController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
for {
select {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/machined/pkg/controllers/ctest/ctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// DefaultSuite is a base suite for controller testing.
type DefaultSuite struct { //nolint:govet
type DefaultSuite struct {
suite.Suite

state state.State
Expand Down
2 changes: 1 addition & 1 deletion internal/app/machined/pkg/controllers/etcd/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (ctrl *MemberController) Outputs() []controller.Output {

// Run implements controller.Controller interface.
//
//nolint:gocyclo,cyclop
//nolint:gocyclo
func (ctrl *MemberController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
for {
select {
Expand Down
4 changes: 2 additions & 2 deletions internal/app/machined/pkg/controllers/etcd/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (suite *MemberSuite) assertInexistentEtcdMember(member *etcd.Member) func()
}
}

func (suite *MemberSuite) TestEtcdRunning() { //nolint:dupl
func (suite *MemberSuite) TestEtcdRunning() {
// given
suite.ctrl.GetLocalMemberIDFunc = func(ctx context.Context) (uint64, error) {
return 123, nil
Expand All @@ -98,7 +98,7 @@ func (suite *MemberSuite) TestEtcdRunning() { //nolint:dupl
)
}

func (suite *MemberSuite) TestEtcdNotRunning() { //nolint:dupl
func (suite *MemberSuite) TestEtcdNotRunning() {
// given
suite.ctrl.GetLocalMemberIDFunc = func(ctx context.Context) (uint64, error) {
return 123, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//nolint:dupl
package k8s_test

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/app/machined/pkg/controllers/k8s/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func (ctrl *EndpointController) Run(ctx context.Context, r controller.Runtime, l
}
}

//nolint:gocyclo
func (ctrl *EndpointController) watchEndpointsOnWorker(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
logger.Debug("waiting for kubelet client config", zap.String("file", constants.KubeletKubeconfig))

Expand Down Expand Up @@ -144,7 +143,6 @@ func (ctrl *EndpointController) watchEndpointsOnWorker(ctx context.Context, r co
}
}

//nolint:gocyclo
func (ctrl *EndpointController) watchEndpointsOnControlPlane(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
if err := r.UpdateInputs([]controller.Input{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (ctrl *KubeletStaticPodController) Outputs() []controller.Output {

// Run implements controller.Controller interface.
//
//nolint:gocyclo,cyclop
//nolint:gocyclo
func (ctrl *KubeletStaticPodController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
var kubeletClient *kubelet.Client

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (ctrl *RenderSecretsStaticPodController) Name() string {
}

// Inputs implements controller.Controller interface.
func (ctrl *RenderSecretsStaticPodController) Inputs() []controller.Input { //nolint:dupl
func (ctrl *RenderSecretsStaticPodController) Inputs() []controller.Input {
return []controller.Input{
{
Namespace: secrets.NamespaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ type podList struct {
}

// Run implements controller.Controller interface.
//
//nolint:gocyclo,cyclop
func (ctrl *StaticPodServerController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
ctrl.staticPodVersions = map[string]string{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (ctrl *CRDController) Outputs() []controller.Output {

// Run implements controller.Controller interface.
//
//nolint:gocyclo,cyclop
//nolint:gocyclo
func (ctrl *CRDController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
var crdControllerCtxCancel context.CancelFunc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (t *CRDController) Run(ctx context.Context, workers int) error {
}

func (t *CRDController) runWorker(ctx context.Context) {
for t.processNextWorkItem(ctx) { //nolint:revive
for t.processNextWorkItem(ctx) {
}
}

Expand Down Expand Up @@ -293,7 +293,7 @@ func (t *CRDController) processNextWorkItem(ctx context.Context) bool {
return true
}

//nolint:gocyclo,cyclop,dupl
//nolint:gocyclo,cyclop
func (t *CRDController) syncHandler(ctx context.Context, key string) error {
namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//nolint:dupl
package network_test

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func (suite *AddressMergeSuite) TestMerge() {
)
}

//nolint:gocyclo
func (suite *AddressMergeSuite) TestMergeFlapping() {
// simulate two conflicting address definitions which are getting removed/added constantly
dhcp := network.NewAddressSpec(network.ConfigNamespaceName, "dhcp/eth0/10.0.0.1/8")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//nolint:dupl
package network_test

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//nolint:dupl
package network_test

import (
Expand Down Expand Up @@ -199,7 +198,7 @@ func (suite *EtcFileConfigSuite) TestNoSearchDomain() {
suite.testFiles(
[]resource.Resource{cfg, suite.defaultAddress, suite.hostnameStatus, suite.resolverStatus},
"nameserver 1.1.1.1\nnameserver 2.2.2.2\nnameserver 3.3.3.3\n",
"127.0.0.1 localhost\n33.11.22.44 foo.example.com foo\n::1 localhost ip6-localhost ip6-loopback\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters\n", //nolint:lll
"127.0.0.1 localhost\n33.11.22.44 foo.example.com foo\n::1 localhost ip6-localhost ip6-loopback\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters\n",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//nolint:dupl
package network_test

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ func (suite *LinkMergeSuite) TestMergeLogicalLink() {
)
}

//nolint:gocyclo
func (suite *LinkMergeSuite) TestMergeFlapping() {
// simulate two conflicting link definitions which are getting removed/added constantly
dhcp := network.NewLinkSpec(network.ConfigNamespaceName, "dhcp/eth0")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/machined/pkg/controllers/network/link_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (ctrl *LinkSpecController) Run(ctx context.Context, r controller.Runtime, l
// in proper order.
func SortBonds(items []resource.Resource) {
sort.Slice(items, func(i, j int) bool {
left := items[i].(*network.LinkSpec).TypedSpec() //nolint:errcheck
right := items[j].(*network.LinkSpec).TypedSpec() //nolint:errcheck
left := items[i].(*network.LinkSpec).TypedSpec()
right := items[j].(*network.LinkSpec).TypedSpec()

l := ordered.MakeTriple(left.Name, 0, "")
if left.BondSlave.MasterName != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (ctrl *LinkStatusController) Run(ctx context.Context, r controller.Runtime,
if err != nil {
logger.Warn("error dialing ethtool ioctl socket", zap.Error(err))
} else {
defer ethIoctlClient.Close() //nolint:errcheck
defer ethIoctlClient.Close()
}

wgClient, err := wgctrl.New()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (suite *LinkStatusSuite) TestInterfaceHwInfo() {
suite.Require().NoError(err)

for _, res := range resources.Items {
spec := res.(*network.LinkStatus).TypedSpec() //nolint:errcheck,forcetypeassert
spec := res.(*network.LinkStatus).TypedSpec() //nolint:forcetypeassert

if !spec.Physical() {
continue
Expand Down
Loading

0 comments on commit 3c9f7a7

Please sign in to comment.