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
270 changes: 128 additions & 142 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,159 +1,145 @@
linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- hugeParam

gocyclo:
min-complexity: 30
mnd:
# don't include the "operation" and "assign"
checks: [argument, case, condition, return]

revive:
enable-all-rules: false
rules:
# enable (taken from https://github.com/mgechev/revive/blob/master/defaults.toml)
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
# tweaks
- name: dot-imports
exclude: [TEST]
- name: unused-parameter
exclude: [TEST]

govet:
disable:
- shadow
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
stylecheck:
# ST1003 underscore in package names and var-naming
checks: ["all", "-ST1003"]

version: "2"
run:
issues-exit-code: 1
tests: true
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
default: none
enable:
- bodyclose
- dogsled
- dupl
- gocritic
- gofmt
- goimports
- gocyclo
- goprintffuncname
- gosimple
- gosec
- govet
- ineffassign
- lll
- misspell
- nakedret
- nolintlint
- revive
- rowserrcheck
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
- revive
- dupl
- gocyclo
- gosec
- nolintlint

# don't enable:
# - noctx
# - funlen # TODO reconcile functions are way too large
# - prealloc
# - exportloopref
# - gomnd # magic number detected -> sometimes useful
# - golint # is deprecated
# - goerr113 # we have some dynamic errors
# - exhaustive # missing switch case statements
# - asciicheck
# - depguard
# - errcheck # Disabled since it detects defers that do not check errors. This is a standard pattern.
# see https://github.com/kisielk/errcheck/issues/55
# - scopelint
# - gochecknoinits
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - interfacer
# - nestif
# - testpackage
# - wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- gochecknoglobals
- gosec
- noctx
- goerr113
- goconst
- dupl
- unparam

# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"

- text: "should not use dot imports"
path: _test\.go

exclude:
- directive `// nolint.*` should be written without leading space

run:
timeout: 15m
issues-exit-code: 1
tests: true
settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
gocritic:
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- hugeParam
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 30
govet:
disable:
- shadow
lll:
line-length: 140
misspell:
locale: US
mnd:
checks:
- argument
- case
- condition
- return
nolintlint:
require-explanation: true
require-specific: true
allow-unused: false
revive:
enable-all-rules: false
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: dot-imports
exclude:
- TEST
- name: unused-parameter
exclude:
- TEST
staticcheck:
checks:
- all
- -ST1003
- -QF1008
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- dupl
- err113
- gochecknoglobals
- goconst
- gosec
- mnd
- noctx
- unparam
path: _test\.go
- linters:
- gocritic
text: 'unnecessaryDefer:'
- path: _test\.go
text: should not use dot imports
- path: (.+)\.go$
text: directive `// nolint.*` should be written without leading space
# TODO: GetEventRecorderFor is deprecated
- linters:
- staticcheck
text: "GetEventRecorderFor is deprecated"
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
12 changes: 6 additions & 6 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
VERSION 0.8
FROM golang:1.23
FROM golang:1.25
ARG --global DOCKER_REPO=ghcr.io/stackitcloud/yawol/
ARG --global BINPATH=/usr/local/bin/
ARG --global GOCACHE=/go-cache

ARG --global ENVOY_VERSION=v1.27.0
ARG --global HELM_VERSION=3.12.3
ARG --global GOLANGCI_LINT_VERSION=v1.61.0
ARG --global GOLANGCI_LINT_VERSION=v2.10.1
ARG --global PACKER_VERSION=1.9
ARG --global TERRAFORM_VERSION=1.4.6

Expand Down Expand Up @@ -261,7 +261,7 @@ lint:

test:
FROM +deps
ARG KUBERNETES_VERSION=1.26.x
ARG KUBERNETES_VERSION=1.35.x
COPY +gotools/bin/setup-envtest $BINPATH
COPY +envoy/envoy $BINPATH
# install envtest in its own layer
Expand All @@ -276,9 +276,9 @@ test:
eval "$GO_TEST ./..."

test-multiple-k8s-versions:
BUILD +test --KUBERNETES_VERSION=1.25.x
BUILD +test --KUBERNETES_VERSION=1.26.x
BUILD +test --KUBERNETES_VERSION=1.27.x
BUILD +test --KUBERNETES_VERSION=1.33.x
BUILD +test --KUBERNETES_VERSION=1.34.x
BUILD +test --KUBERNETES_VERSION=1.35.x

list-available-k8s-envtest-versions:
FROM +deps
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
// ServiceDebugSSHKey set an sshkey
ServiceDebugSSHKey = "yawol.stackit.cloud/debugsshkey"
// ServiceClassName for filtering services in cloud-controller
//
// Deprecated: use .spec.loadBalancerClass instead
ServiceClassName = "yawol.stackit.cloud/className"
// ServiceReplicas for setting loadbalancer replicas in cloud-controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"reflect"
"strings"
"time"

"github.com/go-logr/logr"
yawolv1beta1 "github.com/stackitcloud/yawol/api/v1beta1"
Expand Down Expand Up @@ -68,7 +69,7 @@ func (r *LoadBalancerReconciler) Reconcile(ctx context.Context, req ctrl.Request
v1.EventTypeNormal,
"creation",
fmt.Sprintf("LoadBalancer is successfully created with IP %v", *lb.Status.ExternalIP))
return ctrl.Result{Requeue: true}, nil
return ctrl.Result{RequeueAfter: 1 * time.Second}, nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ func (r *ServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
r.Recorder.Event(svc, coreV1.EventTypeNormal, "creation", "LoadBalancer is in creation")

return ctrl.Result{Requeue: true}, nil
return ctrl.Result{RequeueAfter: 1 * time.Second}, nil
}

if loadBalancer.ObjectMeta.Annotations[ServiceAnnotation] != svc.Namespace+"/"+svc.Name {
if err := r.addAnnotation(ctx, loadBalancer, ServiceAnnotation, svc.Namespace+"/"+svc.Name); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: true}, err
return ctrl.Result{RequeueAfter: 1 * time.Second}, err
}

// if port specs differ, patch svc => lb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ var _ = Describe("Check loadbalancer reconcile", Serial, Ordered, func() {
Name: "class-name-service-test1",
Namespace: "default",
Annotations: map[string]string{
// nolint: staticcheck // this tests the deprecated feature
yawolv1beta1.ServiceClassName: "foo",
},
},
Expand Down Expand Up @@ -559,6 +560,7 @@ var _ = Describe("Check loadbalancer reconcile", Serial, Ordered, func() {
Name: "class-name-service-test2",
Namespace: "default",
Annotations: map[string]string{
// nolint: staticcheck // this tests the deprecated feature
yawolv1beta1.ServiceClassName: "",
},
},
Expand Down Expand Up @@ -1108,7 +1110,7 @@ var _ = Describe("Check loadbalancer reconcile", Serial, Ordered, func() {
},
Spec: v1.ServiceSpec{
IPFamilies: []v1.IPFamily{v1.IPv4Protocol, v1.IPv6Protocol},
IPFamilyPolicy: (*v1.IPFamilyPolicyType)(ptr.To(string(v1.IPFamilyPolicyRequireDualStack))),
IPFamilyPolicy: (*v1.IPFamilyPolicy)(ptr.To(string(v1.IPFamilyPolicyRequireDualStack))),
Ports: []v1.ServicePort{
{
Name: "port1",
Expand Down
Loading