From cb01bc62148bf238e9052c86d504cd965504fc2d Mon Sep 17 00:00:00 2001 From: Aisuko Date: Thu, 12 Oct 2023 01:47:35 +0000 Subject: [PATCH] Add fix code error and no more OAM Signed-off-by: GitHub --- .github/workflows/ci.yml | 157 +++++++-------------------------- .golangci.yml | 181 +++++++++++---------------------------- consul/consul.go | 57 ------------ consul/oam/register.go | 8 +- go.mod | 2 - 5 files changed, 81 insertions(+), 324 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19497f17..838879ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,152 +1,55 @@ name: Meshery Consul Default Workflow on: push: - branches: - - '**' - tags: - - 'v*' - paths-ignore: - - 'docs/**' - - '.github/**' + branches: [ master ] # keep it simple and reduce the abuse of CI resources pull_request: - branches: - - master + branches: [ master ] jobs: golangci: name: golangci-lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@master - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.49 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true + version: latest + args: --timeout 5m + codecov: + # golandci-lint need to be run before codecov and succeed + needs: golangci-lint + name: Code Coverage + if: github.repository == 'meshery/meshery-consul' + runs-on: ubuntu-22.04 + steps: + - name: Checkout code + uses: actions/checkout@master + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.19.x + - name: Set up test-env + run: make test-env + - name: Run unit tests + run: go test --short ./... -race -coverprofile=coverage.txt -covermode=atomic + - name: Upload coverage to Codecov + if: github.repository == 'meshery/meshery-consul' + uses: codecov/codecov-action@v3 + with: + files: ./coverage.txt + flags: unittests build: name: Build check runs-on: ubuntu-latest # needs: [lint, error_check, static_check, vet, sec_check, tests] steps: - name: Check out code - uses: actions/checkout@v3 + uses: actions/checkout@master with: fetch-depth: 1 - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: go-version: '1.19' - run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go build . - error_check: - name: Error check - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: 1.19 - - run: GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go install github.com/kisielk/errcheck@latest; /home/runner/go/bin/errcheck -tags draft ./... - error_code_check: - name: Error code utility check - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: 1.19 - - run: | - errWillHave="level=error" - GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go install github.com/layer5io/meshkit/cmd/errorutil; - err=$(/home/runner/go/bin/errorutil -d . update --skip-dirs meshery -i ./helpers -o ./helpers); - echo "ERR: $err"; - - if [[ $err == *"$errWillHave"* ]]; - then - echo "$err"; - return 1; - fi - - static_check: - name: Static check - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: 1.19 - - uses: dominikh/staticcheck-action@v1.2.0 - with: - version: "2022.1" - # - run: GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go get -u honnef.co/go/tools/cmd/staticcheck; /home/runner/go/bin/staticcheck -tags draft -checks all ./... # https://staticcheck.io/docs/checks - vet: - name: Vet - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: 1.19 - - run: GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go vet -tags draft ./... - sec_check: - name: Security check - runs-on: ubuntu-latest - env: - GO111MODULE: on - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Run Gosec Security Scanner - uses: securego/gosec@master - with: - args: -exclude=G301,G304,G107,G101,G110,G204,G409,G305,G302 ./... - tests: - # needs: [lint, error_check, static_check, vet, sec_check] - name: Tests - runs-on: ubuntu-latest - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: 1.19 - - name: Create cluster using KinD - uses: engineerd/setup-kind@v0.5.0 - with: - version: "v0.11.0" - - run: | - export CURRENTCONTEXT="$(kubectl config current-context)" - echo "current-context:" ${CURRENTCONTEXT} - export KUBECONFIG="${HOME}/.kube/config" - echo "environment-kubeconfig:" ${KUBECONFIG} - GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go test -v ./... \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index c9e76d0e..bc6faf2d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,144 +1,63 @@ linters-settings: - depguard: - list-type: blacklist - packages: - # logging is allowed only by logutils.Log, logrus - # is allowed to use only in logutils package - - github.com/sirupsen/logrus - packages-with-error-message: - - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" - dupl: - threshold: 100 - exhaustive: - default-signifies-exhaustive: false - funlen: - lines: 100 - statements: 50 gci: - local-prefixes: github.com/golangci/golangci-lint + enabled: true + max-len: 120 + line-length: 120 goconst: - min-len: 2 - min-occurrences: 2 + enabled: true gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - disabled-checks: - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - ifElseChain - - octalLiteral - - whyNoLint - - wrapperFunc - gocyclo: - min-complexity: 15 - goimports: - local-prefixes: github.com/golangci/golangci-lint - golint: - min-confidence: 0 - gomnd: - settings: - mnd: - # don't include the "operation" and "assign" - checks: argument,case,condition,return - gosec: - settings: - exclude: -G204 + enabled: true + disable: + - parallelize + - nesting + - hugeParam + - hugeStruct + - nestParam + - prealloc govet: - check-shadowing: false - settings: - printf: - funcs: - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - lll: - line-length: 950 - maligned: - suggest-new: true - misspell: - locale: US - nolintlint: - allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) - allow-unused: false # report any unused nolint directives - require-explanation: false # don't require an explanation for nolint directives - require-specific: false # don't require nolint directives to be specific about which linter is being skipped + enabled: true + check-shadowing: true + tests: true + golint: + enabled: true + min-confidence: 0.8 + unused: + enabled: true + check-exported: true + check-packages: true + check-generated: true + tests: true + allow-unused-type-export: true + cyclop: + enabled: true + average-strictness: 7 + scopelint: + enabled: true + tests: true + +# Configuration for golangci-lint that is suitable for a Kubernetes operator project built with Golang linters: - # please, do not use `enable-all`: it's deprecated and will be removed soon. - # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint - # https://golangci-lint.run/usage/linters/ - disable-all: true - enable: - # TODO: consider continuously if more should be enabled. - # Can also be useful to run with more strict settings before commit locally, i.e. to test for TODOs (godox) - # - bodyclose - # - deadcode - - dogsled - # - dupl - - errcheck - # - exhaustive - # - funlen - # - goconst - # - gocritic - # - gocyclo - - gofmt - - goimports - # - golint - - gomodguard - - gosec - # - gomnd - # - goprintffuncname - - gosimple + enable-all: false + disable-all: false + linters: + - gci + - goconst + - gocritic - govet - - ineffassign - # - interfacer - - lll - - misspell - # - nakedret - # - nolintlint - # - rowserrcheck - # - scopelint - - staticcheck - # - structcheck - - stylecheck - - typecheck - # - unconvert - # - unparam + - golint - unused - # - varcheck - - whitespace - - asciicheck -# - gochecknoglobals -# - gocognit -# - godot -# - godox -# - goerr113 -# - maligned -# - nestif -# - prealloc -# - testpackage -# - wsl - -issues: - # Excluding configuration per-path, per-linter, per-text and per-source + - cyclop + - scopelint exclude-rules: - - path: _test\.go - linters: - - gomnd - - # https://github.com/go-critic/go-critic/issues/926 - - linters: - - gocritic - text: "unnecessaryDefer:" + - testpackage run: + enable-cache: true skip-dirs: - - test/testdata_etc - - internal/cache - - internal/renameio - - internal/robustio - timeout: 5m + - vendor + - bundle + - config + - hack + - helpers + - img \ No newline at end of file diff --git a/consul/consul.go b/consul/consul.go index 4470e1f8..6f075db5 100644 --- a/consul/consul.go +++ b/consul/consul.go @@ -15,14 +15,10 @@ package consul import ( - "context" - "github.com/layer5io/meshery-adapter-library/adapter" "github.com/layer5io/meshery-adapter-library/config" - "github.com/layer5io/meshery-consul/consul/oam" "github.com/layer5io/meshkit/logger" "github.com/layer5io/meshkit/models" - "github.com/layer5io/meshkit/models/oam/core/v1alpha1" "github.com/layer5io/meshkit/utils/events" "gopkg.in/yaml.v2" ) @@ -81,56 +77,3 @@ func (h *Consul) CreateKubeconfigs(kubeconfigs []string) error { } return mergeErrors(errs) } - -// ProcessOAM will handles the grpc invocation for handling OAM objects -func (h *Consul) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest) (string, error) { - err := h.CreateKubeconfigs(oamReq.K8sConfigs) - if err != nil { - return "", err - } - kubeconfigs := oamReq.K8sConfigs - var comps []v1alpha1.Component - for _, acomp := range oamReq.OamComps { - comp, err := oam.ParseApplicationComponent(acomp) - if err != nil { - h.Log.Error(ErrParseOAMComponent) - continue - } - - comps = append(comps, comp) - } - - config, err := oam.ParseApplicationConfiguration(oamReq.OamConfig) - if err != nil { - h.Log.Error(ErrParseOAMConfig) - } - // If operation is delete then first HandleConfiguration and then handle the deployment - if oamReq.DeleteOp { - // Process configuration - msg2, err := h.HandleApplicationConfiguration(config, oamReq.DeleteOp, kubeconfigs) - if err != nil { - return msg2, ErrProcessOAM(err) - } - - // Process components - msg1, err := h.HandleComponents(comps, oamReq.DeleteOp, kubeconfigs) - if err != nil { - return msg1 + "\n" + msg2, ErrProcessOAM(err) - } - - return msg1 + "\n" + msg2, nil - } - // Process components - msg1, err := h.HandleComponents(comps, oamReq.DeleteOp, kubeconfigs) - if err != nil { - return msg1, ErrProcessOAM(err) - } - - // Process configuration - msg2, err := h.HandleApplicationConfiguration(config, oamReq.DeleteOp, kubeconfigs) - if err != nil { - return msg1 + "\n" + msg2, ErrProcessOAM(err) - } - - return msg1 + "\n" + msg2, nil -} diff --git a/consul/oam/register.go b/consul/oam/register.go index adf56a8e..2d46dac7 100644 --- a/consul/oam/register.go +++ b/consul/oam/register.go @@ -16,14 +16,8 @@ var ( MeshmodelComponents = filepath.Join(basePath, "templates", "meshmodel", "components") ) -type schemaDefinitionPathSet struct { - oamDefinitionPath string - jsonSchemaPath string - name string -} - var AvailableVersions = map[string]bool{} -var pathSets []schemaDefinitionPathSet + var availableVersionGlobalMutex sync.Mutex type meshmodelDefinitionPathSet struct { diff --git a/go.mod b/go.mod index aeda76ee..38858ad5 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,11 @@ module github.com/layer5io/meshery-consul go 1.19 replace ( - //github.com/docker/docker => github.com/moby/moby v17.12.0-ce-rc1.0.20200618181300-9dc6525e6118+incompatible github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334 github.com/spf13/afero => github.com/spf13/afero v1.5.1 // Until viper bug is resolved #1161 go.opentelemetry.io/otel => go.opentelemetry.io/otel v0.11.0 go.opentelemetry.io/otel/sdk => go.opentelemetry.io/otel/sdk v0.11.0 gopkg.in/ini.v1 => github.com/go-ini/ini v1.62.0 -//golang.org/x/sys => golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 ) require (