From 3776353f918d1fd8c684b000fc83663ce3d5e732 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 30 Jun 2023 12:10:12 +1100 Subject: [PATCH 1/8] use workflows from .github Signed-off-by: Nikita Skrynnik --- .github/workflows/ci.yaml | 128 +++++--------------------- go.mod | 4 +- go.sum | 8 +- pkg/networkservice/ifconfig/server.go | 12 +-- 4 files changed, 33 insertions(+), 119 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f7f9986..1663449 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,125 +8,43 @@ on: pull_request: jobs: yamllint: - name: yamllint - runs-on: ubuntu-latest - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: yaml-lint - uses: ibiqlik/action-yamllint@v1 - with: - config_file: .yamllint.yml - strict: true + uses: networkservicemesh/.github/.github/workflows/yamllint.yaml@main + with: + config_file: "./.yamllint.yml" shellcheck: - name: shellcheck - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: shellcheck - uses: fkautz/shell-linter@v1.0.1 + uses: networkservicemesh/.github/.github/workflows/shellcheck.yaml@main build: - name: build - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - steps: - - name: Check out code - uses: actions/checkout@v2 - - name: Setup Go - uses: actions/setup-go@v1 - with: - go-version: 1.18.2 - - name: Build - run: go build -race ./... + uses: networkservicemesh/.github/.github/workflows/build-and-test.yaml@main golangci-lint: - name: golangci-lint - runs-on: ubuntu-latest - if: github.repository != 'networkservicemesh/cmd-template' - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Setup Go - uses: actions/setup-go@v1 - with: - go-version: 1.18.2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.51.1 + uses: networkservicemesh/.github/.github/workflows/golangci-lint.yaml@main excludeFmtErrorf: - name: exclude fmt.Errorf - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Exclude fmt.Errorf - run: | - if grep -r --include=*.go --exclude=*.pb.go fmt.Errorf . ; then - echo "Please use errors.Errorf (or errors.New or errors.Wrap or errors.Wrapf) as appropriate rather than fmt.Errorf" - exit 1 - fi + uses: networkservicemesh/.github/.github/workflows/exclude-fmt-errorf.yaml@main restrictNSMDeps: - name: Restrict dependencies on github.com/networkservicemesh/* - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Restrict dependencies on github.com/networkservicemesh/* - env: - ALLOWED_REPOSITORIES: "sdk, api, sdk-vpp, sdk-sriov" - run: | - for i in $(grep github.com/networkservicemesh/ go.mod | grep -v '^module' | sed 's;.*\(github.com\/networkservicemesh\/[^ ]*\).*;\1;g');do - if ! [ "$(echo ${ALLOWED_REPOSITORIES} | grep ${i#github.com/networkservicemesh/})" ]; then - echo Dependency on "${i}" is forbidden - exit 1 - fi; - done + uses: networkservicemesh/.github/.github/workflows/restrict-nsm-deps.yaml@main + with: + allowed_repositories: "sdk, api, sdk-vpp, sdk-sriov, govpp" checkgomod: - name: Check go.mod and go.sum - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.18.2 - - run: go mod tidy - - name: Check for changes - run: | - git diff --name-only --exit-code || ( echo "Run go mod tidy" && false ) + uses: networkservicemesh/.github/.github/workflows/checkgomod.yaml@main gogenerate: - name: Check generated files - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.18.2 - - run: go generate ./... - - name: Check for changes - run: | - git diff --name-only --exit-code || ( echo "Rerun go generate ./... locally and resubmit" && false ) + uses: networkservicemesh/.github/.github/workflows/cmd-gogenerate.yaml@main excludereplace: - name: Exclude Replace in go.mod - runs-on: ubuntu-latest - steps: - - name: Check out the code - uses: actions/checkout@v2 - - name: Exclude replace in go.mod - run: | - grep ^replace go.mod || exit 0 - exit 1 + uses: networkservicemesh/.github/.github/workflows/exclude-replace.yaml@main + + docker-build-and-test: + if: github.repository != 'networkservicemesh/cmd-template' + uses: networkservicemesh/.github/.github/workflows/docker-build-and-test.yaml@main + secrets: + token: ${{ secrets.GITHUB_TOKEN }} - docker: + docker-publish: name: Docker Build & Test runs-on: ubuntu-latest if: github.repository != 'networkservicemesh/cmd-template' @@ -134,11 +52,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v1 with: - go-version: 1.18.2 - - name: Build container - run: docker build . - - name: Run tests - run: docker run --privileged --rm $(docker build -q . --target test) + go-version: 1.20.5 - name: Find merged PR if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: jwalton/gh-find-current-pr@v1 diff --git a/go.mod b/go.mod index a6f07be..00437cf 100644 --- a/go.mod +++ b/go.mod @@ -4,15 +4,15 @@ go 1.18 require ( github.com/antonfisher/nested-logrus-formatter v1.3.1 - github.com/edwarnicke/govpp v0.0.0-20230130211138-14ef5d20b1d0 github.com/edwarnicke/grpcfd v1.1.2 github.com/edwarnicke/vpphelper v0.2.0 github.com/golang/protobuf v1.5.2 github.com/kelseyhightower/envconfig v1.4.0 github.com/networkservicemesh/api v1.7.2-0.20230123083145-4a6c3ec589e1 + github.com/networkservicemesh/govpp v0.0.0-20230626092821-fc47696d971b github.com/networkservicemesh/sdk v0.5.1-0.20230620142740-a8c394e69c4e github.com/networkservicemesh/sdk-sriov v0.0.0-20230629162853-517dec7cabb0 - github.com/networkservicemesh/sdk-vpp v0.0.0-20230626101316-8199d4b43295 + github.com/networkservicemesh/sdk-vpp v0.0.0-20230629190822-0b5241ae37a2 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.0 github.com/spiffe/go-spiffe/v2 v2.0.0 diff --git a/go.sum b/go.sum index 4951316..400c2fa 100644 --- a/go.sum +++ b/go.sum @@ -86,8 +86,6 @@ github.com/edwarnicke/exechelper v1.0.2 h1:dD49Ui2U0FBFxxhalnKw6vLS0P0TkgnXBRvKL 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= github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29/go.mod h1:3m+ZfVq+z0pTLW798jmqnifMsalrVLIKmfXaMFvqSuc= -github.com/edwarnicke/govpp v0.0.0-20230130211138-14ef5d20b1d0 h1:3qXBk0lN7PhPrS/2TVJE30TZA/Ecd6LwkFW4rBxxb2w= -github.com/edwarnicke/govpp v0.0.0-20230130211138-14ef5d20b1d0/go.mod h1:kHDnxA+SSNFeMEHz7xvhub1zvx4mOTRlWWRCay2n5NM= github.com/edwarnicke/grpcfd v1.1.2 h1:2b8kCABQ1+JjSKGDoHadqSW7whCeTXMqtyo6jmB5B8k= github.com/edwarnicke/grpcfd v1.1.2/go.mod h1:rHihB9YvNMixz8rS+ZbwosI2kj65VLkeyYAI2M+/cGA= github.com/edwarnicke/log v1.0.0 h1:T6uRNCmR99GTt/CpRr2Gz8eGW8fm0HMThDNGdNxPaGk= @@ -219,12 +217,14 @@ github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= github.com/networkservicemesh/api v1.7.2-0.20230123083145-4a6c3ec589e1 h1:RxNKksXsXsnDsEo+Cfn43pdPfML024ad//QcdKfgXK4= github.com/networkservicemesh/api v1.7.2-0.20230123083145-4a6c3ec589e1/go.mod h1:hOF2844BSstH1311oDMDgqqXS+kdc77htZNPRKl9mf8= +github.com/networkservicemesh/govpp v0.0.0-20230626092821-fc47696d971b h1:5no/Hfw/UaLGDWN8deavInPomlzkWwxbGXoXNdeY0sc= +github.com/networkservicemesh/govpp v0.0.0-20230626092821-fc47696d971b/go.mod h1:akUChTiTQ93H2iVixGfUS3x0UMKuu1pzmcECwdwj6Rk= github.com/networkservicemesh/sdk v0.5.1-0.20230620142740-a8c394e69c4e h1:Gd9eqXL8E7Pb+wHjdy96/b7goBH52g5uVLQy8kgdxmI= github.com/networkservicemesh/sdk v0.5.1-0.20230620142740-a8c394e69c4e/go.mod h1:hmu0t7IxKa1v7Mj7Y3dQrcpRD0YtEyFE5vJorXRQT2A= github.com/networkservicemesh/sdk-sriov v0.0.0-20230629162853-517dec7cabb0 h1:cJO3sll/o7+Btszr2HwD58aA0wM+KtxpePA6y8FifN0= github.com/networkservicemesh/sdk-sriov v0.0.0-20230629162853-517dec7cabb0/go.mod h1:05zMTOIle9N096LdS9G1Pet8aubYQc5jBlm+kixcT78= -github.com/networkservicemesh/sdk-vpp v0.0.0-20230626101316-8199d4b43295 h1:QSDPB+9RgcfXk4vb4Y8gqhXeH6eXfrbyiUqFMaSGlsg= -github.com/networkservicemesh/sdk-vpp v0.0.0-20230626101316-8199d4b43295/go.mod h1:5P4pS7qAR0r4KiIX/zusAI7iMyAZqGiKYUJ2in+wA24= +github.com/networkservicemesh/sdk-vpp v0.0.0-20230629190822-0b5241ae37a2 h1:fz9tfaDo0Rjl4r0tgkyZPtYhReGSIo5Aa1j2HhY3QRs= +github.com/networkservicemesh/sdk-vpp v0.0.0-20230629190822-0b5241ae37a2/go.mod h1:/A0p5N2WKM/eOu0vjhxoxVHDRtIl5t4rhnfaWu9afh4= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.1.0 h1:e3YP4dN/HYPpGh29X1ZkcxcEICsOls9huyVCRBaxjq8= github.com/onsi/gomega v1.1.0/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= diff --git a/pkg/networkservice/ifconfig/server.go b/pkg/networkservice/ifconfig/server.go index c5a59ee..9421c5d 100644 --- a/pkg/networkservice/ifconfig/server.go +++ b/pkg/networkservice/ifconfig/server.go @@ -25,14 +25,14 @@ import ( "net" "sync" - "github.com/edwarnicke/govpp/binapi/af_packet" - "github.com/edwarnicke/govpp/binapi/fib_types" - interfaces "github.com/edwarnicke/govpp/binapi/interface" - "github.com/edwarnicke/govpp/binapi/interface_types" - "github.com/edwarnicke/govpp/binapi/ip" - "github.com/edwarnicke/govpp/binapi/rdma" "github.com/edwarnicke/vpphelper" "github.com/golang/protobuf/ptypes/empty" + "github.com/networkservicemesh/govpp/binapi/af_packet" + "github.com/networkservicemesh/govpp/binapi/fib_types" + interfaces "github.com/networkservicemesh/govpp/binapi/interface" + "github.com/networkservicemesh/govpp/binapi/interface_types" + "github.com/networkservicemesh/govpp/binapi/ip" + "github.com/networkservicemesh/govpp/binapi/rdma" "github.com/pkg/errors" "github.com/vishvananda/netlink" From 8c2e6a8651d6296b3c1b15280363dd18330a0029 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 30 Jun 2023 12:15:21 +1100 Subject: [PATCH 2/8] fix CI Signed-off-by: Nikita Skrynnik --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1663449..709c05c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,6 +17,8 @@ jobs: build: uses: networkservicemesh/.github/.github/workflows/build-and-test.yaml@main + with: + os: '["ubuntu-latest", "macos-latest", "windows-latest"]' golangci-lint: uses: networkservicemesh/.github/.github/workflows/golangci-lint.yaml@main From 8bc681425ce578ab27f3bc273b71a6a537e80597 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 30 Jun 2023 12:18:43 +1100 Subject: [PATCH 3/8] use only go build on CI Signed-off-by: Nikita Skrynnik --- .github/workflows/ci.yaml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 709c05c..30a92e2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,9 +16,20 @@ jobs: uses: networkservicemesh/.github/.github/workflows/shellcheck.yaml@main build: - uses: networkservicemesh/.github/.github/workflows/build-and-test.yaml@main - with: - os: '["ubuntu-latest", "macos-latest", "windows-latest"]' + name: build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: 1.20.5 + - name: Build + run: go build -race ./... golangci-lint: uses: networkservicemesh/.github/.github/workflows/golangci-lint.yaml@main From dccc2021ae8611fbb726a1e3db8e3a6d35276a25 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 30 Jun 2023 17:02:04 +1100 Subject: [PATCH 4/8] fix linter issues Signed-off-by: Nikita Skrynnik --- .golangci.yml | 12 +++++------- main.go | 3 +-- pkg/networkservice/ifconfig/server.go | 7 +++++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index cdb89b3..120ce48 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -42,13 +42,11 @@ linters-settings: min-len: 2 min-occurrences: 2 depguard: - list-type: blacklist - include-go-root: false - packages: - - errors - packages-with-error-message: - # specify an error message to output when a blacklisted package is used - - errors: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports" + rules: + main: + deny: + - pkg: errors + desc: Please use github.com/pkg/errors instead of errors in go imports misspell: locale: US unparam: diff --git a/main.go b/main.go index 3b43665..ffea4b1 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,6 @@ import ( "crypto/tls" "fmt" "io" - "io/ioutil" "net" "net/url" "os" @@ -335,7 +334,7 @@ func main() { // ******************************************************************************** server := registerGRPCServer(tlsServerConfig, &responderEndpoint) - tmpDir, err := ioutil.TempDir("", config.Name) + tmpDir, err := os.MkdirTemp("", config.Name) if err != nil { logrus.Fatalf("error creating tmpDir %+v", err) } diff --git a/pkg/networkservice/ifconfig/server.go b/pkg/networkservice/ifconfig/server.go index 9421c5d..e9edc1f 100644 --- a/pkg/networkservice/ifconfig/server.go +++ b/pkg/networkservice/ifconfig/server.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-2022 Nordix Foundation. // +// Copyright (c) 2023 Cisco Foundation. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,14 +29,15 @@ import ( "github.com/edwarnicke/vpphelper" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" + "github.com/vishvananda/netlink" + "github.com/networkservicemesh/govpp/binapi/af_packet" "github.com/networkservicemesh/govpp/binapi/fib_types" interfaces "github.com/networkservicemesh/govpp/binapi/interface" "github.com/networkservicemesh/govpp/binapi/interface_types" "github.com/networkservicemesh/govpp/binapi/ip" "github.com/networkservicemesh/govpp/binapi/rdma" - "github.com/pkg/errors" - "github.com/vishvananda/netlink" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel" From 965b37c06d53b69eeb1593917cd7e3a6bbb8a579 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 30 Jun 2023 17:04:36 +1100 Subject: [PATCH 5/8] fix more issues Signed-off-by: Nikita Skrynnik --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index ffea4b1..506e5dc 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,6 @@ -// Copyright (c) 2021-2022 Nordix Foundation. +// Copyright (c) 2021-2023 Nordix Foundation. +// +// Copyright (c) 2023 Cisco Foundation. // // SPDX-License-Identifier: Apache-2.0 // From f5142594e01554d9852a3cf9fe95252e6d8b095d Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 30 Jun 2023 17:10:01 +1100 Subject: [PATCH 6/8] add exclude-rules Signed-off-by: Nikita Skrynnik --- .golangci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 120ce48..a7bbd16 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -169,3 +169,7 @@ issues: linters: - revive text: 'package-comments: should have a package comment' + - path: 'pkg/networkservice/ifconfig/server.go' + linters: + - revive + text: 'Function "closeLinkSubscribe"' From 5ddff37e53753a8febc6fdfb491542cdc62105eb Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 30 Jun 2023 18:14:04 +1100 Subject: [PATCH 7/8] update go Signed-off-by: Nikita Skrynnik --- .golangci.yml | 6 +----- Dockerfile | 2 +- go.mod | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a7bbd16..3dd6e6e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ --- run: # concurrency: 6 - go: "1.19" + go: "1.20" timeout: 2m issues-exit-code: 1 tests: true @@ -108,7 +108,6 @@ linters-settings: - regexpPattern - singleCaseSwitch - sloppyLen - # - sloppyReassign - stringXbytes - switchTrue - typeAssertChain @@ -127,7 +126,6 @@ linters-settings: linters: disable-all: true enable: - # - rowserrcheck - goheader - bodyclose - deadcode @@ -147,7 +145,6 @@ linters: - gosimple - govet - ineffassign - # - lll - misspell - nakedret - revive @@ -157,7 +154,6 @@ linters: - typecheck - unconvert - unparam - # - unused - varcheck - whitespace issues: diff --git a/Dockerfile b/Dockerfile index 2c6ba8b..e83c692 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ARG VPP_VERSION=v23.02-rc0-189-g0359d19f2 FROM ghcr.io/edwarnicke/govpp/vpp:${VPP_VERSION} as go -COPY --from=golang:1.18.2-buster /usr/local/go/ /go +COPY --from=golang:1.20.5-buster /usr/local/go/ /go ENV PATH ${PATH}:/go/bin ENV GO111MODULE=on ENV CGO_ENABLED=0 diff --git a/go.mod b/go.mod index 00437cf..c0de07c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/networkservicemesh/cmd-nse-vlan-vpp -go 1.18 +go 1.20 require ( github.com/antonfisher/nested-logrus-formatter v1.3.1 From 2c18078d05d3bd41d20effbc0d8d97e1cad4f6e3 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 30 Jun 2023 22:21:02 +1100 Subject: [PATCH 8/8] disable linter for function Signed-off-by: Nikita Skrynnik --- pkg/networkservice/ifconfig/server.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/networkservice/ifconfig/server.go b/pkg/networkservice/ifconfig/server.go index e9edc1f..1ad938b 100644 --- a/pkg/networkservice/ifconfig/server.go +++ b/pkg/networkservice/ifconfig/server.go @@ -428,11 +428,10 @@ func (i *ifConfigServer) makeIfOpUp(ctx context.Context, swIfIndex interface_typ return nil } +// nolint: revive func (i *ifConfigServer) closeLinkSubscribe(done chan struct{}, linkUpdateCh chan netlink.LinkUpdate) { close(done) // `linkUpdateCh` should be fully read after the `done` close to prevent goroutine leak in `netlink.LinkSubscribe` - go func() { - for range linkUpdateCh { - } - }() + for range linkUpdateCh { + } }