Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor-lint #188

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,18 @@ 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

# 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: 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.
Expand Down
73 changes: 73 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,79 @@
linters:
# Enable specific linter
enable:
# https://golangci-lint.run/usage/linters/#enabled-by-default
# - errcheck
# - gosimple
# - govet
# - ineffassign
# - staticcheck
# - unused
- gocritic
- gofmt
- goimports
- gosec
- revive
- typecheck
- bodyclose
linters-settings:
gosec:
excludes:
- G115
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,6 @@ catalog-push: ## Push a catalog image.

clean:
rm -r $(TESTBIN_DIR)

lint:
golangci-lint run
10 changes: 10 additions & 0 deletions controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Loading