diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 0f8502a..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,114 +0,0 @@ -name: Default Meshery-App Mesh Workflow -on: - push: - branches: - - "*" - tags: - - "v*" - pull_request: - branches: - - master -jobs: - lint: - name: Check & Review code - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v3 - with: - go-version: 1.19 - - uses: actions/checkout@v3 - - 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 - error_check: - name: Error check - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@master - with: - fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@master - with: - go-version: 1.19 - - run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go get -u github.com/kisielk/errcheck; /home/runner/go/bin/errcheck -tags draft ./... - 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: - install-go: false - version: "2022.1" - vet: - name: Vet - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@master - with: - fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@master - with: - go-version: 1.19 - - run: GOPROXY=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@master - 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 - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@master - with: - fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@master - 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=direct GOSUMDB=off GO111MODULE=on go test ./... diff --git a/.github/workflows/golang-ci-test.yml b/.github/workflows/golang-ci-test.yml new file mode 100644 index 0000000..46d0ac4 --- /dev/null +++ b/.github/workflows/golang-ci-test.yml @@ -0,0 +1,35 @@ +name: Test Meshery-App Mesh Workflow +on: + push: + branches: + - "*" + tags: + - "v*" + pull_request: + branches: + - master +jobs: + tests: + name: Tests + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@main + with: + fetch-depth: 1 + - name: Setup Go + uses: actions/setup-go@main + with: + go-version: 1.19 + check-latest: true + cache: true + - name: Create cluster using KinD + uses: helm/kind-action@v1.1.0 + - run: | + export CURRENTCONTEXT="$(kubectl config current-context)" + echo "current-context:" ${CURRENTCONTEXT} + export KUBECONFIG="${HOME}/.kube/config" + echo "environment-kubeconfig:" ${KUBECONFIG} + GOPROXY=direct GOSUMDB=off GO111MODULE=on go test ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..5e75bcc --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,32 @@ +name: Golangci-Lint CI Workflow +on: + push: + branches: + - "*" + tags: + - "v*" + pull_request: + branches: + - master +permissions: + contents: read + +jobs: + golangci: + strategy: + matrix: + go: [1.19] + os: [ubuntu-latest] + name: golangci-lint + runs-on: ${{ matrix.os }} + steps: + - uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + check-latest: true + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --timeout 5m --verbose \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..c9e76d0 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,144 @@ +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 + goconst: + min-len: 2 + min-occurrences: 2 + 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 + 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 + +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 + - govet + - ineffassign + # - interfacer + - lll + - misspell + # - nakedret + # - nolintlint + # - rowserrcheck + # - scopelint + - staticcheck + # - structcheck + - stylecheck + - typecheck + # - unconvert + # - unparam + - 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 + exclude-rules: + - path: _test\.go + linters: + - gomnd + + # https://github.com/go-critic/go-critic/issues/926 + - linters: + - gocritic + text: "unnecessaryDefer:" + +run: + skip-dirs: + - test/testdata_etc + - internal/cache + - internal/renameio + - internal/robustio + timeout: 5m diff --git a/appmesh/addons.go b/appmesh/addons.go index b26e7be..a1cb940 100644 --- a/appmesh/addons.go +++ b/appmesh/addons.go @@ -13,7 +13,6 @@ import ( ) func (appMesh *AppMesh) installAddon(ns string, del bool, svcName string, patches []string, helmChartURL string, kubeconfigs []string) (string, error) { - st := status.Installing if del { @@ -24,9 +23,8 @@ func (appMesh *AppMesh) installAddon(ns string, del bool, svcName string, patche var errs []error var errMx sync.Mutex - for _, config := range kubeconfigs { - wg.Add(1); + wg.Add(1) go func(config string) { defer wg.Done() kClient, err := kubernetes.New([]byte(config)) diff --git a/appmesh/app_mesh.go b/appmesh/app_mesh.go index 40835a8..e9480a2 100644 --- a/appmesh/app_mesh.go +++ b/appmesh/app_mesh.go @@ -82,7 +82,7 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat operation = "removed" } if err != nil { - summary := fmt.Sprintf("Error while labelling %s", opReq.Namespace) + summary := fmt.Sprintf("Error while labeling %s", opReq.Namespace) hh.streamErr(summary, e, err) return } @@ -107,8 +107,8 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat hh.streamErr(summary, e, err) return } - ee.Summary = fmt.Sprintf("Succesfully %sed %s", operation, opReq.OperationName) - ee.Details = fmt.Sprintf("Succesfully %sed %s from the %s namespace", operation, opReq.OperationName, opReq.Namespace) + ee.Summary = fmt.Sprintf("Successfully %sed %s", operation, opReq.OperationName) + ee.Details = fmt.Sprintf("Successfully %sed %s from the %s namespace", operation, opReq.OperationName, opReq.Namespace) hh.StreamInfo(e) }(appMesh, e) case common.BookInfoOperation, common.HTTPBinOperation, common.ImageHubOperation, common.EmojiVotoOperation: @@ -139,12 +139,11 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat }(appMesh, e) default: appMesh.streamErr("Invalid operation", e, ErrOpInvalid) - } return nil } -//CreateKubeconfigs creates and writes passed kubeconfig onto the filesystem +// CreateKubeconfigs creates and writes passed kubeconfig onto the filesystem func (appMesh *AppMesh) CreateKubeconfigs(kubeconfigs []string) error { var errs = make([]error, 0) for _, kubeconfig := range kubeconfigs { @@ -191,7 +190,6 @@ func (appMesh *AppMesh) CreateKubeconfigs(kubeconfigs []string) error { // ProcessOAM handles the grpc invocation for handling OAM objects func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest) (string, error) { - err := appMesh.CreateKubeconfigs(oamReq.K8sConfigs) if err != nil { return "", err diff --git a/appmesh/error.go b/appmesh/error.go index d98418c..c483f28 100644 --- a/appmesh/error.go +++ b/appmesh/error.go @@ -18,7 +18,7 @@ var ( // ErrSampleAppCode failure ErrSampleAppCode = "appmesh_test_code" // ErrLoadNamespaceToMeshCode represents the error - // which is generated when the namespace could not be labelled and updated + // which is generated when the namespace could not be labeled and updated ErrLoadNamespaceToMeshCode = "appmesh_test_code" // ErrOpInvalidCode failure ErrOpInvalidCode = "appmesh_test_code" @@ -38,7 +38,7 @@ var ( ErrAppMeshCoreComponentFailCode = "replace" // ErrInvalidOAMComponentTypeCode represents error code when - // invalid OAM components are registerd + // invalid OAM components are registered ErrInvalidOAMComponentTypeCode = "replace" // ErrProcessOAMCode represents error code while parsing OAM @@ -67,17 +67,16 @@ var ( // ErrParseOAMComponent represents the error which is // generated during the OAM component parsing - ErrParseOAMComponent = errors.New(ErrParseOAMComponentCode, errors.Alert, []string{"error parsing the component"}, []string{"Error occured while prasing application component in the OAM request made"}, []string{"Invalid OAM component passed in OAM request"}, []string{"Check if your request has vaild OAM components"}) + ErrParseOAMComponent = errors.New(ErrParseOAMComponentCode, errors.Alert, []string{"error parsing the component"}, []string{"Error occurred while prasing application component in the OAM request made"}, []string{"Invalid OAM component passed in OAM request"}, []string{"Check if your request has vaild OAM components"}) // ErrParseOAMConfig represents the error which is // generated during the OAM configuration parsing - ErrParseOAMConfig = errors.New(ErrParseOAMConfigCode, errors.Alert, []string{"error parsing the configuration"}, []string{"Error occured while prasing component config in the OAM request made"}, []string{"Invalid OAM config passed in OAM request"}, []string{"Check if your request has vaild OAM config"}) + ErrParseOAMConfig = errors.New(ErrParseOAMConfigCode, errors.Alert, []string{"error parsing the configuration"}, []string{"Error occurred while prasing component config in the OAM request made"}, []string{"Invalid OAM config passed in OAM request"}, []string{"Check if your request has vaild OAM config"}) ) // ErrInstallAppMesh is the error for install mesh func ErrInstallAppMesh(err error) error { return errors.New(ErrInstallAppMeshCode, errors.Alert, []string{"Error with App Mesh installation"}, []string{err.Error()}, []string{}, []string{}) - } // ErrMeshConfig is the error for mesh config @@ -97,7 +96,7 @@ func ErrStreamEvent(err error) error { // ErrSampleApp is the error for operations on the sample apps func ErrSampleApp(err error, status string) error { - return errors.New(ErrSampleAppCode, errors.Alert, []string{"Error with sample app operation"}, []string{err.Error(), "Error occured while trying to install a sample application using manifests"}, []string{"Invalid kubeclient config", "Invalid manifest"}, []string{"Reconnect your adapter to meshery server to refresh the kubeclient"}) + return errors.New(ErrSampleAppCode, errors.Alert, []string{"Error with sample app operation"}, []string{err.Error(), "Error occurred while trying to install a sample application using manifests"}, []string{"Invalid kubeclient config", "Invalid manifest"}, []string{"Reconnect your adapter to meshery server to refresh the kubeclient"}) } // ErrCustomOperation is the error for custom operations @@ -107,7 +106,7 @@ func ErrCustomOperation(err error) error { // ErrApplyHelmChart is the occurend while applying helm chart func ErrApplyHelmChart(err error) error { - return errors.New(ErrApplyHelmChartCode, errors.Alert, []string{"Error occured while applying Helm Chart"}, []string{err.Error()}, []string{}, []string{}) + return errors.New(ErrApplyHelmChartCode, errors.Alert, []string{"Error occurred while applying Helm Chart"}, []string{err.Error()}, []string{}, []string{}) } // ErrParseAppMeshCoreComponent is the error when app-mesh core component manifest parsing fails diff --git a/appmesh/install.go b/appmesh/install.go index 1561c0c..485fef5 100644 --- a/appmesh/install.go +++ b/appmesh/install.go @@ -67,9 +67,9 @@ func (appMesh *AppMesh) applyHelmChart(del bool, version, namespace string, kube var errMx sync.Mutex for _, config := range kubeconfigs { - wg.Add(1); + wg.Add(1) go func(config string, act mesherykube.HelmChartAction) { - defer wg.Done(); + defer wg.Done() kClient, err := mesherykube.New([]byte(config)) if err != nil { errMx.Lock() @@ -116,8 +116,6 @@ func (appMesh *AppMesh) applyHelmChart(del bool, version, namespace string, kube return } } - - }(config, act) } @@ -149,8 +147,8 @@ func (appMesh *AppMesh) applyManifest(manifest []byte, isDel bool, namespace str err = kClient.ApplyManifest(manifest, mesherykube.ApplyOptions{ Namespace: namespace, - Update: true, - Delete: isDel, + Update: true, + Delete: isDel, }) if err != nil { errMx.Lock() @@ -158,7 +156,6 @@ func (appMesh *AppMesh) applyManifest(manifest []byte, isDel bool, namespace str errMx.Unlock() return } - }(config) } diff --git a/appmesh/oam.go b/appmesh/oam.go index bc6622a..ab4f544 100644 --- a/appmesh/oam.go +++ b/appmesh/oam.go @@ -94,7 +94,6 @@ func (appMesh *AppMesh) HandleApplicationConfiguration(config v1alpha1.Configura } return mergeMsgs(msgs), nil - } func handleNamespaceLabel(appMesh *AppMesh, namespaces []string, isDel bool, kubeconfigs []string) error { diff --git a/appmesh/sample_apps.go b/appmesh/sample_apps.go index 69285f5..5d6f6c8 100644 --- a/appmesh/sample_apps.go +++ b/appmesh/sample_apps.go @@ -20,8 +20,8 @@ import ( "github.com/layer5io/meshery-adapter-library/adapter" "github.com/layer5io/meshery-adapter-library/status" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" mesherykube "github.com/layer5io/meshkit/utils/kubernetes" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (appMesh *AppMesh) installSampleApp(namespace string, del bool, templates []adapter.Template, kubeconfigs []string) (string, error) { @@ -72,7 +72,7 @@ func (appMesh *AppMesh) installSampleApp(namespace string, del bool, templates [ } */ -// LoadNamespaceToMesh enables sidecar injection on by labelling requested +// LoadNamespaceToMesh enables sidecar injection on by labeling requested // namespace func (appMesh *AppMesh) LoadNamespaceToMesh(namespace string, remove bool, kubeconfigs []string) error { var wg sync.WaitGroup @@ -116,8 +116,6 @@ func (appMesh *AppMesh) LoadNamespaceToMesh(namespace string, remove bool, kubec errMx.Unlock() return } - - }(config) } diff --git a/go.sum b/go.sum index bf68871..2f99914 100644 --- a/go.sum +++ b/go.sum @@ -607,8 +607,6 @@ github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3 github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw= github.com/layer5io/meshery-adapter-library v0.6.3 h1:5tsbgrB1q84X2rM1TsRVe3pSBZ8kztjo4lPsHuPBe/Y= github.com/layer5io/meshery-adapter-library v0.6.3/go.mod h1:x9/295iLiWab88uOwjgyZbJTX8aqkxfUlVZhqQKabew= -github.com/layer5io/meshkit v0.6.16 h1:bU9Q4Fl31yPqPjNJkf91wT7bM5LtLh+7P0eQix9f22I= -github.com/layer5io/meshkit v0.6.16/go.mod h1:9ZXmiP0dxRCNlVYgchrOnfFcNrdHVXuayiuN8RRTQ68= github.com/layer5io/meshkit v0.6.17 h1:1AsEo59R8q3xhYSpQWAXkoVkbOpexvLFVzuQYVmKk/E= github.com/layer5io/meshkit v0.6.17/go.mod h1:9ZXmiP0dxRCNlVYgchrOnfFcNrdHVXuayiuN8RRTQ68= github.com/layer5io/service-mesh-performance v0.3.2-0.20210122142912-a94e0658b021/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ= diff --git a/internal/config/config.go b/internal/config/config.go index f3606cc..6db6cab 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,8 +7,8 @@ import ( "github.com/layer5io/meshery-adapter-library/adapter" "github.com/layer5io/meshery-adapter-library/common" "github.com/layer5io/meshery-adapter-library/config" - configprovider "github.com/layer5io/meshkit/config/provider" "github.com/layer5io/meshery-adapter-library/status" + configprovider "github.com/layer5io/meshkit/config/provider" // "github.com/layer5io/meshery-adapter-library" "github.com/layer5io/meshkit/utils" diff --git a/main.go b/main.go index d9c1a42..117672b 100644 --- a/main.go +++ b/main.go @@ -45,7 +45,6 @@ func init() { // main is the entrypoint of the adaptor func main() { - // Initialize Logger instance log, err := logger.New(serviceName, logger.Options{ Format: logger.SyslogLogFormat, @@ -142,7 +141,6 @@ func registerDynamicCapabilities(port string, log logger.Handler) { <-ticker.C registerWorkloads(port, log) } - } func registerWorkloads(port string, log logger.Handler) { log.Info("Registering latest components with Meshery Server")