diff --git a/.golangci.yml b/.golangci.yml index 5e6a2163..a10e822e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ --- run: # concurrency: 6 - go: "1.20" + go: "1.23" timeout: 2m issues-exit-code: 1 tests: true @@ -17,7 +17,8 @@ linters-settings: check-type-assertions: false check-blank: false govet: - check-shadowing: true + enable: + - shadow settings: printf: funcs: @@ -25,19 +26,15 @@ linters-settings: - (github.com/sirupsen/logrus.FieldLogger).Warnf - (github.com/sirupsen/logrus.FieldLogger).Errorf - (github.com/sirupsen/logrus.FieldLogger).Fatalf - golint: - min-confidence: 0.8 goimports: local-prefixes: github.com/networkservicemesh gocyclo: min-complexity: 15 - maligned: - suggest-new: true dupl: threshold: 150 funlen: - Lines: 100 - Statements: 50 + lines: 100 + statements: 50 goconst: min-len: 2 min-occurrences: 2 @@ -57,106 +54,70 @@ linters-settings: simple: true range-loops: true for-loops: false + varnamelen: + ignore-names: + - cl + - m + - u + - wg 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 - rangeExprCopy - rangeValCopy - - regexpMust - regexpPattern - - singleCaseSwitch - - sloppyLen - stringXbytes - - switchTrue - typeAssertChain - - typeSwitchVar - typeUnparen - unlabelStmt - unnamedResult - unnecessaryBlock - - underef - - unlambda - - unslice - - valSwap - weakCond - - wrapperFunc - yodaStyleExpr linters: - disable-all: true - enable: - - goheader - - bodyclose - - deadcode - - depguard - - dogsled - - dupl - - errcheck - - funlen - - gochecknoinits - - goconst - - gocritic - - gocyclo - - gofmt - - goimports - - golint - - gosec - - gosimple - - govet - - ineffassign - - interfacer - - misspell - - nakedret - - scopelint - - staticcheck - - structcheck - - stylecheck - - typecheck - - unconvert - - unparam - - varcheck - - whitespace + enable-all: true + disable: + - execinquery # The linter 'execinquery' is deprecated (since v1.58.0) due to: The repository of the linter has been archived by the owner. + - exportloopref # The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar. + - paralleltest # t.Parallel() adds on test run stage if required + - gci # It conflicts with goimports + + # New linters, that were not enabled or/either were not created on older linter version. + - testpackage + - thelper + - intrange + - exhaustruct + - nlreturn + - nonamedreturns + - wsl + - varnamelen + - ireturn + - gomnd + - containedctx + - mnd + - lll + - gofumpt + - godox issues: exclude-use-default: false max-issues-per-linter: 0 diff --git a/Dockerfile b/Dockerfile index c6edeb04..6f91d201 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.12 as go +FROM golang:1.23 as go ENV GO111MODULE=on ENV CGO_ENABLED=0 ENV GOBIN=/bin diff --git a/go.mod b/go.mod index a3f30ea4..e3db0cab 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/networkservicemesh/cmd-nsmgr -go 1.20 +go 1.23 require ( github.com/antonfisher/nested-logrus-formatter v1.3.1 diff --git a/go.sum b/go.sum index 218bfa7e..2d20519a 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,7 @@ cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go/compute v1.23.1 h1:V97tBoDaZHb6leicZ1G6DLK2BAaZLJ/7+9BB/En3hR0= +cloud.google.com/go/compute v1.23.1/go.mod h1:CqB3xpmPKKt3OJpW2ndFIXnA9A4xAy/F3Xp1ixncW78= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -11,31 +12,39 @@ github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdII github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ= github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= +github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bytecodealliance/wasmtime-go v0.40.0 h1:7cGLQEctJf09JWBl3Ai0eMl1PTrXVAjkAb27+KHfIq0= +github.com/bytecodealliance/wasmtime-go v0.40.0/go.mod h1:q320gUxqyI8yB+ZqRuaJOEnGkAnHh6WtJjMaT2CW4wI= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k= +github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger/v3 v3.2103.2 h1:dpyM5eCJAtQCBcMCZcT4UBZchuTJgCywerHHgmxfxM8= +github.com/dgraph-io/badger/v3 v3.2103.2/go.mod h1:RHo4/GmYcKKh5Lxu63wLEMHJ70Pac2JqZRYGhlyAo2M= github.com/dgraph-io/ristretto v0.1.0 h1:Jv3CGQHp9OjuMBSne1485aDpUkTKEcUqF+jm/LuerPI= +github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/edwarnicke/exechelper v1.0.2 h1:dD49Ui2U0FBFxxhalnKw6vLS0P0TkgnXBRvKL/xmC5w= github.com/edwarnicke/exechelper v1.0.2/go.mod h1:/T271jtNX/ND4De6pa2aRy2+8sNtyCDB1A2pp4M+fUs= github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 h1:4/2wgileNvQB4HfJbq7u4FFLKIfc38a6P0S/51ZGgX8= @@ -49,8 +58,11 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA= +github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/foxcpp/go-mockdns v0.0.0-20210729171921-fb145fc6f897 h1:E52jfcE64UG42SwLmrW0QByONfGynWuzBvm86BoB9z8= +github.com/foxcpp/go-mockdns v0.0.0-20210729171921-fb145fc6f897/go.mod h1:lgRN6+KxQBawyIghpnl5CezHFGS9VLzvtVlwxvzXTQ4= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= @@ -65,11 +77,14 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU= github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 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/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -78,7 +93,9 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS 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/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/flatbuffers v2.0.8+incompatible h1:ivUb1cGomAB101ZM1T0nOiWz9pSrTMoa9+EiY7igmkM= +github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -94,14 +111,18 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9K github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk= +github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 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/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA= +github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= 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.20240820090035-6fad31a9f0aa h1:+/bYBzySJJLgnCSjR8SLHsA+r6PYmAusUbka/W/bw5w= @@ -122,10 +143,13 @@ 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/r3labs/diff v1.1.0 h1:V53xhrbTHrWFWq3gI4b94AjgEJOerO1+1l0xyHOBi8M= +github.com/r3labs/diff v1.1.0/go.mod h1:7WjXasNzi0vJetRcB/RqNl5dlIsmXcTTLmF5IoH6Xig= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= 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/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spiffe/go-spiffe/v2 v2.1.7 h1:VUkM1yIyg/x8X7u1uXqSRVRCdMdfRIEdFBzpqoeASGk= @@ -149,6 +173,7 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs= github.com/zeebo/errs v1.3.0/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= +go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0 h1:PzIubN4/sjByhDRHLviCjJuweBXWFZWhghjg7cS28+M= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0/go.mod h1:Ct6zzQEuGK3WpJs2n4dn+wfJYzd/+hNnxMRTWjGn30M= go.opentelemetry.io/otel v1.20.0 h1:vsb/ggIY+hUjD/zCAQHpzTmndPqv/ml2ArbsbfBYTAc= @@ -175,6 +200,7 @@ go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= @@ -202,6 +228,7 @@ golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY= +golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -209,6 +236,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -250,9 +278,11 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 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= @@ -270,6 +300,7 @@ google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/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.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/internal/config/config.go b/internal/config/config.go index 91fe4f11..7c44f692 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -24,19 +24,19 @@ import ( "time" ) -// Config - configuration for cmd-nsmgr +// Config - configuration for cmd-nsmgr. type Config struct { - Name string `default:"nmgr" desc:"Name of Network service manager"` - ListenOn []url.URL `default:"unix:///var/lib/networkservicemesh/nsm.io.sock" desc:"url to listen on. tcp:// one will be used a public to register NSM." split_words:"true"` - RegistryURL url.URL `default:"tcp://localhost:5001" desc:"A NSE registry url to use" split_words:"true"` - MaxTokenLifetime time.Duration `default:"10m" desc:"maximum lifetime of tokens" split_words:"true"` + Name string `default:"nmgr" desc:"Name of Network service manager"` + ListenOn []url.URL `default:"unix:///var/lib/networkservicemesh/nsm.io.sock" desc:"url to listen on. tcp:// one will be used a public to register NSM." split_words:"true"` + RegistryURL url.URL `default:"tcp://localhost:5001" desc:"A NSE registry url to use" split_words:"true"` + MaxTokenLifetime time.Duration `default:"10m" desc:"maximum lifetime of tokens" split_words:"true"` RegistryServerPolicies []string `default:"etc/nsm/opa/common/.*.rego,etc/nsm/opa/registry/.*.rego,etc/nsm/opa/server/.*.rego" desc:"paths to files and directories that contain registry server policies" split_words:"true"` RegistryClientPolicies []string `default:"etc/nsm/opa/common/.*.rego,etc/nsm/opa/registry/.*.rego,etc/nsm/opa/client/.*.rego" desc:"paths to files and directories that contain registry client policies" split_words:"true"` - LogLevel string `default:"INFO" desc:"Log level" split_words:"true"` - DialTimeout time.Duration `default:"750ms" desc:"Timeout for the dial the next endpoint" split_words:"true"` - ForwarderNetworkServiceName string `default:"forwarder" desc:"the default service name for forwarder discovering" split_words:"true"` - OpenTelemetryEndpoint string `default:"otel-collector.observability.svc.cluster.local:4317" desc:"OpenTelemetry Collector Endpoint" split_words:"true"` - MetricsExportInterval time.Duration `default:"10s" desc:"interval between mertics exports" split_words:"true"` - PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"` - PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"` + LogLevel string `default:"INFO" desc:"Log level" split_words:"true"` + DialTimeout time.Duration `default:"750ms" desc:"Timeout for the dial the next endpoint" split_words:"true"` + ForwarderNetworkServiceName string `default:"forwarder" desc:"the default service name for forwarder discovering" split_words:"true"` + OpenTelemetryEndpoint string `default:"otel-collector.observability.svc.cluster.local:4317" desc:"OpenTelemetry Collector Endpoint" split_words:"true"` + MetricsExportInterval time.Duration `default:"10s" desc:"interval between mertics exports" split_words:"true"` + PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"` + PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"` } diff --git a/internal/imports/gen.go b/internal/imports/gen.go index 1373eebf..d4a8afc7 100644 --- a/internal/imports/gen.go +++ b/internal/imports/gen.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // diff --git a/internal/manager/grpcfd.go b/internal/manager/grpcfd.go index 38b0079c..e03a49a2 100644 --- a/internal/manager/grpcfd.go +++ b/internal/manager/grpcfd.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 Doc.ai and/or its affiliates. // +// Copyright (c) 2022-2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +16,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build !linux +//go:build !linux +// +build !linux package manager diff --git a/internal/manager/manager.go b/internal/manager/manager.go index 7db24705..7081c397 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -2,7 +2,7 @@ // // Copyright (c) 2022 Nordix and/or its affiliates. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -79,14 +79,17 @@ func (m *manager) Stop() { func (m *manager) initSecurity() (err error) { // Get a X509Source logrus.Infof("Obtaining X509 Certificate Source") + m.source, err = workloadapi.NewX509Source(m.ctx) if err != nil { logrus.Fatalf("error getting x509 source: %+v", err) } + m.svid, err = m.source.GetX509SVID() if err != nil { logrus.Fatalf("error getting x509 svid: %+v", err) } + logrus.Infof("SVID: %q", m.svid.ID) return } @@ -105,6 +108,7 @@ func RunNsmgr(ctx context.Context, configuration *config.Config) error { if err := m.initSecurity(); err != nil { m.logger.Errorf("failed to create new spiffe TLS Peer %v", err) + return err } @@ -151,7 +155,7 @@ func RunNsmgr(ctx context.Context, configuration *config.Config) error { mgrOptions = append(mgrOptions, nsmgr.WithRegistry(&configuration.RegistryURL)) } - m.mgr = nsmgr.NewServer(m.ctx, spiffejwt.TokenGeneratorFunc(m.source, m.configuration.MaxTokenLifetime), mgrOptions...) + m.mgr = nsmgr.NewServer(m.ctx, spiffejwt.TokenGeneratorFunc(m.source, m.configuration.MaxTokenLifetime), mgrOptions...) //nolint: contextcheck // If we Listen on Unix socket for local connections we need to be sure folder are exist createListenFolders(configuration) @@ -173,6 +177,7 @@ func RunNsmgr(ctx context.Context, configuration *config.Config) error { m.logger.Infof("Startup completed in %v", time.Since(starttime)) starttime = time.Now() + <-m.ctx.Done() m.logger.Infof("Exit requested. Uptime: %v", time.Since(starttime)) @@ -205,6 +210,7 @@ func (m *manager) startServers(server *grpc.Server) { var wg sync.WaitGroup for i := 0; i < len(m.configuration.ListenOn); i++ { listenURL := &m.configuration.ListenOn[i] + wg.Add(1) go func() { @@ -217,18 +223,22 @@ func (m *manager) startServers(server *grpc.Server) { waitErrChan(m.ctx, errChan, m) }() } + wg.Wait() } func genPublishableURL(listenOn []url.URL, logger log.Logger) *url.URL { u := defaultURL(listenOn) addrs, err := net.InterfaceAddrs() + if err != nil { logger.Warn(err.Error()) return u } + return listenonurl.GetPublicURL(addrs, u) } + func defaultURL(listenOn []url.URL) *url.URL { for i := 0; i < len(listenOn); i++ { u := &listenOn[i] @@ -236,5 +246,6 @@ func defaultURL(listenOn []url.URL) *url.URL { return u } } + return &listenOn[0] } diff --git a/main.go b/main.go index 31eae152..cb794316 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build linux +// +build linux + package main import ( @@ -63,6 +66,7 @@ func main() { if err := envconfig.Usage("nsm", cfg); err != nil { log.FromContext(ctx).Fatal(err) } + if err := envconfig.Process("nsm", cfg); err != nil { log.FromContext(ctx).Fatalf("error processing cfg from env: %+v", err) } @@ -73,6 +77,7 @@ func main() { if err != nil { log.FromContext(ctx).Fatalf("invalid log level %s", cfg.LogLevel) } + logrus.SetLevel(level) log.EnableTracing(true) @@ -82,6 +87,7 @@ func main() { spanExporter := opentelemetry.InitSpanExporter(ctx, collectorAddress) metricExporter := opentelemetry.InitOPTLMetricExporter(ctx, collectorAddress, cfg.MetricsExportInterval) o := opentelemetry.Init(ctx, spanExporter, metricExporter, cfg.Name) + defer func() { if err = o.Close(); err != nil { log.FromContext(ctx).Error(err.Error()) diff --git a/test/client_endpoint_test.go b/test/client_endpoint_test.go index 253eb1b6..105b3a29 100644 --- a/test/client_endpoint_test.go +++ b/test/client_endpoint_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 Doc.ai 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"); @@ -19,7 +21,6 @@ package test import ( "context" - "net/url" "os" "path" @@ -64,9 +65,10 @@ type myEndpouint struct { endpoint.Endpoint } -// NewCrossNSE construct a new Cross connect test NSE +// NewCrossNSE construct a new Cross connect test NSE. func newCrossNSE(ctx context.Context, name string, connectTo *url.URL, tokenGenerator token.GeneratorFunc, clientDialOptions ...grpc.DialOption) endpoint.Endpoint { - var crossNSe = &myEndpouint{} + crossNSe := &myEndpouint{} + nseClient := chain.NewNetworkServiceEndpointRegistryClient( registryclient.NewNetworkServiceEndpointRegistryClient(ctx, registryclient.WithClientURL(connectTo), @@ -97,16 +99,19 @@ func newCrossNSE(ctx context.Context, name string, connectTo *url.URL, tokenGene return crossNSe } -// Check endpoint registration and Client request to it with sendfd/recvfd +// Check endpoint registration and Client request to it with sendfd/recvfd. func (f *NsmgrTestSuite) TestNSmgrEndpointSendFD() { if runtime.GOOS != "linux" { f.T().Skip("not a linux") } + t := f.T() // TODO: check with defer goleak.VerifyNone(t) setup := newSetup(t) setup.Start() + defer setup.Stop() + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() @@ -133,6 +138,7 @@ func (f *NsmgrTestSuite) TestNSmgrEndpointSendFD() { nseRegClient := registryclient.NewNetworkServiceEndpointRegistryClient(ctx, registryclient.WithClientURL(&setup.configuration.ListenOn[0]), registryclient.WithDialOptions(setup.dialOptions()...)) + logrus.Infof("Register network service") ns, nserr := nsRegClient.Register(context.Background(), ®istry.NetworkService{ Name: "my-service", @@ -144,10 +150,10 @@ func (f *NsmgrTestSuite) TestNSmgrEndpointSendFD() { nseReg, err := nseRegClient.Register(context.Background(), ®istry.NetworkServiceEndpoint{ Name: "nse-1", - NetworkServiceNames: []string{ns.Name}, + NetworkServiceNames: []string{ns.GetName()}, Url: nseURL.String(), }) - require.Nil(t, err) + require.NoError(t, err) require.NotNil(t, nseReg) logrus.Infof("Register cross NSE") @@ -161,6 +167,7 @@ func (f *NsmgrTestSuite) TestNSmgrEndpointSendFD() { ) var connection *networkservice.Connection + ctx = clienturlctx.WithClientURL(ctx, &setup.configuration.ListenOn[0]) connection, err = cl.Request(ctx, &networkservice.NetworkServiceRequest{ @@ -173,12 +180,12 @@ func (f *NsmgrTestSuite) TestNSmgrEndpointSendFD() { Context: &networkservice.ConnectionContext{}, }, }) - require.Nil(t, err) + require.NoError(t, err) require.NotNil(t, connection) - require.Equal(t, 4, len(connection.Path.PathSegments)) + require.Len(t, 4, len(connection.GetPath().GetPathSegments())) _, err = cl.Close(ctx, connection) - require.Nil(t, err) + require.NoError(t, err) } func (f *NsmgrTestSuite) registerCrossNSE(ctx context.Context, setup *testSetup, regClient registry.NetworkServiceEndpointRegistryClient, t *testing.T) { @@ -195,5 +202,5 @@ func (f *NsmgrTestSuite) registerCrossNSE(ctx context.Context, setup *testSetup, Name: "cross-nse", NetworkServiceNames: []string{"forwarder"}, }) - require.Nil(t, err) + require.NoError(t, err) } diff --git a/test/mock/registry/server.go b/test/mock/registry/server.go index 027cc9cf..9750f69e 100644 --- a/test/mock/registry/server.go +++ b/test/mock/registry/server.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -45,7 +45,7 @@ import ( "github.com/networkservicemesh/api/pkg/api/registry" ) -// Server mock registry server interface +// Server mock registry server interface. type Server interface { NetworkServiceRegistryServer() registry.NetworkServiceRegistryServer NetworkServiceEndpointRegistryServer() registry.NetworkServiceEndpointRegistryServer @@ -116,6 +116,7 @@ func (s *serverImpl) Start(options ...grpc.ServerOption) error { s.errChan = grpcutils.ListenAndServe(s.ctx, s.listenOn, s.server) logrus.Infof("Mock registry host at: %v", s.GetListenEndpointURI().String()) + go func() { select { case <-s.ctx.Done(): diff --git a/test/nsmgr_registry_test.go b/test/nsmgr_registry_test.go index 52020398..59f6aa9d 100644 --- a/test/nsmgr_registry_test.go +++ b/test/nsmgr_registry_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2021 Doc.ai 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"); @@ -31,6 +33,7 @@ func (f *NsmgrTestSuite) TestNSMgrEndpointRegister() { t := f.T() setup := newSetup(t) setup.Start() + defer setup.Stop() regCtx := peer.NewContext(setup.ctx, @@ -48,7 +51,7 @@ func (f *NsmgrTestSuite) TestNSMgrEndpointRegister() { Name: "my-nse", Url: (&url.URL{Scheme: "unix", Path: path.Join("nsmgr", "endpoint.socket")}).String(), }) - require.Nil(t, err) + require.NoError(t, err) require.NotNil(t, regResponse) - require.NotEmpty(t, regResponse.Url) + require.NotEmpty(t, regResponse.GetUrl()) } diff --git a/test/suite_test.go b/test/suite_test.go index e3082f25..b85e88a1 100644 --- a/test/suite_test.go +++ b/test/suite_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2021 Doc.ai 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"); @@ -19,7 +21,6 @@ package test import ( "context" - "fmt" "os" "path/filepath" "testing" @@ -29,7 +30,6 @@ import ( nested "github.com/antonfisher/nested-logrus-formatter" "github.com/sirupsen/logrus" "github.com/spiffe/go-spiffe/v2/workloadapi" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/networkservicemesh/sdk/pkg/tools/spire" @@ -46,11 +46,12 @@ type NsmgrTestSuite struct { func (f *NsmgrTestSuite) SetupSuite() { logrus.SetFormatter(&nested.Formatter{}) log.EnableTracing(true) + f.ctx, f.cancel = context.WithCancel(context.Background()) // Run spire executable, err := os.Executable() - require.NoError(f.T(), err) + f.Require().NoError(err) reuseSpire := os.Getenv(workloadapi.SocketEnv) != "" if !reuseSpire { @@ -58,14 +59,14 @@ func (f *NsmgrTestSuite) SetupSuite() { spire.WithContext(f.ctx), spire.WithEntry("spiffe://example.org/nsmgr", "unix:path:/bin/nsmgr"), spire.WithEntry("spiffe://example.org/nsmgr.test", "unix:uid:0"), - spire.WithEntry(fmt.Sprintf("spiffe://example.org/%s", filepath.Base(executable)), - fmt.Sprintf("unix:path:%s", executable), - ), + spire.WithEntry("spiffe://example.org/"+filepath.Base(executable), "unix:path:"+executable), ) } } + func (f *NsmgrTestSuite) TearDownSuite() { f.cancel() + if f.spireErrCh != nil { for { _, ok := <-f.spireErrCh @@ -77,7 +78,7 @@ func (f *NsmgrTestSuite) TearDownSuite() { } // In order for 'go test' to run this suite, we need to create -// a normal test function and pass our suite to suite.Run +// a normal test function and pass our suite to suite.Run. func TestRegistryTestSuite(t *testing.T) { suite.Run(t, new(NsmgrTestSuite)) } diff --git a/test/test_utils.go b/test/test_utils.go index e2106dd6..af321a9a 100644 --- a/test/test_utils.go +++ b/test/test_utils.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -58,9 +58,11 @@ import ( func TempFolder() string { baseDir := path.Join(os.TempDir(), "nsm") err := os.MkdirAll(baseDir, os.ModeDir|os.ModePerm) + if err != nil { logrus.Errorf("err: %v", err) } + socketFile, _ := os.MkdirTemp(baseDir, "nsm_test") return socketFile } @@ -84,10 +86,11 @@ func (s *testSetup) init() { s.baseDir = TempFolder() // Configure ListenOnURL - s.configuration.ListenOn = []url.URL{{ - Scheme: "unix", - Path: path.Join(s.baseDir, "nsm.server.sock"), - }, + s.configuration.ListenOn = []url.URL{ + { + Scheme: "unix", + Path: path.Join(s.baseDir, "nsm.server.sock"), + }, } // All TCP public IP as default address @@ -102,10 +105,12 @@ func (s *testSetup) init() { if err != nil { logrus.Fatalf("error getting x509 Source: %+v", err) } + s.SVid, err = s.Source.GetX509SVID() if err != nil { logrus.Fatalf("error getting x509 SVid: %+v", err) } + logrus.Infof("SVID: %q", s.SVid.ID) // Setup registry @@ -113,7 +118,7 @@ func (s *testSetup) init() { &url.URL{Scheme: "tcp", Host: "127.0.0.1:0"}, spiffejwt.TokenGeneratorFunc(s.Source, time.Hour)) - require.Nil(s.t, s.registryServer.Start(grpc.Creds(credentials.NewTLS(tlsconfig.MTLSServerConfig(s.Source, s.Source, tlsconfig.AuthorizeAny()))))) + require.NoError(s.t, s.registryServer.Start(grpc.Creds(credentials.NewTLS(tlsconfig.MTLSServerConfig(s.Source, s.Source, tlsconfig.AuthorizeAny()))))) s.configuration.RegistryURL = *s.registryServer.GetListenEndpointURI() s.configuration.MaxTokenLifetime = time.Hour @@ -124,7 +129,7 @@ func (s *testSetup) Start() { go func() { e := manager.RunNsmgr(s.ctx, s.configuration) - require.Nil(s.t, e) + require.NoError(s.t, e) }() // Check Health is ok @@ -161,16 +166,17 @@ func (s *testSetup) CheckHeal() { healthResponse, err := healthClient.Check(s.ctx, &grpc_health_v1.HealthCheckRequest{ Service: "networkservice.NetworkService", }) - assert.NoError(s.t, err) + require.NoError(s.t, err) assert.NotNil(s.t, healthResponse) - assert.Equal(s.t, grpc_health_v1.HealthCheckResponse_SERVING, healthResponse.Status) + assert.Equal(s.t, grpc_health_v1.HealthCheckResponse_SERVING, healthResponse.GetStatus()) } func (s *testSetup) newClient(ctx context.Context) grpc.ClientConnInterface { clientCtx, clientCancelFunc := context.WithTimeout(ctx, 5*time.Second) defer clientCancelFunc() + grpcCC, err := grpc.DialContext(clientCtx, grpcutils.URLToTarget(&s.configuration.ListenOn[0]), s.dialOptions()...) - require.Nil(s.t, err) + require.NoError(s.t, err) return grpcCC } diff --git a/test/test_utils_test.go b/test/test_utils_test.go index d47a6a26..089b12c0 100644 --- a/test/test_utils_test.go +++ b/test/test_utils_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 Doc.ai 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"); @@ -26,9 +28,11 @@ import ( func TestTempFolder(t *testing.T) { folder := TempFolder() require.NotNil(t, folder) + defer func() { - require.Nil(t, os.Remove(folder)) + require.NoError(t, os.Remove(folder)) }() + info, err := os.Stat(folder) require.False(t, os.IsNotExist(err)) require.True(t, info.IsDir())