Skip to content

Commit f776ca8

Browse files
Update dependencies and go version (#45)
* Chore: update GitHub Actions to use latest versions of actions and improve multi-arch support * Fix: update bundle-build target to use standard build command * feat: upgrade Go to 1.26 and update dependencies to fix vulnerabilities BREAKING CHANGE: migrate webhook interfaces to typed generics from controller-runtime v0.23.3 (Validator[T], Defaulter[T]) * chore: update Go version to 1.26.2 in CI workflows * refactor: migrate to golangci-lint v2 and fix all lint issues Adapt config to v2 format, fix indent-error-flow/superfluous-else, add package comments, remove unused code, fix deprecated API usage, and correct error string capitalization.
1 parent c8d6580 commit f776ca8

32 files changed

Lines changed: 635 additions & 683 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup Go ⬇️
2121
uses: actions/setup-go@v3
2222
with:
23-
go-version: 1.24.2
23+
go-version: 1.26.2
2424

2525
- name: Install kubectl, helm, kind and kuttl ⬇️
2626
env:

.github/workflows/go-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup Go ⬇️
2121
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
2222
with:
23-
go-version: 1.24.2
23+
go-version: 1.26.2
2424

2525
- name: Build and test 🏗️
2626
run: |
@@ -43,7 +43,7 @@ jobs:
4343
- name: Setup Go ⬇️
4444
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
4545
with:
46-
go-version: 1.24.2
46+
go-version: 1.26.2
4747

4848
- name: Linter 🔍
4949
run: |

.golangci.yml

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
1+
version: "2"
2+
13
run:
24
timeout: 5m
35
allow-parallel-runners: true
6+
tests: false
47

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: "cmd/*"
20-
linters:
21-
- lll
228
linters:
23-
disable-all: true
9+
default: none
2410
enable:
25-
- dupl
2611
- errcheck
27-
- exportloopref
2812
- ginkgolinter
2913
- goconst
30-
- gocyclo
31-
- gofmt
32-
- goimports
33-
- gosimple
3414
- govet
3515
- ineffassign
36-
- lll
3716
- misspell
3817
- nakedret
39-
- prealloc
4018
- revive
4119
- staticcheck
42-
- typecheck
4320
- unconvert
4421
- unparam
4522
- unused
46-
47-
linters-settings:
48-
revive:
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
- name: indent-error-flow
28+
- name: superfluous-else
29+
- name: package-comments
30+
- name: exported
31+
disabled: true
32+
- name: unused-parameter
33+
disabled: true
34+
- name: var-naming
35+
disabled: true
36+
exclusions:
4937
rules:
50-
- name: comment-spacings
38+
- linters:
39+
- staticcheck
40+
text: "SA1019"
41+
42+
formatters:
43+
enable:
44+
- gofmt
45+
- goimports

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.24.0 AS builder
2+
FROM golang:1.26.2 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -14,7 +14,7 @@ RUN go mod download
1414
# Copy the go source
1515
COPY cmd/main.go cmd/main.go
1616
COPY api/ api/
17-
COPY internal// internal//
17+
COPY internal/ internal/
1818
COPY pkg/ pkg/
1919

2020
# Build

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ test-e2e:
128128

129129
.PHONY: lint
130130
lint: golangci-lint ## Run golangci-lint linter
131-
$(GOLANGCI_LINT) --tests=false --config=.golangci.yml --exclude=type run
131+
$(GOLANGCI_LINT) run --config=.golangci.yml
132132

133133
.PHONY: lint-fix
134134
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
135-
$(GOLANGCI_LINT) --tests=false --config=.golangci.yml --exclude=type run --fix
135+
$(GOLANGCI_LINT) run --config=.golangci.yml --fix
136136

137137
##@ Build
138138

@@ -219,7 +219,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
219219
KUSTOMIZE_VERSION ?= v5.4.3
220220
CONTROLLER_TOOLS_VERSION ?= v0.17.2
221221
ENVTEST_VERSION ?= release-0.19
222-
GOLANGCI_LINT_VERSION ?= v1.59.1
222+
GOLANGCI_LINT_VERSION ?= v2.11.4
223223

224224
.PHONY: kustomize
225225
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -239,7 +239,7 @@ $(ENVTEST): $(LOCALBIN)
239239
.PHONY: golangci-lint
240240
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
241241
$(GOLANGCI_LINT): $(LOCALBIN)
242-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
242+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
243243

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

api/v1alphav1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// SPDX-License-Identifier: Apache-2.0
55

6-
// Package v1 contains API Schema definitions for the overcommit v1 API group
6+
// Package v1alphav1 contains API Schema definitions for the overcommit v1alphav1 API group
77
// +kubebuilder:object:generate=true
88
// +groupName=overcommit.inditex.dev
99
package v1alphav1

api/v1alphav1/overcommitclass_webhook.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ package v1alphav1
77

88
import (
99
"context"
10-
"fmt"
11-
12-
"k8s.io/apimachinery/pkg/runtime"
1310

1411
ctrl "sigs.k8s.io/controller-runtime"
1512
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -34,21 +31,16 @@ func (v *OvercommitClassValidator) InjectClient(c client.Client) {
3431
func (r *OvercommitClass) SetupWebhookWithManager(mgr ctrl.Manager) error {
3532
validator := &OvercommitClassValidator{}
3633
validator.InjectClient(mgr.GetClient())
37-
return ctrl.NewWebhookManagedBy(mgr).
38-
For(r).
34+
return ctrl.NewWebhookManagedBy(mgr, r).
3935
WithValidator(validator).
4036
Complete()
4137
}
4238

4339
// +kubebuilder:webhook:path=/validate-overcommit-inditex-dev-v1alphav1-overcommitclass,mutating=false,failurePolicy=fail,sideEffects=None,groups=overcommit.inditex.dev,resources=overcommitclass,verbs=create;update,versions=v1alphav1,name=overcommitclass.inditex.dev,admissionReviewVersions=v1
4440

4541
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
46-
func (v *OvercommitClassValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
42+
func (v *OvercommitClassValidator) ValidateCreate(ctx context.Context, overcommitClass *OvercommitClass) (admission.Warnings, error) {
4743

48-
overcommitClass, ok := obj.(*OvercommitClass)
49-
if !ok {
50-
return nil, fmt.Errorf("failed to cast object to OvercommitClass")
51-
}
5244
overcommitclasslog.Info("validate create", "name", overcommitClass.Name)
5345

5446
err := isClassDefault(*overcommitClass, v.Client)
@@ -75,21 +67,10 @@ func (v *OvercommitClassValidator) ValidateCreate(ctx context.Context, obj runti
7567
}
7668

7769
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
78-
func (v *OvercommitClassValidator) ValidateUpdate(ctx context.Context, old runtime.Object, new runtime.Object) (admission.Warnings, error) {
70+
func (v *OvercommitClassValidator) ValidateUpdate(ctx context.Context, oldOvercommitClass *OvercommitClass, newOvercommitClass *OvercommitClass) (admission.Warnings, error) {
7971

80-
// Convert old runtime.Object to *OvercommitClass
81-
oldOvercommitClass, ok := old.(*OvercommitClass)
82-
if !ok {
83-
return nil, fmt.Errorf("failed to cast old object to OvercommitClass")
84-
}
8572
overcommitclasslog.Info("validate update", "name", oldOvercommitClass.Name)
8673

87-
// Convert new runtime.Object to *OvercommitClass
88-
newOvercommitClass, ok := new.(*OvercommitClass)
89-
if !ok {
90-
return nil, fmt.Errorf("failed to cast new object to OvercommitClass")
91-
}
92-
9374
if !oldOvercommitClass.Spec.IsDefault {
9475
err := isClassDefault(*newOvercommitClass, v.Client)
9576
if err != nil {
@@ -114,11 +95,7 @@ func (v *OvercommitClassValidator) ValidateUpdate(ctx context.Context, old runti
11495
}
11596

11697
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
117-
func (v *OvercommitClassValidator) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
118-
overcommitClass, ok := obj.(*OvercommitClass)
119-
if !ok {
120-
return nil, fmt.Errorf("failed to cast object to OvercommitClass")
121-
}
98+
func (v *OvercommitClassValidator) ValidateDelete(ctx context.Context, overcommitClass *OvercommitClass) (admission.Warnings, error) {
12299
overcommitclasslog.Info("validate delete", "name", overcommitClass.Name)
123100

124101
return nil, nil

api/v1alphav1/webhook_validations.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717

1818
func validateSpecOvercommit(class OvercommitClass) error {
1919
if class.Spec.CpuOvercommit <= 0 || class.Spec.CpuOvercommit > 1 {
20-
return errors.New("Error: cpuOvercommit must be greater than 0 and equal or lower than 1, failed creating " + class.ObjectMeta.Name + " class ")
20+
return errors.New("Error: cpuOvercommit must be greater than 0 and equal or lower than 1, failed creating " + class.Name + " class ")
2121
}
2222
if class.Spec.MemoryOvercommit <= 0 || class.Spec.MemoryOvercommit > 1 {
23-
return errors.New("Error: memoryOvercommit must be greater than 0 and equal or lower than 1, failed creating " + class.ObjectMeta.Name + " class ")
23+
return errors.New("Error: memoryOvercommit must be greater than 0 and equal or lower than 1, failed creating " + class.Name + " class ")
2424
}
2525
return nil
2626
}
@@ -32,12 +32,12 @@ func checkDecimals(class OvercommitClass) error {
3232
roundedCpu := math.Round(cpu*precision) / precision
3333

3434
if math.Abs(cpu-roundedCpu) > 1e-9 {
35-
return errors.New("Error: the CPU value must have 4 decimals max")
35+
return errors.New("the CPU value must have 4 decimals max")
3636
}
3737

3838
roundedMemory := math.Round(memory*precision) / precision
3939
if math.Abs(memory-roundedMemory) > 1e-9 {
40-
return errors.New("Error: the memory value must have 4 decimals max")
40+
return errors.New("the memory value must have 4 decimals max")
4141
}
4242
return nil
4343
}
@@ -63,7 +63,7 @@ func isClassDefault(class OvercommitClass, client client.Client) error {
6363
}
6464

6565
if existsDefault {
66-
return fmt.Errorf("error: only one OvercommitClass can be default, failed creating %s class", class.ObjectMeta.Name)
66+
return fmt.Errorf("error: only one OvercommitClass can be default, failed creating %s class", class.Name)
6767
}
6868

6969
return nil

api/v1alphav1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44
// SPDX-License-Identifier: Apache-2.0
55

6+
// Package main is the entrypoint for the k8s-overcommit-operator.
67
package main
78

89
import (

0 commit comments

Comments
 (0)