Skip to content

Commit da716f5

Browse files
committed
Update linter, address violations.
1 parent b52e864 commit da716f5

File tree

11 files changed

+47
-289
lines changed

11 files changed

+47
-289
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@v7
2222
with:
23-
version: v1.61
23+
version: v2.1.5

.golangci.yml

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
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:
7+
- copyloopvar
228
- dupl
239
- errcheck
24-
- copyloopvar
2510
- ginkgolinter
2611
- goconst
2712
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3113
- govet
3214
- ineffassign
3315
- lll
@@ -36,12 +18,34 @@ linters:
3618
- prealloc
3719
- revive
3820
- staticcheck
39-
- typecheck
4021
- unconvert
4122
- unparam
4223
- unused
43-
44-
linters-settings:
45-
revive:
24+
settings:
25+
revive:
26+
rules:
27+
- name: comment-spacings
28+
exclusions:
29+
generated: lax
4630
rules:
47-
- name: comment-spacings
31+
- linters:
32+
- lll
33+
path: api/*
34+
- linters:
35+
- dupl
36+
- lll
37+
path: internal/*
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$
42+
formatters:
43+
enable:
44+
- gofmt
45+
- goimports
46+
exclusions:
47+
generated: lax
48+
paths:
49+
- third_party$
50+
- builtin$
51+
- examples$

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
181181
KUSTOMIZE_VERSION ?= v5.5.0
182182
CONTROLLER_TOOLS_VERSION ?= v0.16.4
183183
ENVTEST_VERSION ?= release-0.19
184-
GOLANGCI_LINT_VERSION ?= v1.62.0
184+
GOLANGCI_LINT_VERSION ?= v2.1.5
185185

186186
.PHONY: kustomize
187187
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -201,7 +201,7 @@ $(ENVTEST): $(LOCALBIN)
201201
.PHONY: golangci-lint
202202
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
203203
$(GOLANGCI_LINT): $(LOCALBIN)
204-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
204+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
205205

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

internal/controller/instance_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
// InstanceReconciler reconciles an Instance object
2121
type InstanceReconciler struct {
22-
client.Client
22+
Client client.Client
2323
Scheme *runtime.Scheme
2424
}
2525

internal/controller/workload_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const deploymentWorkloadUID = "spec.workloadRef.uid"
3131

3232
// WorkloadReconciler reconciles a Workload object
3333
type WorkloadReconciler struct {
34-
client.Client
34+
Client client.Client
3535
Scheme *runtime.Scheme
3636
finalizers finalizer.Finalizers
3737
}
@@ -53,7 +53,7 @@ func (r *WorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
5353

5454
finalizationResult, err := r.finalizers.Finalize(ctx, &workload)
5555
if err != nil {
56-
if v, ok := err.(kerrors.Aggregate); ok && v.Is(workloadHasDeploymentsErr) {
56+
if v, ok := err.(kerrors.Aggregate); ok && v.Is(errWorkloadHasDeployments) {
5757
// Don't produce an error in this case and let the watch on deployments
5858
// result in another reconcile schedule.
5959
logger.Info("workload still has deployments, waiting until removal")
@@ -293,7 +293,7 @@ func (r *WorkloadReconciler) reconcileWorkloadStatus(
293293
return nil
294294
}
295295

296-
var workloadHasDeploymentsErr = errors.New("workload has deployments")
296+
var errWorkloadHasDeployments = errors.New("workload has deployments")
297297

298298
func (r *WorkloadReconciler) Finalize(ctx context.Context, obj client.Object) (finalizer.Result, error) {
299299

@@ -336,7 +336,7 @@ func (r *WorkloadReconciler) Finalize(ctx context.Context, obj client.Object) (f
336336
// Really don't like using errors for communication here. I think we'd need
337337
// to move away from the finalizer helper to ensure we can wait on child
338338
// resources to be gone before allowing the finalizer to be removed.
339-
return finalizer.Result{}, workloadHasDeploymentsErr
339+
return finalizer.Result{}, errWorkloadHasDeployments
340340
}
341341

342342
// getDeploymentsForWorkload returns both deployments that are desired to exist
@@ -368,7 +368,7 @@ func (r *WorkloadReconciler) getDeploymentsForWorkload(
368368
}
369369

370370
if len(locations.Items) == 0 {
371-
return nil, nil, fmt.Errorf("no locations are registered with the system.")
371+
return nil, nil, fmt.Errorf("no locations are registered with the system")
372372
}
373373

374374
// Remember this: namespace, name, err := cache.SplitMetaNamespaceKey(key)

internal/controller/workloaddeployment_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
// WorkloadDeploymentReconciler reconciles a WorkloadDeployment object
2222
type WorkloadDeploymentReconciler struct {
23-
client.Client
23+
Client client.Client
2424
Scheme *runtime.Scheme
2525
}
2626

internal/controller/workloaddeployment_scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
// WorkloadDeploymentScheduler schedules a WorkloadDeployment
2525
type WorkloadDeploymentScheduler struct {
26-
client.Client
26+
Client client.Client
2727
Scheme *runtime.Scheme
2828
}
2929

internal/webhook/workload_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func SetupWorkloadWebhookWithManager(mgr ctrl.Manager) error {
3838
// +kubebuilder:webhook:path=/mutate-compute-datumapis-com-v1alpha-workload,mutating=true,failurePolicy=fail,sideEffects=None,groups=compute.datumapis.com,resources=workloads,verbs=create;update,versions=v1alpha,name=mworkload.kb.io,admissionReviewVersions=v1
3939

4040
type workloadWebhook struct {
41-
client.Client
41+
Client client.Client
4242
logger logr.Logger
4343
}
4444

test/e2e/e2e_suite_test.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/e2e/e2e_test.go

Lines changed: 4 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,6 @@
1-
// SPDX-License-Identifier: AGPL-3.0-only
2-
31
package e2e
42

5-
import (
6-
"fmt"
7-
"os/exec"
8-
"time"
9-
10-
. "github.com/onsi/ginkgo/v2"
11-
. "github.com/onsi/gomega"
12-
13-
"go.datum.net/workload-operator/test/utils"
14-
)
15-
16-
const namespace = "workload-operator-system"
17-
18-
var _ = Describe("controller", Ordered, func() {
19-
BeforeAll(func() {
20-
By("installing prometheus operator")
21-
Expect(utils.InstallPrometheusOperator()).To(Succeed())
22-
23-
By("installing the cert-manager")
24-
Expect(utils.InstallCertManager()).To(Succeed())
25-
26-
By("creating manager namespace")
27-
cmd := exec.Command("kubectl", "create", "ns", namespace)
28-
_, _ = utils.Run(cmd)
29-
})
30-
31-
AfterAll(func() {
32-
By("uninstalling the Prometheus manager bundle")
33-
utils.UninstallPrometheusOperator()
34-
35-
By("uninstalling the cert-manager bundle")
36-
utils.UninstallCertManager()
37-
38-
By("removing manager namespace")
39-
cmd := exec.Command("kubectl", "delete", "ns", namespace)
40-
_, _ = utils.Run(cmd)
41-
})
42-
43-
Context("Operator", func() {
44-
It("should run successfully", func() {
45-
var controllerPodName string
46-
var err error
47-
48-
// projectimage stores the name of the image used in the example
49-
var projectimage = "example.com/workload-operator:v0.0.1"
50-
51-
By("building the manager(Operator) image")
52-
cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectimage))
53-
_, err = utils.Run(cmd)
54-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
55-
56-
By("loading the the manager(Operator) image on Kind")
57-
err = utils.LoadImageToKindClusterWithName(projectimage)
58-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
59-
60-
By("installing CRDs")
61-
cmd = exec.Command("make", "install")
62-
_, err = utils.Run(cmd)
63-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
64-
65-
By("deploying the controller-manager")
66-
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage))
67-
_, err = utils.Run(cmd)
68-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
69-
70-
By("validating that the controller-manager pod is running as expected")
71-
verifyControllerUp := func() error {
72-
// Get pod name
73-
74-
cmd = exec.Command("kubectl", "get",
75-
"pods", "-l", "control-plane=controller-manager",
76-
"-o", "go-template={{ range .items }}"+
77-
"{{ if not .metadata.deletionTimestamp }}"+
78-
"{{ .metadata.name }}"+
79-
"{{ \"\\n\" }}{{ end }}{{ end }}",
80-
"-n", namespace,
81-
)
82-
83-
podOutput, err := utils.Run(cmd)
84-
ExpectWithOffset(2, err).NotTo(HaveOccurred())
85-
podNames := utils.GetNonEmptyLines(string(podOutput))
86-
if len(podNames) != 1 {
87-
return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames))
88-
}
89-
controllerPodName = podNames[0]
90-
ExpectWithOffset(2, controllerPodName).Should(ContainSubstring("controller-manager"))
91-
92-
// Validate pod status
93-
cmd = exec.Command("kubectl", "get",
94-
"pods", controllerPodName, "-o", "jsonpath={.status.phase}",
95-
"-n", namespace,
96-
)
97-
status, err := utils.Run(cmd)
98-
ExpectWithOffset(2, err).NotTo(HaveOccurred())
99-
if string(status) != "Running" {
100-
return fmt.Errorf("controller pod in %s status", status)
101-
}
102-
return nil
103-
}
104-
EventuallyWithOffset(1, verifyControllerUp, time.Minute, time.Second).Should(Succeed())
105-
106-
})
107-
})
108-
})
3+
// This file exists due to the inability to bypass e2e generation when using
4+
// kubebuilder to generate resources.
5+
//
6+
// See: https://github.com/kubernetes-sigs/kubebuilder/issues/4509

0 commit comments

Comments
 (0)