From 122e19deb0653dae6843781f2d25a525001f246c Mon Sep 17 00:00:00 2001 From: "Victor M." Date: Thu, 5 Sep 2024 12:48:35 +0200 Subject: [PATCH 1/4] refactor: move all golangci-lint options from GHA to config file --- .github/workflows/lint.yml | 15 ++------- .golangci.yml | 69 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b0639690..009616ee 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,21 +24,10 @@ jobs: name: Checkout frontend-operator - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: latest - - args: > - --enable=errcheck,gocritic,gofmt,goimports,gosec,gosimple,govet,ineffassign,revive,staticcheck,typecheck,unused,bodyclose - --fix=false - --max-same-issues=20 - --out-${NO_FUTURE}format=colored-line-number - --print-issued-lines=true - --print-linter-name=true - --sort-results=true - --timeout=5m0s - --uniq-by-line=false # Optional: working directory, useful for monorepos # working-directory: somedir @@ -46,7 +35,7 @@ jobs: # args: --issues-exit-code=0 # Optional: show only new issues if it's a pull request. The default value is `false`. - only-new-issues: false +# only-new-issues: false # Optional: if set to true then the all caching functionality will be complete disabled, # takes precedence over all other caching options. diff --git a/.golangci.yml b/.golangci.yml index 91bd5443..c40c9d96 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,75 @@ +linters: + # Enable specific linter + # https://golangci-lint.run/usage/linters/#enabled-by-default + enable: + - errcheck + - gocritic + - gofmt + - goimports + - gosec + - gosimple + - govet + - ineffassign + - revive + - staticcheck + - typecheck + - unused + - bodyclose issues: exclude-rules: - path: api/v1alpha1/groupversion_info.go linters: - gofmt - goimports + # Fix found issues (if it's supported by the linter). + # Default: false + # fix: true + + # Maximum count of issues with the same text. + # Set to 0 to disable. + # Default: 3 + max-same-issues: 20 + +output: +# The formats used to render issues. +# Formats: +# - `colored-line-number` +# - `line-number` +# - `json` +# - `colored-tab` +# - `tab` +# - `html` +# - `checkstyle` +# - `code-climate` +# - `junit-xml` +# - `github-actions` +# - `teamcity` +# - `sarif` +# Output path can be either `stdout`, `stderr` or path to the file to write to. +# +# For the CLI flag (`--out-format`), multiple formats can be specified by separating them by comma. +# The output can be specified for each of them by separating format name and path by colon symbol. +# Example: "--out-format=checkstyle:report.xml,json:stdout,colored-line-number" +# The CLI flag (`--out-format`) override the configuration file. +# +# Default: +# formats: +# - format: colored-line-number +# path: stdout +# Print lines of code with issue. +# Default: true +# print-issued-lines: false +# Print linter name in the end of issue text. +# Default: true +# print-linter-name: false +# Sort results by the order defined in `sort-order`. +# Default: false + sort-results: true +# Make issues output unique by line. +# Default: true + uniq-by-line: false + +run: + # Timeout for analysis, e.g. 30s, 5m. + # Default: 1m + timeout: 5m From e10c1334bb5be5bca8fcecb775d959589671d902 Mon Sep 17 00:00:00 2001 From: "Victor M." Date: Thu, 5 Sep 2024 15:20:07 +0200 Subject: [PATCH 2/4] feat: add a lint target --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 9650ba2a..bccb17df 100644 --- a/Makefile +++ b/Makefile @@ -250,3 +250,6 @@ catalog-push: ## Push a catalog image. clean: rm -r $(TESTBIN_DIR) + +lint: + golangci-lint run From edc744ef79ed5b63cc7c2340b6c1b65f2b0ea783 Mon Sep 17 00:00:00 2001 From: "Victor M." Date: Thu, 5 Sep 2024 15:22:07 +0200 Subject: [PATCH 3/4] fix: handle int overflow --- .golangci.yml | 14 +++++++------- controllers/status.go | 10 ++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c40c9d96..5d81b75f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,19 +1,19 @@ linters: # Enable specific linter - # https://golangci-lint.run/usage/linters/#enabled-by-default enable: - - errcheck +# https://golangci-lint.run/usage/linters/#enabled-by-default +# - errcheck +# - gosimple +# - govet +# - ineffassign +# - staticcheck +# - unused - gocritic - gofmt - goimports - gosec - - gosimple - - govet - - ineffassign - revive - - staticcheck - typecheck - - unused - bodyclose issues: exclude-rules: diff --git a/controllers/status.go b/controllers/status.go index 9c0c9fa8..69087bc3 100644 --- a/controllers/status.go +++ b/controllers/status.go @@ -2,6 +2,7 @@ package controllers import ( "context" + "math" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/errors" crd "github.com/RedHatInsights/frontend-operator/api/v1alpha1" @@ -53,6 +54,7 @@ func SetFrontendConditions(ctx context.Context, client client.Client, o *crd.Fro condition.Type = crd.FrontendsReady condition.LastTransitionTime = metav1.Now() + //FIXME: condition is always false if err != nil { condition.Message += err.Error() condition.Reason = "Error" @@ -112,7 +114,15 @@ func GetFrontendFigures(ctx context.Context, client client.Client, o *crd.Fronte return crd.FrontendDeployments{}, "", errors.Wrap("count resources: ", err) } + if results.Managed < math.MinInt32 || results.Managed > math.MaxInt32 { + return crd.FrontendDeployments{}, "", errors.NewClowderError("value out of range for int32") + } deploymentStats.ManagedDeployments = int32(results.Managed) + + if results.Ready < math.MinInt32 || results.Ready > math.MaxInt32 { + return crd.FrontendDeployments{}, "", errors.NewClowderError("value out of range for int32") + } deploymentStats.ReadyDeployments = int32(results.Ready) + return deploymentStats, results.BrokenMessage, nil } From a2864240fe01a6be54d2ed40568e7b2555ea0279 Mon Sep 17 00:00:00 2001 From: "Victor M." Date: Thu, 12 Sep 2024 19:27:26 +0200 Subject: [PATCH 4/4] chore: disable G115 --- .golangci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 5d81b75f..3ff06e9f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,6 +15,10 @@ linters: - revive - typecheck - bodyclose +linters-settings: + gosec: + excludes: + - G115 issues: exclude-rules: - path: api/v1alpha1/groupversion_info.go