Skip to content

Commit 33a36ca

Browse files
zmotsoSergK
authored andcommitted
chore: Upgrade golangci-lint from v1.64.7 to v2.8.0 (#257)
1 parent b8eb490 commit 33a36ca

67 files changed

Lines changed: 977 additions & 378 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yaml

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,52 @@
1-
version: "1"
1+
version: "2"
22
run:
3-
timeout: 5m
43
allow-parallel-runners: true
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
19-
- path: ".*_test\\.go$"
20-
linters:
21-
- errcheck
224
linters:
23-
disable-all: true
5+
default: none
246
enable:
257
- copyloopvar
8+
- dupl
269
- errcheck
27-
- gci
2810
- ginkgolinter
2911
- goconst
3012
- gocyclo
31-
- gofmt
32-
- goimports
33-
- gosimple
3413
- govet
3514
- ineffassign
15+
- lll
3616
- misspell
3717
- nakedret
3818
- prealloc
3919
- revive
4020
- staticcheck
41-
- typecheck
4221
- unconvert
4322
- unparam
4423
- unused
45-
- wsl
46-
47-
linters-settings:
48-
revive:
24+
- wsl_v5
25+
settings:
26+
revive:
27+
rules:
28+
- name: comment-spacings
29+
- name: import-shadowing
30+
exclusions:
31+
generated: lax
4932
rules:
50-
- name: comment-spacings
51-
gci:
52-
# Section configuration to compare against.
53-
# Section names are case-insensitive and may contain parameters in ().
54-
# The default order of sections is `standard > default > custom > blank > dot`,
55-
# If `custom-order` is `true`, it follows the order of `sections` option.
56-
# Default: ["standard", "default"]
57-
sections:
58-
- standard # Standard section: captures all standard packages.
59-
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
60-
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
61-
- default # Default section: contains all imports that could not be matched to another section type.
62-
- prefix(github.com/epam) # Custom section: groups all imports with the specified Prefix.
63-
- prefix(github.com/epam/edp-codebase-operator) # Custom section: groups all imports with the specified Prefix.
64-
65-
# Skip generated files.
66-
skip-generated: true
67-
68-
# Enable custom order of sections.
69-
# If `true`, make the section order the same as the order of `sections`.
70-
# Default: false
71-
custom-order: true
33+
- linters:
34+
- lll
35+
path: api/*
36+
- linters:
37+
- lll
38+
source: "\\+kubebuilder"
39+
paths:
40+
- third_party$
41+
- builtin$
42+
- examples$
43+
formatters:
44+
enable:
45+
- gofmt
46+
- goimports
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- third_party$
51+
- builtin$
52+
- examples$

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ vet: ## Run go vet
9999

100100
.PHONY: lint
101101
lint: golangci-lint ## Run go lint
102-
${GOLANGCI_LINT} run -v -c .golangci.yaml ./...
102+
${GOLANGCI_LINT} run -v ./...
103103

104-
.PHONY: lint
104+
.PHONY: lint-fix
105105
lint-fix: golangci-lint ## Run go lint fix
106-
${GOLANGCI_LINT} run -v -c .golangci.yaml ./... --fix
106+
${GOLANGCI_LINT} run -v ./... --fix
107107

108108
.PHONY: build
109109
build: ## build operator's binary
@@ -133,7 +133,7 @@ helm-docs: helmdocs ## generate helm docs
133133
GOLANGCI_LINT = ${CURRENT_DIR}/bin/golangci-lint
134134
.PHONY: golangci-lint
135135
golangci-lint: ## Download golangci-lint locally if necessary.
136-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
136+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
137137

138138
.PHONY: install
139139
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
@@ -146,7 +146,7 @@ KUSTOMIZE_VERSION ?= v5.6.0
146146
CONTROLLER_TOOLS_VERSION ?= v0.18.0
147147
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
148148
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
149-
GOLANGCI_LINT_VERSION ?= v1.64.7
149+
GOLANGCI_LINT_VERSION ?= v2.8.0
150150
MOCKERY_VERSION ?= v3.6.2
151151
HELMDOCS_VERSION ?= v1.14.2
152152
GITCHGLOG_VERSION ?= v0.15.4

controllers/cdstagedeploy/chain/process_trigger_template.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ func NewProcessTriggerTemplate(
3535
}
3636

3737
func (h *ProcessTriggerTemplate) ServeRequest(ctx context.Context, stageDeploy *codebaseApi.CDStageDeploy) error {
38-
log := ctrl.LoggerFrom(ctx).WithValues("stage", stageDeploy.Spec.Stage, "pipeline", stageDeploy.Spec.Pipeline, "status", stageDeploy.Status.Status)
38+
log := ctrl.LoggerFrom(ctx).WithValues(
39+
"stage",
40+
stageDeploy.Spec.Stage,
41+
"pipeline",
42+
stageDeploy.Spec.Pipeline,
43+
"status",
44+
stageDeploy.Status.Status,
45+
)
3946

4047
if skipPipelineRunCreation(stageDeploy) {
4148
log.Info("Skip processing TriggerTemplate for auto-deploy.")
@@ -45,10 +52,19 @@ func (h *ProcessTriggerTemplate) ServeRequest(ctx context.Context, stageDeploy *
4552

4653
log.Info("Start processing TriggerTemplate for auto-deploy.")
4754

48-
pipeline, stage, rawResource, err := getResourcesForPipelineRun(ctx, stageDeploy, h.k8sClient, h.triggerTemplateManager)
55+
pipeline, stage, rawResource, err := getResourcesForPipelineRun(
56+
ctx,
57+
stageDeploy,
58+
h.k8sClient,
59+
h.triggerTemplateManager,
60+
)
4961
if err != nil {
5062
if errors.Is(err, tektoncd.ErrEmptyTriggerTemplateResources) {
51-
log.Info("No resource templates found in the trigger template. Skip processing.", "triggertemplate", stage.Spec.TriggerTemplate)
63+
log.Info(
64+
"No resource templates found in the trigger template. Skip processing.",
65+
"triggertemplate",
66+
stage.Spec.TriggerTemplate,
67+
)
5268

5369
stageDeploy.Status.Status = codebaseApi.CDStageDeployStatusCompleted
5470

@@ -150,7 +166,11 @@ func getResourcesForPipelineRun(
150166
return pipeline, nil, nil, fmt.Errorf("failed to get Stage: %w", err)
151167
}
152168

153-
rawResource, err := triggerTemplateManager.GetRawResourceFromTriggerTemplate(ctx, stage.Spec.TriggerTemplate, stageDeploy.Namespace)
169+
rawResource, err := triggerTemplateManager.GetRawResourceFromTriggerTemplate(
170+
ctx,
171+
stage.Spec.TriggerTemplate,
172+
stageDeploy.Namespace,
173+
)
154174
if err != nil {
155175
return pipeline, stage, nil, fmt.Errorf("failed to get raw resource from TriggerTemplate: %w", err)
156176
}

controllers/cdstagedeploy/chain/resolve_status.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ func (r *ResolveStatus) ServeRequest(ctx context.Context, stageDeploy *codebaseA
9090
return nil
9191
}
9292

93-
func (r *ResolveStatus) getRunningPipelines(ctx context.Context, stageDeploy *codebaseApi.CDStageDeploy) (*tektonpipelineApi.PipelineRunList, error) {
93+
func (r *ResolveStatus) getRunningPipelines(
94+
ctx context.Context,
95+
stageDeploy *codebaseApi.CDStageDeploy,
96+
) (*tektonpipelineApi.PipelineRunList, error) {
9497
log := ctrl.LoggerFrom(ctx)
9598

9699
pipelineRun := &tektonpipelineApi.PipelineRunList{}

controllers/codebase/codebase_controller.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func (r *ReconcileCodebase) updateFinishStatus(ctx context.Context, c *codebaseA
194194
// setFailureCount increments failure count and returns delay for next reconciliation.
195195
func (r *ReconcileCodebase) setFailureCount(ctx context.Context, codebase *codebaseApi.Codebase) time.Duration {
196196
const defaultTimeout = 10 * time.Second
197+
197198
timeout := util.GetTimeout(codebase.Status.FailureCount, defaultTimeout)
198199

199200
codebase.Status.FailureCount++
@@ -205,7 +206,10 @@ func (r *ReconcileCodebase) setFailureCount(ctx context.Context, codebase *codeb
205206
return timeout
206207
}
207208

208-
func (r *ReconcileCodebase) getChain(ctx context.Context, codebase *codebaseApi.Codebase) (cHand.CodebaseHandler, error) {
209+
func (r *ReconcileCodebase) getChain(
210+
ctx context.Context,
211+
codebase *codebaseApi.Codebase,
212+
) (cHand.CodebaseHandler, error) {
209213
if r.chainGetter == nil {
210214
r.chainGetter = func(cr *codebaseApi.Codebase) (cHand.CodebaseHandler, error) {
211215
return chain.MakeChain(ctx, r.client), nil
@@ -215,7 +219,10 @@ func (r *ReconcileCodebase) getChain(ctx context.Context, codebase *codebaseApi.
215219
return r.chainGetter(codebase)
216220
}
217221

218-
func (r *ReconcileCodebase) tryToDeleteCodebase(ctx context.Context, codebase *codebaseApi.Codebase) (*reconcile.Result, error) {
222+
func (r *ReconcileCodebase) tryToDeleteCodebase(
223+
ctx context.Context,
224+
codebase *codebaseApi.Codebase,
225+
) (*reconcile.Result, error) {
219226
log := ctrl.LoggerFrom(ctx)
220227

221228
if codebase.GetDeletionTimestamp().IsZero() {

controllers/codebase/service/chain/checkout_branch.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ func CheckoutBranch(
2121
gitProviderFactory func(config gitproviderv2.Config) gitproviderv2.Git,
2222
) error {
2323
log := ctrl.LoggerFrom(ctx)
24-
gitProvider := gitProviderFactory(gitproviderv2.NewConfigFromGitServerAndSecret(repoContext.GitServer, repoContext.GitServerSecret))
24+
gitProvider := gitProviderFactory(
25+
gitproviderv2.NewConfigFromGitServerAndSecret(
26+
repoContext.GitServer,
27+
repoContext.GitServerSecret,
28+
),
29+
)
2530

2631
currentBranchName, err := gitProvider.GetCurrentBranchName(ctx, repoContext.WorkDir)
2732
if err != nil {

controllers/codebase/service/chain/common.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ type GitRepositoryContext struct {
2828
WorkDir string
2929
}
3030

31-
func setIntermediateSuccessFields(ctx context.Context, c client.Client, cb *codebaseApi.Codebase, action codebaseApi.ActionType) error {
31+
func setIntermediateSuccessFields(
32+
ctx context.Context,
33+
c client.Client,
34+
cb *codebaseApi.Codebase,
35+
action codebaseApi.ActionType,
36+
) error {
3237
// Set WebHookRef from WebHookID for backward compatibility.
3338
webHookRef := cb.Status.WebHookRef
3439
if webHookRef == "" && cb.Status.WebHookID != 0 {
@@ -81,6 +86,7 @@ func updateGitStatusWithPatch(
8186
// Apply patch to status subresource
8287
if err := c.Status().Patch(ctx, codebase, patch); err != nil {
8388
setFailedFields(codebase, action, err.Error())
89+
8490
return fmt.Errorf("failed to patch git status to %s for codebase %s: %w",
8591
gitStatus, codebase.Name, err)
8692
}
@@ -113,7 +119,12 @@ func PrepareGitRepository(
113119
return nil, err
114120
}
115121

116-
gitProvider := gitProviderFactory(gitproviderv2.NewConfigFromGitServerAndSecret(gitRepoCtx.GitServer, gitRepoCtx.GitServerSecret))
122+
gitProvider := gitProviderFactory(
123+
gitproviderv2.NewConfigFromGitServerAndSecret(
124+
gitRepoCtx.GitServer,
125+
gitRepoCtx.GitServerSecret,
126+
),
127+
)
117128

118129
if !util.DoesDirectoryExist(gitRepoCtx.WorkDir) || util.IsDirectoryEmpty(gitRepoCtx.WorkDir) {
119130
log.Info("Start cloning repository", "url", gitRepoCtx.RepoGitUrl)

controllers/codebase/service/chain/common_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ func TestPrepareGitRepository(t *testing.T) {
312312
m := gitMocks.NewMockGit(t)
313313
m.On("Clone", testify.Anything, testify.Anything, testify.Anything).Return(nil)
314314
m.On("GetCurrentBranchName", testify.Anything, testify.Anything).Return("main", nil)
315+
315316
return m
316317
},
317318
wantErr: require.NoError,
@@ -388,6 +389,7 @@ func TestPrepareGitRepository(t *testing.T) {
388389
m := gitMocks.NewMockGit(t)
389390
m.On("Clone", testify.Anything, testify.Anything, testify.Anything).
390391
Return(assert.AnError)
392+
391393
return m
392394
},
393395
wantErr: func(t require.TestingT, err error, i ...interface{}) {
@@ -432,6 +434,7 @@ func TestPrepareGitRepository(t *testing.T) {
432434
m.On("Clone", testify.Anything, testify.Anything, testify.Anything).Return(nil)
433435
m.On("GetCurrentBranchName", testify.Anything, testify.Anything).
434436
Return("", errors.New("failed to get current branch"))
437+
435438
return m
436439
},
437440
wantErr: func(t require.TestingT, err error, i ...interface{}) {

controllers/codebase/service/chain/delete_webhook.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ func (s *DeleteWebHook) ServeRequest(ctx context.Context, codebase *codebaseApi.
4646
}
4747

4848
gitServer := &codebaseApi.GitServer{}
49-
if err := s.client.Get(ctx, client.ObjectKey{Name: codebase.Spec.GitServer, Namespace: codebase.Namespace}, gitServer); err != nil {
49+
if err := s.client.Get(
50+
ctx,
51+
client.ObjectKey{Name: codebase.Spec.GitServer, Namespace: codebase.Namespace},
52+
gitServer,
53+
); err != nil {
5054
log.Error(err, "Failed to delete webhook: unable to get GitServer", "gitServer", codebase.Spec.GitServer)
5155

5256
return nil
@@ -59,7 +63,11 @@ func (s *DeleteWebHook) ServeRequest(ctx context.Context, codebase *codebaseApi.
5963
return nil
6064
}
6165

62-
gitProvider, err := gitprovider.NewProvider(gitServer, s.restyClient, string(secret.Data[util.GitServerSecretTokenField]))
66+
gitProvider, err := gitprovider.NewProvider(
67+
gitServer,
68+
s.restyClient,
69+
string(secret.Data[util.GitServerSecretTokenField]),
70+
)
6371
if err != nil {
6472
log.Error(err, "Failed to delete webhook: unable to create git provider")
6573

0 commit comments

Comments
 (0)