Skip to content

Commit cbbd11d

Browse files
authored
Merge pull request #4 from miscord-dev/bump-up-golangci-lint
Update lint.yml
2 parents 8ff01b9 + eb8cef5 commit cbbd11d

File tree

8 files changed

+54
-47
lines changed

8 files changed

+54
-47
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
go-version: '~1.24.0'
1919

2020
- name: Run linter
21-
uses: golangci/golangci-lint-action@v6
21+
uses: golangci/golangci-lint-action@v8
2222
with:
23-
version: v1.59
23+
version: v2.1.6

.golangci.yml

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
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
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
227
- dupl
238
- errcheck
24-
- exportloopref
259
- ginkgolinter
2610
- goconst
2711
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3112
- govet
3213
- ineffassign
3314
- lll
@@ -36,12 +17,34 @@ linters:
3617
- prealloc
3718
- revive
3819
- staticcheck
39-
- typecheck
4020
- unconvert
4121
- unparam
4222
- unused
43-
44-
linters-settings:
45-
revive:
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
exclusions:
28+
generated: lax
4629
rules:
47-
- name: comment-spacings
30+
- linters:
31+
- lll
32+
path: api/*
33+
- linters:
34+
- dupl
35+
- lll
36+
path: internal/*
37+
paths:
38+
- third_party$
39+
- builtin$
40+
- examples$
41+
formatters:
42+
enable:
43+
- gofmt
44+
- goimports
45+
exclusions:
46+
generated: lax
47+
paths:
48+
- third_party$
49+
- builtin$
50+
- examples$

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
173173
KUSTOMIZE_VERSION ?= v5.4.3
174174
CONTROLLER_TOOLS_VERSION ?= v0.16.4
175175
ENVTEST_VERSION ?= release-0.19
176-
GOLANGCI_LINT_VERSION ?= v1.59.1
176+
GOLANGCI_LINT_VERSION ?= v2.1.6
177177

178178
.PHONY: kustomize
179179
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -193,7 +193,7 @@ $(ENVTEST): $(LOCALBIN)
193193
.PHONY: golangci-lint
194194
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
195195
$(GOLANGCI_LINT): $(LOCALBIN)
196-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
196+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
197197

198198
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
199199
# $1 - target path with name of binary

config/default/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ images:
4545
- name: controller
4646
newTag: main
4747
newName: ghcr.io/miscord-dev/dexchange
48+
digest: sha256:6fe19ae37223e322eac2d0ce6cd8db5899115f011881e50e69326848b8648f40
4849

4950
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
5051
# crd/kustomization.yaml

internal/controller/dextoken_controller.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ func (r *DeXTokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
6464
logger := log.FromContext(ctx)
6565

6666
dexToken := &dexchangev1alpha1.DeXToken{}
67-
if err := r.Client.Get(ctx, req.NamespacedName, dexToken); err != nil {
67+
if err := r.Get(ctx, req.NamespacedName, dexToken); err != nil {
6868
return ctrl.Result{}, err
6969
}
7070

71-
if !dexToken.ObjectMeta.DeletionTimestamp.IsZero() {
71+
if !dexToken.DeletionTimestamp.IsZero() {
7272
return ctrl.Result{}, nil
7373
}
7474

@@ -95,7 +95,7 @@ func (r *DeXTokenReconciler) reconcileNormal(ctx context.Context, dexToken *dexc
9595
secretKey := dexToken.Spec.SecretKey
9696

9797
var secret corev1.Secret
98-
if err := r.Client.Get(ctx, client.ObjectKey{
98+
if err := r.Get(ctx, client.ObjectKey{
9999
Namespace: dexToken.Namespace,
100100
Name: dexToken.Status.TokenSecretName,
101101
}, &secret); err != nil && !apierrors.IsNotFound(err) {
@@ -134,6 +134,7 @@ func (r *DeXTokenReconciler) reconcileNormal(ctx context.Context, dexToken *dexc
134134
}, nil
135135
}
136136

137+
//nolint:unparam
137138
func (r *DeXTokenReconciler) checkExpired(ctx context.Context, dexToken *dexchangev1alpha1.DeXToken, secret *corev1.Secret, secretKey string) (ctrl.Result, error) {
138139
logger := log.FromContext(ctx)
139140

@@ -207,7 +208,7 @@ func (r *DeXTokenReconciler) issueServiceAccountToken(ctx context.Context, dexTo
207208
serviceAccountName := dexToken.Spec.ServiceAccount.Name
208209

209210
var serviceAccount corev1.ServiceAccount
210-
err := r.Client.Get(ctx, client.ObjectKey{
211+
err := r.Get(ctx, client.ObjectKey{
211212
Namespace: dexToken.Namespace,
212213
Name: serviceAccountName,
213214
}, &serviceAccount)
@@ -233,7 +234,7 @@ func (r *DeXTokenReconciler) issueServiceAccountToken(ctx context.Context, dexTo
233234
func (r *DeXTokenReconciler) getClientSecret(ctx context.Context, dexToken *dexchangev1alpha1.DeXToken) (string, error) {
234235
if dexToken.Spec.DeX.ClientSecretRef.Name != "" {
235236
var secret corev1.Secret
236-
if err := r.Client.Get(ctx, client.ObjectKey{
237+
if err := r.Get(ctx, client.ObjectKey{
237238
Namespace: dexToken.Namespace,
238239
Name: dexToken.Spec.DeX.ClientSecretRef.Name,
239240
}, &secret); err != nil {

internal/dex/dex.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ func Issue(ctx context.Context, config Config) (string, error) {
4545
if err != nil {
4646
return "", fmt.Errorf("failed to send a request: %w", err)
4747
}
48-
defer resp.Body.Close()
48+
defer func() {
49+
_ = resp.Body.Close()
50+
}()
4951

5052
if resp.StatusCode != http.StatusOK {
5153
b, _ := io.ReadAll(resp.Body)

test/e2e/e2e_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,27 @@ var _ = Describe("Manager", Ordered, func() {
9393
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
9494
controllerLogs, err := utils.Run(cmd)
9595
if err == nil {
96-
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Controller logs:\n %s", controllerLogs))
96+
_, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs)
9797
} else {
98-
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Controller logs: %s", err))
98+
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Controller logs: %s", err)
9999
}
100100

101101
By("Fetching Kubernetes events")
102102
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
103103
eventsOutput, err := utils.Run(cmd)
104104
if err == nil {
105-
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Kubernetes events:\n%s", eventsOutput))
105+
_, _ = fmt.Fprintf(GinkgoWriter, "Kubernetes events:\n%s", eventsOutput)
106106
} else {
107-
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Kubernetes events: %s", err))
107+
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Kubernetes events: %s", err)
108108
}
109109

110110
By("Fetching curl-metrics logs")
111111
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
112112
metricsOutput, err := utils.Run(cmd)
113113
if err == nil {
114-
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Metrics logs:\n %s", metricsOutput))
114+
_, _ = fmt.Fprintf(GinkgoWriter, "Metrics logs:\n %s", metricsOutput)
115115
} else {
116-
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get curl-metrics logs: %s", err))
116+
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get curl-metrics logs: %s", err)
117117
}
118118

119119
By("Fetching controller manager pod description")
@@ -278,7 +278,7 @@ func serviceAccountToken() (string, error) {
278278

279279
// Parse the JSON output to extract the token
280280
var token tokenRequest
281-
err = json.Unmarshal([]byte(output), &token)
281+
err = json.Unmarshal(output, &token)
282282
g.Expect(err).NotTo(HaveOccurred())
283283

284284
out = token.Status.Token

test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"os/exec"
2525
"strings"
2626

27-
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive
27+
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck
2828
)
2929

3030
const (
@@ -92,7 +92,7 @@ func IsPrometheusCRDsInstalled() bool {
9292
if err != nil {
9393
return false
9494
}
95-
crdList := GetNonEmptyLines(string(output))
95+
crdList := GetNonEmptyLines(output)
9696
for _, crd := range prometheusCRDs {
9797
for _, line := range crdList {
9898
if strings.Contains(line, crd) {
@@ -153,7 +153,7 @@ func IsCertManagerCRDsInstalled() bool {
153153
}
154154

155155
// Check if any of the Cert Manager CRDs are present
156-
crdList := GetNonEmptyLines(string(output))
156+
crdList := GetNonEmptyLines(output)
157157
for _, crd := range certManagerCRDs {
158158
for _, line := range crdList {
159159
if strings.Contains(line, crd) {
@@ -197,7 +197,7 @@ func GetProjectDir() (string, error) {
197197
if err != nil {
198198
return wd, err
199199
}
200-
wd = strings.Replace(wd, "/test/e2e", "", -1)
200+
wd = strings.ReplaceAll(wd, "/test/e2e", "")
201201
return wd, nil
202202
}
203203

0 commit comments

Comments
 (0)