diff --git a/.golangci.yml b/.golangci.yml index e90d26d05..4a2fc72b7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,17 +1,32 @@ +version: "2" linters: + disable: + - unused enable: - - errcheck - - gofmt - - govet - - ineffassign - - unconvert - - staticcheck - gocyclo - enable-all: false -linters-settings: - gocyclo: - # Minimal code complexity to report. - # Default: 30 (but we recommend 10-20) - min-complexity: 100 -run: - timeout: 20m + - unconvert + settings: + gocyclo: + # Minimal code complexity to report. + # Default: 30 (but we recommend 10-20) + min-complexity: 100 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/cmds/identityd/main.go b/cmds/identityd/main.go index 554634ff5..e1c718342 100644 --- a/cmds/identityd/main.go +++ b/cmds/identityd/main.go @@ -125,8 +125,8 @@ func main() { log.Fatal().Msgf("fail to connect to message broker server: %v\n", err) } - server.Register(zbus.ObjectID{Name: "manager", Version: "0.0.1"}, idMgr) - server.Register(zbus.ObjectID{Name: "monitor", Version: "0.0.1"}, monitor) + _ = server.Register(zbus.ObjectID{Name: "manager", Version: "0.0.1"}, idMgr) + _ = server.Register(zbus.ObjectID{Name: "monitor", Version: "0.0.1"}, monitor) ctx, cancel := utils.WithSignal(context.Background()) // register the cancel function with defer if the process stops because of a update diff --git a/cmds/modules/api_gateway/main.go b/cmds/modules/api_gateway/main.go index 94538fd6c..7dea8ad53 100644 --- a/cmds/modules/api_gateway/main.go +++ b/cmds/modules/api_gateway/main.go @@ -44,8 +44,8 @@ var Module cli.Command = cli.Command{ func action(cli *cli.Context) error { var ( - msgBrokerCon string = cli.String("broker") - workerNr uint = cli.Uint("workers") + msgBrokerCon = cli.String("broker") + workerNr = cli.Uint("workers") ) server, err := zbus.NewRedisServer(module, msgBrokerCon, workerNr) @@ -78,7 +78,7 @@ func action(cli *cli.Context) error { return fmt.Errorf("failed to create api gateway: %w", err) } - server.Register(zbus.ObjectID{Name: "api-gateway", Version: "0.0.1"}, gw) + _ = server.Register(zbus.ObjectID{Name: "api-gateway", Version: "0.0.1"}, gw) ctx, _ := utils.WithSignal(context.Background()) utils.OnDone(ctx, func(_ error) { @@ -112,7 +112,7 @@ func action(cli *cli.Context) error { // this ctx is used to allow the node to restart the peer without leaving any unwanted open connections currentPeerCtx, cancel := context.WithCancel(ctx) - backoff.Retry(func() error { + _ = backoff.Retry(func() error { _, err = peer.NewPeer( currentPeerCtx, hex.EncodeToString(pair.Seed()), @@ -181,7 +181,7 @@ func action(cli *cli.Context) error { } currentPeerCtx, cancel = context.WithCancel(ctx) - backoff.Retry(func() error { + _ = backoff.Retry(func() error { _, err = peer.NewPeer( currentPeerCtx, hex.EncodeToString(pair.Seed()), diff --git a/cmds/modules/contd/main.go b/cmds/modules/contd/main.go index 39fdc2f61..4ee91ba0f 100644 --- a/cmds/modules/contd/main.go +++ b/cmds/modules/contd/main.go @@ -49,10 +49,10 @@ var Module cli.Command = cli.Command{ func action(cli *cli.Context) error { var ( - moduleRoot string = cli.String("root") - msgBrokerCon string = cli.String("broker") - workerNr uint = cli.Uint("workers") - containerdCon string = cli.String("containerd") + moduleRoot = cli.String("root") + msgBrokerCon = cli.String("broker") + workerNr = cli.Uint("workers") + containerdCon = cli.String("containerd") ) // wait for shim-logs to be available before starting @@ -83,7 +83,7 @@ func action(cli *cli.Context) error { containerd := container.New(client, moduleRoot, containerdCon) - server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, containerd) + _ = server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, containerd) log.Info(). Str("broker", msgBrokerCon). diff --git a/cmds/modules/flistd/main.go b/cmds/modules/flistd/main.go index 2c348b366..d8bd4622e 100644 --- a/cmds/modules/flistd/main.go +++ b/cmds/modules/flistd/main.go @@ -48,9 +48,9 @@ var Module cli.Command = cli.Command{ func action(cli *cli.Context) error { var ( - moduleRoot string = cli.String("root") - msgBrokerCon string = cli.String("broker") - workerNr uint = cli.Uint("workers") + moduleRoot = cli.String("root") + msgBrokerCon = cli.String("broker") + workerNr = cli.Uint("workers") ) redis, err := zbus.NewRedisClient(msgBrokerCon) @@ -66,7 +66,7 @@ func action(cli *cli.Context) error { } mod := flist.New(moduleRoot, storage) - server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, mod) + _ = server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, mod) ctx, _ := utils.WithSignal(context.Background()) diff --git a/cmds/modules/gateway/main.go b/cmds/modules/gateway/main.go index 8ec49e0ff..6cbf3a288 100644 --- a/cmds/modules/gateway/main.go +++ b/cmds/modules/gateway/main.go @@ -43,9 +43,9 @@ var Module cli.Command = cli.Command{ func action(cli *cli.Context) error { var ( - moduleRoot string = cli.String("root") - msgBrokerCon string = cli.String("broker") - workerNr uint = cli.Uint("workers") + moduleRoot = cli.String("root") + msgBrokerCon = cli.String("broker") + workerNr = cli.Uint("workers") ) server, err := zbus.NewRedisServer(module, msgBrokerCon, workerNr) @@ -62,7 +62,7 @@ func action(cli *cli.Context) error { if err != nil { return errors.Wrap(err, "failed to construct gateway object") } - server.Register(zbus.ObjectID{Name: "manager", Version: "0.0.1"}, mod) + _ = server.Register(zbus.ObjectID{Name: "manager", Version: "0.0.1"}, mod) ctx, cancel := utils.WithSignal(context.Background()) defer cancel() diff --git a/cmds/modules/networkd/main.go b/cmds/modules/networkd/main.go index 381fcf467..27cb09039 100644 --- a/cmds/modules/networkd/main.go +++ b/cmds/modules/networkd/main.go @@ -54,8 +54,8 @@ var Module cli.Command = cli.Command{ func action(cli *cli.Context) error { var ( - root string = cli.String("root") - broker string = cli.String("broker") + root = cli.String("root") + broker = cli.String("broker") ) if err := os.MkdirAll(root, 0755); err != nil { @@ -159,7 +159,7 @@ func startZBusServer(ctx context.Context, broker string, networker pkg.Networker log.Error().Err(err).Msgf("fail to connect to message broker server") } - server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, networker) + _ = server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, networker) log.Info(). Str("broker", broker). diff --git a/cmds/modules/noded/main.go b/cmds/modules/noded/main.go index 91f325282..abd766855 100644 --- a/cmds/modules/noded/main.go +++ b/cmds/modules/noded/main.go @@ -72,7 +72,7 @@ func registerationServer(ctx context.Context, msgBrokerCon string, info registra } registrar := registrar.NewRegistrar(ctx, redis, info) - server.Register(zbus.ObjectID{Name: "registrar", Version: "0.0.1"}, registrar) + _ = server.Register(zbus.ObjectID{Name: "registrar", Version: "0.0.1"}, registrar) log.Debug().Msg("object registered") if err := server.Run(ctx); err != nil && err != context.Canceled { log.Fatal().Err(err).Msg("unexpected error exited registrar") @@ -82,9 +82,9 @@ func registerationServer(ctx context.Context, msgBrokerCon string, info registra func action(cli *cli.Context) error { var ( - msgBrokerCon string = cli.String("broker") - printID bool = cli.Bool("id") - printNet bool = cli.Bool("net") + msgBrokerCon = cli.String("broker") + printID = cli.Bool("id") + printNet = cli.Bool("net") ) env := environment.MustGet() subURLs := env.SubstrateURL @@ -162,7 +162,11 @@ func action(cli *cli.Context) error { WithSecureBoot(secureBoot). WithVirtualized(len(hypervisor) != 0) - go registerationServer(ctx, msgBrokerCon, info) + go func() { + if err := registerationServer(ctx, msgBrokerCon, info); err != nil { + log.Error().Err(err).Msg("registration server failed") + } + }() log.Info().Msg("start perf scheduler") perfMon, err := perf.NewPerformanceMonitor(msgBrokerCon) @@ -234,9 +238,9 @@ func action(cli *cli.Context) error { log.Fatal().Err(err).Msg("failed to initialize host monitor") } - server.Register(zbus.ObjectID{Name: "host", Version: "0.0.1"}, host) - server.Register(zbus.ObjectID{Name: "system", Version: "0.0.1"}, system) - server.Register(zbus.ObjectID{Name: "performance-monitor", Version: "0.0.1"}, perfMon) + _ = server.Register(zbus.ObjectID{Name: "host", Version: "0.0.1"}, host) + _ = server.Register(zbus.ObjectID{Name: "system", Version: "0.0.1"}, system) + _ = server.Register(zbus.ObjectID{Name: "performance-monitor", Version: "0.0.1"}, perfMon) log.Info().Uint32("node", node).Uint32("twin", twin).Msg("node registered") diff --git a/cmds/modules/powerd/main.go b/cmds/modules/powerd/main.go index 670e77482..1c653ca18 100644 --- a/cmds/modules/powerd/main.go +++ b/cmds/modules/powerd/main.go @@ -36,8 +36,8 @@ var Module cli.Command = cli.Command{ func action(cli *cli.Context) error { var ( - msgBrokerCon string = cli.String("broker") - powerdLabel string = "powerd" + msgBrokerCon = cli.String("broker") + powerdLabel = "powerd" ) ctx, _ := utils.WithSignal(cli.Context) diff --git a/cmds/modules/provisiond/main.go b/cmds/modules/provisiond/main.go index 4f3d0b0d2..c4dae2d10 100644 --- a/cmds/modules/provisiond/main.go +++ b/cmds/modules/provisiond/main.go @@ -106,11 +106,12 @@ func runChecks(ctx context.Context, rootDir string, cl zbus.Client) error { log.Info().Err(zuiErr).Send() } - cmd.CombinedOutput() + _, _ = cmd.CombinedOutput() err := cmd.Run() - if err == context.Canceled { + switch err { + case context.Canceled: return err - } else if err == nil { + case nil: return nil } @@ -128,9 +129,9 @@ func runChecks(ctx context.Context, rootDir string, cl zbus.Client) error { func action(cli *cli.Context) error { var ( - msgBrokerCon string = cli.String("broker") - rootDir string = cli.String("root") - integrity bool = cli.Bool("integrity") + msgBrokerCon = cli.String("broker") + rootDir = cli.String("root") + integrity = cli.Bool("integrity") ) server, err := zbus.NewRedisServer(serverName, msgBrokerCon, 1) @@ -194,7 +195,7 @@ func action(cli *cli.Context) error { network := stubs.NewNetworkerStub(cl) bo := backoff.NewExponentialBackOff() bo.MaxElapsedTime = 0 - backoff.RetryNotify(func() error { + _ = backoff.RetryNotify(func() error { return network.Ready(cli.Context) }, bo, func(err error, d time.Duration) { log.Error().Err(err).Msg("networkd is not ready yet") @@ -348,14 +349,14 @@ func action(cli *cli.Context) error { return errors.Wrap(err, "failed to instantiate provision engine") } - server.Register( + _ = server.Register( zbus.ObjectID{Name: provisionModule, Version: "0.0.1"}, pkg.Provision(engine), ) - server.Register( + _ = server.Register( zbus.ObjectID{Name: statisticsModule, Version: "0.0.1"}, - pkg.Statistics(primitives.NewStatisticsStream(statistics)), + primitives.NewStatisticsStream(statistics), ) log.Info(). diff --git a/cmds/modules/qsfsd/main.go b/cmds/modules/qsfsd/main.go index b04f9094c..41b0b6193 100644 --- a/cmds/modules/qsfsd/main.go +++ b/cmds/modules/qsfsd/main.go @@ -43,9 +43,9 @@ var Module cli.Command = cli.Command{ func action(cli *cli.Context) error { var ( - moduleRoot string = cli.String("root") - msgBrokerCon string = cli.String("broker") - workerNr uint = cli.Uint("workers") + moduleRoot = cli.String("root") + msgBrokerCon = cli.String("broker") + workerNr = cli.Uint("workers") ) server, err := zbus.NewRedisServer(module, msgBrokerCon, workerNr) @@ -66,7 +66,7 @@ func action(cli *cli.Context) error { return errors.Wrap(err, "failed to construct qsfsd object") } - server.Register(zbus.ObjectID{Name: "manager", Version: "0.0.1"}, mod) + _ = server.Register(zbus.ObjectID{Name: "manager", Version: "0.0.1"}, mod) log.Info(). Str("broker", msgBrokerCon). Uint("worker nr", workerNr). diff --git a/cmds/modules/storaged/main.go b/cmds/modules/storaged/main.go index 50e9a7bb1..33b9bc524 100644 --- a/cmds/modules/storaged/main.go +++ b/cmds/modules/storaged/main.go @@ -38,8 +38,8 @@ var Module cli.Command = cli.Command{ func action(cli *cli.Context) error { var ( - msgBrokerCon string = cli.String("broker") - workerNr uint = cli.Uint("workers") + msgBrokerCon = cli.String("broker") + workerNr = cli.Uint("workers") ) storageModule, err := storage.New(cli.Context) @@ -53,7 +53,7 @@ func action(cli *cli.Context) error { return errors.Wrap(err, "fail to connect to message broker server") } - server.Register(zbus.ObjectID{Name: "storage", Version: "0.0.1"}, storageModule) + _ = server.Register(zbus.ObjectID{Name: "storage", Version: "0.0.1"}, storageModule) log.Info(). Str("broker", msgBrokerCon). diff --git a/cmds/modules/vmd/main.go b/cmds/modules/vmd/main.go index e5419bad6..40b533202 100644 --- a/cmds/modules/vmd/main.go +++ b/cmds/modules/vmd/main.go @@ -74,9 +74,9 @@ func copyDepth1(src, dst string) error { func action(cli *cli.Context) error { var ( - moduleRoot string = cli.String("root") - msgBrokerCon string = cli.String("broker") - workerNr uint = cli.Uint("workers") + moduleRoot = cli.String("root") + msgBrokerCon = cli.String("broker") + workerNr = cli.Uint("workers") ) if err := os.MkdirAll(moduleRoot, 0755); err != nil { @@ -140,7 +140,7 @@ func action(cli *cli.Context) error { log.Error().Err(err).Msg("failed to clean up deprecated module root") } - server.Register(zbus.ObjectID{Name: "manager", Version: "0.0.1"}, mod) + _ = server.Register(zbus.ObjectID{Name: "manager", Version: "0.0.1"}, mod) ctx, _ := utils.WithSignal(context.Background()) utils.OnDone(ctx, func(_ error) { diff --git a/cmds/modules/zbusdebug/main.go b/cmds/modules/zbusdebug/main.go index 7a3f534de..627b7f346 100644 --- a/cmds/modules/zbusdebug/main.go +++ b/cmds/modules/zbusdebug/main.go @@ -52,8 +52,8 @@ var ( func action(cli *cli.Context) error { var ( - msgBrokerCon string = cli.String("broker") - module string = cli.String("module") + msgBrokerCon = cli.String("broker") + module = cli.String("module") ) cl, err := zbus.NewRedisClient(msgBrokerCon) @@ -99,7 +99,7 @@ func printModuleStatus(ctx context.Context, cl zbus.Client, module string) error enc := yaml.NewEncoder(os.Stdout) defer enc.Close() - enc.Encode(status) + _ = enc.Encode(status) fmt.Println() return nil } diff --git a/cmds/modules/zui/main.go b/cmds/modules/zui/main.go index 020d28a7b..45dae1e09 100644 --- a/cmds/modules/zui/main.go +++ b/cmds/modules/zui/main.go @@ -16,13 +16,6 @@ import ( const module string = "zui" -func trimFloat64(a []float64, size int) []float64 { - if len(a) > size { - return a[len(a)-size:] - } - return a -} - // signalFlag is a safe flag type signalFlag int32 @@ -58,8 +51,8 @@ var Module cli.Command = cli.Command{ func action(ctx *cli.Context) error { var ( - msgBrokerCon string = ctx.String("broker") - workerNr uint = ctx.Uint("workers") + msgBrokerCon = ctx.String("broker") + workerNr = ctx.Uint("workers") ) client, err := zbus.NewRedisClient(msgBrokerCon) @@ -126,7 +119,7 @@ func action(ctx *cli.Context) error { if err := netRender(client, netgrid, &flag); err != nil { log.Error().Err(err).Msg("failed to start net renderer") } - + if err := resourcesRender(client, resources, &flag); err != nil { log.Error().Err(err).Msg("failed to start resources renderer") } @@ -135,7 +128,7 @@ func action(ctx *cli.Context) error { mod := zui.New(ctx.Context, errorsParagraph, &flag) - server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, mod) + _ = server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, mod) go func() { if err := server.Run(ctx.Context); err != nil && err != context.Canceled { diff --git a/cmds/modules/zui/net.go b/cmds/modules/zui/net.go index bdc23462f..aa96d570f 100644 --- a/cmds/modules/zui/net.go +++ b/cmds/modules/zui/net.go @@ -52,7 +52,7 @@ func addressRender(ctx context.Context, table *widgets.Table, client zbus.Client toString := func(al pkg.NetlinkAddresses) string { var buf strings.Builder for _, a := range al { - if a.IP == nil || len(a.IP) == 0 { + if len(a.IP) == 0 { continue } diff --git a/cmds/modules/zui/service.go b/cmds/modules/zui/service.go index 978c99573..af09c2e8a 100644 --- a/cmds/modules/zui/service.go +++ b/cmds/modules/zui/service.go @@ -147,12 +147,12 @@ func getStatisticsStatus(ctx context.Context, client zbus.Client) { func getContainerdStatus(ctx context.Context, client zbus.Client) { statistics := stubs.NewContainerModuleStub(client) - statistics.ListNS(ctx) + _, _ = statistics.ListNS(ctx) } func getStoragedStatus(ctx context.Context, client zbus.Client) { storaged := stubs.NewStorageModuleStub(client) - storaged.Devices(ctx) + _, _ = storaged.Devices(ctx) } func getNodedStatus(ctx context.Context, client zbus.Client) { diff --git a/go.mod b/go.mod index 360794b11..fc1fe9777 100644 --- a/go.mod +++ b/go.mod @@ -20,15 +20,15 @@ require ( gopkg.in/yaml.v2 v2.4.0 ) -require github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - require ( + filippo.io/edwards25519 v1.2.0 // indirect github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect github.com/ChainSafe/go-schnorrkel v1.1.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/Microsoft/hcsshim v0.11.7 // indirect github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect github.com/alexflint/go-filemutex v1.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/containerd/cgroups v1.1.0 // indirect github.com/containerd/containerd v1.7.30 // indirect github.com/containerd/continuity v0.4.4 // indirect @@ -50,6 +50,7 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gtank/merlin v0.1.1 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.7 github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/hasura/go-graphql-client v0.10.0 // indirect @@ -66,6 +67,7 @@ require ( github.com/stretchr/testify v1.11.1 // indirect github.com/threefoldtech/0-fs v1.3.1-0.20240424140157-b488dfedcc56 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect + github.com/vedhavyas/go-subkey/v2 v2.0.0 // indirect github.com/vishvananda/netlink v1.2.1-beta.2 github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect github.com/whs/nacl-sealed-box v0.0.0-20180930164530-92b9ba845d8d // indirect @@ -75,13 +77,12 @@ require ( golang.org/x/sys v0.42.0 // indirect golang.org/x/text v0.35.0 // indirect golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b // indirect + google.golang.org/grpc v1.77.0 // indirect ) require ( - filippo.io/edwards25519 v1.2.0 // indirect github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/containerd/containerd/api v1.8.0 // indirect github.com/containerd/errdefs v0.3.0 // indirect github.com/containerd/log v0.1.0 // indirect @@ -151,7 +152,6 @@ require ( github.com/tklauser/numcpus v0.6.1 // indirect github.com/ulikunitz/xz v0.5.8 // indirect github.com/vedhavyas/go-subkey v1.0.3 // indirect - github.com/vedhavyas/go-subkey/v2 v2.0.0 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect github.com/xxtea/xxtea-go v0.0.0-20170828040851-35c4b17eecf6 // indirect @@ -171,7 +171,6 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b // indirect - google.golang.org/grpc v1.77.0 // indirect google.golang.org/protobuf v1.36.11 // indirect gopkg.in/djherbis/times.v1 v1.2.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect