diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..acd51d25 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,112 @@ +--- +name: ci +on: pull_request +jobs: + yamllint: + name: yamllint + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - name: Setup Python + uses: actions/setup-python@v1 + - name: Install yamllint + run: pip install --user yamllint + - name: Run yamllint + run: ~/.local/bin/yamllint -c .yamllint.yml --strict . + shellcheck: + name: shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: shellcheck + uses: reviewdog/action-shellcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-check + build: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: + go-version: 1.13 + - run: | + go build -race ./... + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: + go-version: 1.13 + - name: Install gotestsum + run: go get gotest.tools/gotestsum@v0.4.0 + - name: Run tests + run: | + eval $(go env) + mkdir -p ~/junit/ + ${GOPATH}/bin/gotestsum --junitfile ~/junit/unit-tests.xml -- -race -short $(go list ./...) + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - name: golangci-lint + uses: reviewdog/action-golangci-lint@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-check + + excludeFmtErrorf: + name: exclude fmt.Errorf + runs-on: ubuntu-latest + steps: + - name: Exclude fmt.Errorf + run: | + if grep -r --include=*.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 + restrictNSMDeps: + name: Restrict dependencies on github.com/networkservicemesh/* + runs-on: ubuntu-latest + steps: + - name: Restrict dependencies on github.com/networkservicemesh/* + run: | + for i in $(grep github.com/networkservicemesh/ go.mod | gsed 's;.*\(github.com\/networkservicemesh\/[a-zA-z\/]*\).*;\1;g' | sort -u);do + if [ "${i}" != "github.com/networkservicemesh/sdk" ] && [ "${i}" != "github.com/networkservicemesh/networkservicemesh/controlplane/api" ]; then + echo Dependency on "${i}" is forbidden + exit 1 + fi + done + checkgomod: + name: check go.mod and go.sum + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: + go-version: 1.13 + - run: go mod tidy + - name: Check for changes in go.mod or go.sum + run: | + git diff --name-only --exit-code go.mod || ( echo "Run go tidy" && false ) + git diff --name-only --exit-code go.sum || ( echo "Run go tidy" && false ) + license: + name: license header check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: + go-version: 1.13 + - name: Install go-header + run: 'go get github.com/denis-tingajkin/go-header@v0.2.1' + - name: Run go-header + run: | + eval $(go env) + ${GOPATH}/bin/go-header diff --git a/.github/workflows/pr-for-updates.yaml b/.github/workflows/pr-for-updates.yaml new file mode 100644 index 00000000..f8f10562 --- /dev/null +++ b/.github/workflows/pr-for-updates.yaml @@ -0,0 +1,18 @@ + +--- +name: Pull Request on update/* Branch Push +on: + push: + branches: + - update/* +jobs: + auto-pull-request: + name: Pull Request on update/* Branch Push + runs-on: ubuntu-latest + steps: + - name: pull-request-action + uses: vsoch/pull-request-action@master + env: + GITHUB_TOKEN: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} + BRANCH_PREFIX: "update/" + PULL_REQUEST_BRANCH: "master" diff --git a/.go-header.yaml b/.go-header.yaml new file mode 100644 index 00000000..aaccf204 --- /dev/null +++ b/.go-header.yaml @@ -0,0 +1,16 @@ +--- +year: 2020 +goroutine-count: 6 +scope: + policy: "diff" + master-branch: "origin/master" +rules: + - template-path: ".license/template.txt" + paths: + - ".*[.]go$" + exclude-paths: + - ".*[.]pb" +custom-patterns: + - name: NSM COPYRIGHT HOLDERS + pattern: "Copyright (c) {YEAR} {COPYRIGHT HOLDER}" + separator: "\n//\n// " diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..5a9bcf87 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,158 @@ +--- +run: + # concurrency: 6 + timeout: 1m + issues-exit-code: 1 + tests: true +linters-settings: + errcheck: + check-type-assertions: false + check-blank: false + govet: + check-shadowing: true + settings: + printf: + funcs: + - (github.com/sirupsen/logrus.FieldLogger).Infof + - (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/sdk-kernel/ + gocyclo: + min-complexity: 15 + maligned: + suggest-new: true + dupl: + threshold: 150 + goconst: + 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" + misspell: + locale: US + unparam: + check-exported: false + nakedret: + max-func-lines: 30 + prealloc: + simple: true + range-loops: true + 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 + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - funlen + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - interfacer + # - lll + - misspell + - nakedret + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + # - unused + - varcheck + - whitespace +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/.license/README.md b/.license/README.md new file mode 100644 index 00000000..74cd3183 --- /dev/null +++ b/.license/README.md @@ -0,0 +1,48 @@ +## Copyright headers for source code +This folder contains the copyright templates for source files of NSM project. + +Below is an example of valid copyright header for `.go` files: +``` +// Copyright (c) 2020 Doc.ai and/or its affiliates. +// +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +``` +Note you can use your company name instead of `Cisco and/or its affiliates`. +Also, source code files can have multi copyright holders, for example: +``` +// Copyright (c) 2020 Doc.ai and/or its affiliates. +// +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// Copyright (c) 2020 Red Hat Inc. and/or its affiliates. +// +// Copyright (c) 2020 VMware, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +``` diff --git a/.license/boilerplate.txt b/.license/boilerplate.txt new file mode 100644 index 00000000..12e47757 --- /dev/null +++ b/.license/boilerplate.txt @@ -0,0 +1,19 @@ +// Copyright (c) 2020 Doc.ai and/or its affiliates. +// +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// Copyright (c) 2020 VMware, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. \ No newline at end of file diff --git a/.license/template.txt b/.license/template.txt new file mode 100644 index 00000000..7cbffa8a --- /dev/null +++ b/.license/template.txt @@ -0,0 +1,15 @@ +// {NSM COPYRIGHT HOLDERS} +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. \ No newline at end of file diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 00000000..d4a3b49d --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,15 @@ +--- +extends: default + +yaml-files: + - '*.yaml' + - '*.yml' + +rules: + truthy: disable + # 80 chars should be enough, but don't fail if a line is longer + line-length: disable + comments-indentation: + ignore: .circleci/config.yml + +ignore: scripts/aws/aws-k8s-cni.yaml diff --git a/README.md b/README.md index 69d31ae3..8c0f1365 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# sdk-kernel \ No newline at end of file +# sdk-kernel diff --git a/cmd/kernel-forwarder.go b/cmd/kernel-forwarder.go new file mode 100644 index 00000000..da67ad3c --- /dev/null +++ b/cmd/kernel-forwarder.go @@ -0,0 +1,55 @@ +// Copyright 2019 VMware, Inc. +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + + "github.com/networkservicemesh/networkservicemesh/pkg/tools/jaeger" + + "github.com/sirupsen/logrus" + + "github.com/networkservicemesh/networkservicemesh/pkg/tools/spanhelper" + + "github.com/networkservicemesh/networkservicemesh/pkg/probes" + + "github.com/networkservicemesh/networkservicemesh/forwarder/kernel-forwarder/pkg/kernelforwarder" + "github.com/networkservicemesh/networkservicemesh/forwarder/pkg/common" + "github.com/networkservicemesh/networkservicemesh/pkg/tools" +) + +func main() { + // Capture signals to cleanup before exiting + logrus.Info("Starting the Kernel-based forwarding plane!") + + closer := jaeger.InitJaeger("kernel-forwarder") + defer func() { _ = closer.Close() }() + + span := spanhelper.FromContext(context.Background(), "Start.KernelForwarder.Forwarder") + defer span.Finish() + c := tools.NewOSSignalChannel() + forwarderGoals := &common.ForwarderProbeGoals{} + forwarderProbes := probes.New("Kernel-based forwarding plane liveness/readiness healthcheck", forwarderGoals) + forwarderProbes.BeginHealthCheck() + + plane := kernelforwarder.CreateKernelForwarder() + + registration := common.CreateForwarder(span.Context(), plane, forwarderGoals) + + <-c + logrus.Info("Closing Forwarder Registration") + registration.Close() +} diff --git a/code-of-conduct.md b/code-of-conduct.md new file mode 100644 index 00000000..a64950c7 --- /dev/null +++ b/code-of-conduct.md @@ -0,0 +1,3 @@ +# Code of Conduct + +We follow the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..8a925f50 --- /dev/null +++ b/go.mod @@ -0,0 +1,6 @@ +module github.com/networkservicemesh/sdk-kernel + +go 1.13 + +require ( +)