Skip to content
Open
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/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
with:
go-version: ${{ steps.vars.outputs.go_version }}
- name: golangci-lint-${{matrix.working-directory}}
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
version: v1.64.7
version: v2.6.2
working-directory: ${{matrix.working-directory}}
args: --timeout=10m
161 changes: 86 additions & 75 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: "2"
run:
go: "1.24"
linters:
disable-all: true
default: none
enable:
- asasalint
- asciicheck
Expand Down Expand Up @@ -30,11 +31,8 @@ linters:
- goconst
- gocritic
- godot
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- iface
Expand All @@ -60,88 +58,101 @@ linters:
#- revive
- rowserrcheck
- staticcheck
- stylecheck
- tagliatelle
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting
- whitespace
# Run with --fast=false for more extensive checks
fast: true
linters-settings:
gosec:
severity: medium
confidence: medium
concurrency: 8
# (NOTE)elfosardo: we should try removing this exclude once we bump golangci-lint to 1.61
excludes:
settings:
gocritic:
enabled-tags:
- experimental
gosec:
# (NOTE)elfosardo: we should try removing this exclude once we bump golangci-lint to 1.61
excludes:
- G115
importas:
no-unaliased: true
alias:
# Kubernetes
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: k8serrors
- pkg: k8s.io/apimachinery/pkg/util/errors
alias: kerrors
- pkg: k8s.io/component-base/logs/api/v1
alias: logsv1
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
# IrSO
- pkg: github.com/metal3-io/ironic-standalone-operator/api/v1alpha1
alias: metal3api
nolintlint:
allow-unused: false
require-specific: true
gocritic:
enabled-tags:
- experimental
tagliatelle:
case:
rules:
json: goCamel
govet:
enable:
- shadow
severity: medium
confidence: medium
concurrency: 8
govet:
enable:
- shadow
importas:
alias:
# Kubernetes
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: k8serrors
- pkg: k8s.io/apimachinery/pkg/util/errors
alias: kerrors
- pkg: k8s.io/component-base/logs/api/v1
alias: logsv1
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
# IrSO
- pkg: github.com/metal3-io/ironic-standalone-operator/api/v1alpha1
alias: metal3api
no-unaliased: true
nolintlint:
require-specific: true
allow-unused: false
tagliatelle:
case:
rules:
json: goCamel
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- path: test/.*.go
text: should not use dot imports
- linters:
- importas
path: cmd/main.go
text: metal3iov1alpha1
- linters:
- gosec
path: suite_test.go
text: 'G404: Use of weak random number generator .*'
- linters:
- tagliatelle
text: CIDR
- linters:
- tagliatelle
text: CA
paths:
- zz_generated.*\.go$
- .*conversion.*\.go$
- third_party$
- builtin$
- examples$
issues:
exclude-files:
- "zz_generated.*\\.go$"
- ".*conversion.*\\.go$"
include:
- EXC0002 # include "missing comments" issues from golangci-lint
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
# Dot imports for gomega or ginkgo are allowed
# within test files.
- path: test/.*.go
text: should not use dot imports
# NOTE(dtantsur): Kubebuilder insists on a specific way to call imports
- linters:
- importas
path: cmd/main.go
text: metal3iov1alpha1
- linters:
- gosec
path: suite_test.go
text: "G404: Use of weak random number generator .*"
- linters:
- tagliatelle
text: "CIDR"
- linters:
- tagliatelle
text: "CA"
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- zz_generated.*\.go$
- .*conversion.*\.go$
- third_party$
- builtin$
- examples$
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.2
CONTROLLER_TOOLS_VERSION ?= v0.17.0
GOLANGCI_LINT_VERSION ?= v1.64.7
GOLANGCI_LINT_VERSION ?= v2.6.2

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand All @@ -237,10 +237,17 @@ $(CONTROLLER_GEN): $(LOCALBIN)

$(GOLANGCI_LINT): $(LOCALBIN) ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten.
test -s $(GOLANGCI_LINT) && $(GOLANGCI_LINT) --version | grep -q $(GOLANGCI_LINT_VERSION) || \
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) config verify
$(GOLANGCI_LINT) run -v --fast-only ./... --timeout=10m
cd api; $(GOLANGCI_LINT) run -v --fast-only --path-prefix=api ./... --timeout=10m
cd test; $(GOLANGCI_LINT) run -v --fast-only --path-prefix=test ./... --timeout=10m

.PHONY: lint-full
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want lint and lint full both to exist. Cherry-pick the lint-full -> lint commit here as well, or just manually do the same.

lint-full: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) config verify
$(GOLANGCI_LINT) run -v ./... --timeout=10m
cd api; $(GOLANGCI_LINT) run -v --path-prefix=api ./... --timeout=10m
Expand Down
2 changes: 1 addition & 1 deletion pkg/ironic/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func TestAnnotationLabelOverrides(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, "my-annotation", podTemplate.Annotations["annotation.example.com"])
assert.NotEqual(t, "", podTemplate.Annotations["ironic.metal3.io/api-secret-version"])
assert.NotEmpty(t, podTemplate.Annotations["ironic.metal3.io/api-secret-version"])
assert.Equal(t, "my-label", podTemplate.Labels["label.example.com"])
assert.Equal(t, "test", podTemplate.Labels[metal3api.IronicServiceLabel])
}
8 changes: 4 additions & 4 deletions pkg/ironic/ironic.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ensureIronicDaemonSet(cctx ControllerContext, resources Resources) (Status,
},
}
result, err := controllerutil.CreateOrUpdate(cctx.Context, cctx.Client, deploy, func() error {
if deploy.ObjectMeta.CreationTimestamp.IsZero() {
if deploy.CreationTimestamp.IsZero() {
cctx.Logger.Info("creating a new ironic daemon set")
}
if deploy.Labels == nil {
Expand Down Expand Up @@ -74,7 +74,7 @@ func ensureIronicDeployment(cctx ControllerContext, resources Resources) (Status
},
}
result, err := controllerutil.CreateOrUpdate(cctx.Context, cctx.Client, deploy, func() error {
if deploy.ObjectMeta.CreationTimestamp.IsZero() {
if deploy.CreationTimestamp.IsZero() {
cctx.Logger.Info("creating a new ironic deployment")
}
if deploy.Labels == nil {
Expand Down Expand Up @@ -113,9 +113,9 @@ func ensureIronicService(cctx ControllerContext, ironic *metal3api.Ironic) (Stat
exposedPort = httpsExposedPort
}
result, err := controllerutil.CreateOrUpdate(cctx.Context, cctx.Client, service, func() error {
if service.ObjectMeta.Labels == nil {
if service.Labels == nil {
cctx.Logger.Info("creating a new ironic service")
service.ObjectMeta.Labels = make(map[string]string, 2)
service.Labels = make(map[string]string, 2)
}
service.Labels[metal3api.IronicServiceLabel] = ironic.Name
service.Labels[metal3api.IronicVersionLabel] = cctx.VersionInfo.InstalledVersion.String()
Expand Down
8 changes: 4 additions & 4 deletions pkg/ironic/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ func ensureIronicUpgradeJob(cctx ControllerContext, resources Resources, phase u
template := newMigrationTemplate(cctx, resources.Ironic, phase)

result, err := controllerutil.CreateOrUpdate(cctx.Context, cctx.Client, job, func() error {
if job.ObjectMeta.Labels == nil {
if job.Labels == nil {
cctx.Logger.Info("creating a new upgrade job", "Phase", phase, "From", fromVersion, "To", toVersion.String())
job.ObjectMeta.Labels = make(map[string]string, 2)
job.Labels = make(map[string]string, 2)
}
job.ObjectMeta.Labels[metal3api.IronicServiceLabel] = resources.Ironic.Name
job.ObjectMeta.Labels[metal3api.IronicVersionLabel] = cctx.VersionInfo.InstalledVersion.String()
job.Labels[metal3api.IronicServiceLabel] = resources.Ironic.Name
job.Labels[metal3api.IronicVersionLabel] = cctx.VersionInfo.InstalledVersion.String()

job.Spec.TTLSecondsAfterFinished = ptr.To(jobTTLSeconds)
mergePodTemplates(&job.Spec.Template, template)
Expand Down
4 changes: 2 additions & 2 deletions pkg/ironic/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func mergeContainers(target, source []corev1.Container) []corev1.Container {
// mergePodTemplates updates an existing pod template, taking care to avoid
// overriding defaulted values.
func mergePodTemplates(target *corev1.PodTemplateSpec, source corev1.PodTemplateSpec) {
if target.ObjectMeta.Labels == nil {
target.ObjectMeta.Labels = make(map[string]string, len(source.ObjectMeta.Labels))
if target.Labels == nil {
target.Labels = make(map[string]string, len(source.Labels))
}
maps.Copy(target.Labels, source.Labels)
if source.Annotations != nil {
Expand Down
Loading