diff --git a/.golangci.yaml b/.golangci.yaml index daf3ea25..442dc36e 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,7 +1,7 @@ --- run: # concurrency: 6 - go: "1.17" + go: "1.23" timeout: 2m issues-exit-code: 1 tests: true @@ -11,13 +11,14 @@ linters-settings: values: regexp: company: .* - copyright-holder: Copyright \(c\) ({{year-range}}) {{company}}\n\n + copyright-holder: Copyright \(c\) ({{mod-year-range}}) {{company}}\n\n copyright-holders: ({{copyright-holder}})+ errcheck: check-type-assertions: false check-blank: false govet: - check-shadowing: true + enable: + - shadow settings: printf: funcs: @@ -26,18 +27,37 @@ linters-settings: - (github.com/sirupsen/logrus.FieldLogger).Errorf - (github.com/sirupsen/logrus.FieldLogger).Fatalf revive: - min-confidence: 0.8 + confidence: 0.8 + rules: + - name: exported + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: increment-decrement + - name: var-naming + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: superfluous-else + - name: unreachable-code goimports: local-prefixes: github.com/networkservicemesh/sdk-kernel/ gocyclo: min-complexity: 16 - maligned: - suggest-new: true dupl: threshold: 150 funlen: - Lines: 100 - Statements: 50 + lines: 100 + statements: 50 goconst: min-len: 2 min-occurrences: 2 @@ -47,6 +67,9 @@ linters-settings: deny: - pkg: "errors" desc: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports" + # TODO - enable lll config https://github.com/networkservicemesh/sdk-kernel/issues/698 + # lll: + # line-length: 160 misspell: locale: US unparam: @@ -59,79 +82,45 @@ linters-settings: for-loops: false gocritic: enabled-checks: - - appendAssign - - assignOp - appendCombine - - argOrder - - badCall - - badCond - boolExprSimplify - builtinShadow - - captLocal - - caseOrder - - codegenComment - - commentFormatting - commentedOutCode - commentedOutImport - - defaultCaseOrder - - deprecatedComment - docStub - - dupArg - - dupBranchBody - - dupCase - dupImport - - dupSubExpr - - elseif - emptyFallthrough - emptyStringTest - equalFold - evalOrder - - exitAfterDefer - - flagDeref - - flagName - hexLiteral - hugeParam - - ifElseChain - importShadow - indexAlloc - initClause - methodExprCall - nestingReduce - - newDeref - nilValReturn - octalLiteral - - offBy1 - paramTypeCombine - - ptrToRefParam - rangeExprCopy - rangeValCopy - - regexpMust - regexpPattern - - singleCaseSwitch - - sloppyLen - sloppyReassign - stringXbytes - - switchTrue - typeAssertChain - - typeSwitchVar - typeUnparen - unlabelStmt - unnamedResult - unnecessaryBlock - - underef - - unlambda - - unslice - - valSwap - weakCond - - wrapperFunc - yodaStyleExpr linters: disable-all: true enable: - # - rowserrcheck - goheader - bodyclose - - deadcode + - unused - depguard - dogsled - dupl @@ -148,19 +137,15 @@ linters: - gosimple - govet - ineffassign - - interfacer # - lll - misspell - nakedret - - scopelint + - copyloopvar - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - # - unused - - varcheck - whitespace issues: exclude-use-default: false diff --git a/go.mod b/go.mod index ac7b3b5e..3ec429ea 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,14 @@ module github.com/networkservicemesh/sdk-kernel -go 1.20 +go 1.23 require ( github.com/edwarnicke/exechelper v1.0.2 github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 github.com/go-ping/ping v1.0.0 github.com/golang/protobuf v1.5.3 - github.com/networkservicemesh/api v1.13.4-0.20240815101554-fdbfcd84fd0e - github.com/networkservicemesh/sdk v0.5.1-0.20241106141620-b53ccb0ebe20 + github.com/networkservicemesh/api v1.14.2-0.20241114102931-df7655523954 + github.com/networkservicemesh/sdk v0.5.1-0.20241119101250-cb2dbb0eccc2 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 github.com/vishvananda/netlink v1.3.1-0.20240922070040-084abd93d350 diff --git a/go.sum b/go.sum index aaa3e159..53c86d44 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ github.com/edwarnicke/exechelper v1.0.2/go.mod h1:/T271jtNX/ND4De6pa2aRy2+8sNtyC github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 h1:4/2wgileNvQB4HfJbq7u4FFLKIfc38a6P0S/51ZGgX8= github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29/go.mod h1:3m+ZfVq+z0pTLW798jmqnifMsalrVLIKmfXaMFvqSuc= github.com/edwarnicke/serialize v1.0.7 h1:geX8vmyu8Ij2S5fFIXjy9gBDkKxXnrMIzMoDvV0Ddac= +github.com/edwarnicke/serialize v1.0.7/go.mod h1:y79KgU2P7ALH/4j37uTSIdNavHFNttqN7pzO6Y8B2aw= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -22,12 +23,14 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/go-ping/ping v1.0.0 h1:34GZiqLDqqIHEeL5NZIz7jSnMluK7/p0qDB436yO6H0= github.com/go-ping/ping v1.0.0/go.mod h1:35JbSyV/BYqHwwRA6Zr1uVDm1637YlNOU61wI797NPI= github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= +github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= @@ -35,13 +38,15 @@ github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/networkservicemesh/api v1.13.4-0.20240815101554-fdbfcd84fd0e h1:Fs34ZZN+bujq5OQEQUpxm0gYQ3g7uSCkcKcoUt70Be0= -github.com/networkservicemesh/api v1.13.4-0.20240815101554-fdbfcd84fd0e/go.mod h1:B8FmS3XZ7NZY7ZEtdcNg2NHYppDHlr4kl4eecdZN9eI= -github.com/networkservicemesh/sdk v0.5.1-0.20241106141620-b53ccb0ebe20 h1:MB62uePZ8UGYTFCJqdiFnLeakQx/m0BPwVp6tJRFWRs= -github.com/networkservicemesh/sdk v0.5.1-0.20241106141620-b53ccb0ebe20/go.mod h1:lV8RBwf6tHkNFwHLFkzh4Tb/XezMP5IHGx5lW04YjQE= +github.com/networkservicemesh/api v1.14.2-0.20241114102931-df7655523954 h1:oNSjeqM9XJcMGzHHZb+yZszlZnxNDnOpeTxg0sNvlsc= +github.com/networkservicemesh/api v1.14.2-0.20241114102931-df7655523954/go.mod h1:GT0Yw1LYFSTxlDyJjBDhIxT82rJ2czZ0TiyzxSyKzvg= +github.com/networkservicemesh/sdk v0.5.1-0.20241119101250-cb2dbb0eccc2 h1:PsFrDO5Nk1kvPb9ef1y+oPAp8LES2PjDgI+uh7NYQ0s= +github.com/networkservicemesh/sdk v0.5.1-0.20241119101250-cb2dbb0eccc2/go.mod h1:SXr8e/1CBLTbdW63DHcaMTSBF0v2mnNKgRMf7pELQso= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -55,6 +60,7 @@ github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI= github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -111,6 +117,7 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA= +google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:CgAqfJo+Xmu0GwA0411Ht3OU3OntXwsGmrmjI8ioGXI= google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a h1:myvhA4is3vrit1a6NZCWBIwN0kNEnX21DJOJX/NvIfI= google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:SUBoKXbI1Efip18FClrQVGjWcyd0QZd8KkvdP34t7ww= google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 h1:AB/lmRny7e2pLhFEYIbl5qkDAUt2h0ZRO4wGPhZf+ik= @@ -123,6 +130,7 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/pkg/kernel/link.go b/pkg/kernel/link.go index ef7b1ff0..68eb7c37 100644 --- a/pkg/kernel/link.go +++ b/pkg/kernel/link.go @@ -2,7 +2,7 @@ // // Copyright (c) 2021-2022 Nordix Foundation. // -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -26,7 +26,6 @@ package kernel import ( "io/fs" - "io/ioutil" "os" "path/filepath" @@ -214,8 +213,8 @@ func searchByPCIAddress(ns netns.NsHandle, _, pciAddress string) (netlink.Link, return errors.Errorf("no net directory under pci device %s: %q", pciAddress, err) } - var fInfos []fs.FileInfo - fInfos, err = ioutil.ReadDir(netDir) + var fInfos []fs.DirEntry + fInfos, err = os.ReadDir(netDir) if err != nil { return errors.Errorf("failed to read net directory %s: %q", netDir, err) } @@ -244,14 +243,14 @@ func findNetDir(basePath string) (string, error) { if _, err := os.Lstat(subDir); err == nil { return subDir, nil } - files, err := ioutil.ReadDir(basePath) + files, err := os.ReadDir(basePath) if err != nil { return "", errors.Wrapf(err, "failed to read directory %s", basePath) } for _, file := range files { if file.IsDir() { subDir = filepath.Join(basePath, file.Name()) - subdirFiles, err := ioutil.ReadDir(subDir) + subdirFiles, err := os.ReadDir(subDir) if err != nil { return "", errors.Wrapf(err, "failed to read subdirectory %s", subDir) } diff --git a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/common.go b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/common.go index db54db0b..fab25474 100644 --- a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/common.go +++ b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/ipaddress/common.go @@ -1,6 +1,6 @@ // Copyright (c) 2021-2022 Nordix Foundation. // -// Copyright (c) 2020-2023 Cisco and/or its affiliates. +// Copyright (c) 2020-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -24,8 +24,8 @@ package ipaddress import ( "context" "fmt" - "io/ioutil" "net" + "os" "time" "github.com/networkservicemesh/api/pkg/api/networkservice" @@ -85,7 +85,7 @@ func create(ctx context.Context, conn *networkservice.Connection, isClient bool) disableIPv6Filename := fmt.Sprintf("/proc/sys/net/ipv6/conf/%s/disable_ipv6", l.Attrs().Name) if err = nshandle.RunIn(forwarderNetNS, targetNetNS, func() error { - return ioutil.WriteFile(disableIPv6Filename, []byte("0"), 0o600) + return os.WriteFile(disableIPv6Filename, []byte("0"), 0o600) }); err != nil { return errors.Wrapf(err, "failed to set %s = 0", disableIPv6Filename) } diff --git a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/nsrtnextid.go b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/nsrtnextid.go index 68711ab3..adcdc0d4 100644 --- a/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/nsrtnextid.go +++ b/pkg/kernel/networkservice/connectioncontextkernel/ipcontext/iprule/nsrtnextid.go @@ -1,5 +1,7 @@ // Copyright (c) 2023 Nordix and/or its affiliates. // +// Copyright (c) 2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +19,14 @@ package iprule // netnsRTableNextID stores Network namespace and Next Routing Table ID +// nolint: unused type netnsRTableNextID struct { ns string nrtid int } // createNetnsRTableNextID returns netnsRTableNextID entry +// nolint: unused func createNetnsRTableNextID(ns string, nrtid int) netnsRTableNextID { return netnsRTableNextID{ ns: ns, diff --git a/pkg/kernel/networkservice/connectioncontextkernel/pinggrouprange/common.go b/pkg/kernel/networkservice/connectioncontextkernel/pinggrouprange/common.go index 93982095..379ebe42 100644 --- a/pkg/kernel/networkservice/connectioncontextkernel/pinggrouprange/common.go +++ b/pkg/kernel/networkservice/connectioncontextkernel/pinggrouprange/common.go @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -18,7 +18,7 @@ package pinggrouprange import ( "context" - "io/ioutil" + "os" "github.com/pkg/errors" "github.com/vishvananda/netns" @@ -51,7 +51,7 @@ func applyPingGroupRange(ctx context.Context, mech *kernel.Mechanism) error { defer func() { _ = targetNetNS.Close() }() if err = nshandle.RunIn(forwarderNetNS, targetNetNS, func() error { - return ioutil.WriteFile(pingGroupRangeFilename, []byte(groupRange), 0o600) + return os.WriteFile(pingGroupRangeFilename, []byte(groupRange), 0o600) }); err != nil { return errors.Wrapf(err, "failed to set %s = %s", pingGroupRangeFilename, groupRange) }