Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
go-version: '~1.24.0'

- name: Run linter
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: v1.59
version: v2.1.6
55 changes: 29 additions & 26 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
version: "2"
run:
timeout: 5m
allow-parallel-runners: true

issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
# restore some of the defaults
# (fill in the rest as needed)
exclude-rules:
- path: "api/*"
linters:
- lll
- path: "internal/*"
linters:
- dupl
- lll
linters:
disable-all: true
default: none
enable:
- dupl
- errcheck
- exportloopref
- ginkgolinter
- goconst
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- lll
Expand All @@ -36,12 +17,34 @@ linters:
- prealloc
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- unused

linters-settings:
revive:
settings:
revive:
rules:
- name: comment-spacings
exclusions:
generated: lax
rules:
- name: comment-spacings
- linters:
- lll
path: api/*
- linters:
- dupl
- lll
path: internal/*
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_TOOLS_VERSION ?= v0.16.4
ENVTEST_VERSION ?= release-0.19
GOLANGCI_LINT_VERSION ?= v1.59.1
GOLANGCI_LINT_VERSION ?= v2.1.6

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand All @@ -193,7 +193,7 @@ $(ENVTEST): $(LOCALBIN)
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
Expand Down
1 change: 1 addition & 0 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ images:
- name: controller
newTag: main
newName: ghcr.io/miscord-dev/dexchange
digest: sha256:6fe19ae37223e322eac2d0ce6cd8db5899115f011881e50e69326848b8648f40

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
11 changes: 6 additions & 5 deletions internal/controller/dextoken_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func (r *DeXTokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
logger := log.FromContext(ctx)

dexToken := &dexchangev1alpha1.DeXToken{}
if err := r.Client.Get(ctx, req.NamespacedName, dexToken); err != nil {
if err := r.Get(ctx, req.NamespacedName, dexToken); err != nil {
return ctrl.Result{}, err
}

if !dexToken.ObjectMeta.DeletionTimestamp.IsZero() {
if !dexToken.DeletionTimestamp.IsZero() {
return ctrl.Result{}, nil
}

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

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

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

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

var serviceAccount corev1.ServiceAccount
err := r.Client.Get(ctx, client.ObjectKey{
err := r.Get(ctx, client.ObjectKey{
Namespace: dexToken.Namespace,
Name: serviceAccountName,
}, &serviceAccount)
Expand All @@ -233,7 +234,7 @@ func (r *DeXTokenReconciler) issueServiceAccountToken(ctx context.Context, dexTo
func (r *DeXTokenReconciler) getClientSecret(ctx context.Context, dexToken *dexchangev1alpha1.DeXToken) (string, error) {
if dexToken.Spec.DeX.ClientSecretRef.Name != "" {
var secret corev1.Secret
if err := r.Client.Get(ctx, client.ObjectKey{
if err := r.Get(ctx, client.ObjectKey{
Namespace: dexToken.Namespace,
Name: dexToken.Spec.DeX.ClientSecretRef.Name,
}, &secret); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion internal/dex/dex.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func Issue(ctx context.Context, config Config) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to send a request: %w", err)
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()

if resp.StatusCode != http.StatusOK {
b, _ := io.ReadAll(resp.Body)
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ var _ = Describe("Manager", Ordered, func() {
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
controllerLogs, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Controller logs:\n %s", controllerLogs))
_, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Controller logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Controller logs: %s", err)
}

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

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

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

// Parse the JSON output to extract the token
var token tokenRequest
err = json.Unmarshal([]byte(output), &token)
err = json.Unmarshal(output, &token)
g.Expect(err).NotTo(HaveOccurred())

out = token.Status.Token
Expand Down
8 changes: 4 additions & 4 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"os/exec"
"strings"

. "github.com/onsi/ginkgo/v2" //nolint:golint,revive
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck
)

const (
Expand Down Expand Up @@ -92,7 +92,7 @@ func IsPrometheusCRDsInstalled() bool {
if err != nil {
return false
}
crdList := GetNonEmptyLines(string(output))
crdList := GetNonEmptyLines(output)
for _, crd := range prometheusCRDs {
for _, line := range crdList {
if strings.Contains(line, crd) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func IsCertManagerCRDsInstalled() bool {
}

// Check if any of the Cert Manager CRDs are present
crdList := GetNonEmptyLines(string(output))
crdList := GetNonEmptyLines(output)
for _, crd := range certManagerCRDs {
for _, line := range crdList {
if strings.Contains(line, crd) {
Expand Down Expand Up @@ -197,7 +197,7 @@ func GetProjectDir() (string, error) {
if err != nil {
return wd, err
}
wd = strings.Replace(wd, "/test/e2e", "", -1)
wd = strings.ReplaceAll(wd, "/test/e2e", "")
return wd, nil
}

Expand Down