Skip to content

Commit

Permalink
Use ginkgolinter
Browse files Browse the repository at this point in the history
- Use ginkgolinter in golangci-lint configuration
- Update golangci-lint installation in Makefile
- Fix ginkgo/gomega linting issues
- Bump golangci-lint to v1.55.2
  • Loading branch information
afritzler committed Nov 14, 2023
1 parent f7b1c98 commit 99e55fe
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
version: v1.55.2
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ linters:
- ineffassign
- misspell
- goimports
- ginkgolinter
- importas

severity:
Expand Down
17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ MOCKGEN ?= $(LOCALBIN)/mockgen
## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.13.0
GOLANGCI_LINT_VERSION ?= v1.54.2
VGOPATH_VERSION ?= v0.1.2
CODE_GENERATOR_VERSION ?= v0.28.3
ADDLICENSE_VERSION ?= v1.1.1
GOIMPORTS_VERSION ?= v0.14.0
GEN_CRD_API_REFERENCE_DOCS_VERSION ?= v0.3.0
MOCKGEN_VERSION ?= v0.3.0
GOLANGCI_LINT_VERSION ?= v1.55.2

#########################################
# Rules for local development scenarios #
Expand Down Expand Up @@ -122,11 +122,6 @@ clean: $(CLEAN)
@$(shell find ./example -type f -name "controller-registration.yaml" -exec rm '{}' \;)
$(CLEAN) ./cmd/... ./pkg/...

$(GOLANGCI_LINT): $(call tool_version_file,$(GOLANGCI_LINT),$(GOLANGCI_LINT_VERSION))
@# CGO_ENABLED has to be set to 1 in order for golangci-lint to be able to load plugins
@# see https://github.com/golangci/golangci-lint/issues/1276
GOBIN=$(abspath $(LOCALBIN)) CGO_ENABLED=1 go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: add-license
add-license: addlicense ## Add license headers to all go files.
find . -name '*.go' -exec $(ADDLICENSE) -c 'OnMetal authors' {} +
Expand Down Expand Up @@ -174,8 +169,8 @@ vet: ## Run go vet against code.
go vet ./...

.PHONY: lint
lint: ## Run golangci-lint on the code.
golangci-lint run ./...
lint: golangci-lint ## Run golangci-lint on the code.
$(GOLANGCI_LINT) run ./...

.PHONY: generate-mocks
generate-mocks: mockgen ## Generate code (mocks etc.).
Expand All @@ -184,7 +179,6 @@ generate-mocks: mockgen ## Generate code (mocks etc.).
.PHONY: test
test: generate-mocks fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
go mod tidy

.PHONY: test-clean
test-clean: $(TEST_CLEAN)
Expand Down Expand Up @@ -300,3 +294,8 @@ $(GEN_CRD_API_REFERENCE_DOCS): $(LOCALBIN)
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
$(MOCKGEN): $(LOCALBIN)
test -s $(LOCALBIN)/mockgen || GOBIN=$(LOCALBIN) go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
sigs.k8s.io/yaml v1.4.0
)

replace k8s.io/client-go => k8s.io/client-go v0.28.2
replace k8s.io/client-go => k8s.io/client-go v0.28.3

require (
github.com/BurntSushi/toml v1.0.0 // indirect
Expand Down
12 changes: 3 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -446,7 +445,6 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down Expand Up @@ -501,7 +499,7 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -514,7 +512,6 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -529,7 +526,6 @@ golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -631,7 +627,6 @@ k8s.io/api v0.18.3/go.mod h1:UOaMwERbqJMfeeeHc8XJKawj4P9TgDRnViIqqBeH2QA=
k8s.io/api v0.18.8/go.mod h1:d/CXqwWv+Z2XEG1LgceeDmHQwpUJhROPx16SlxJgERY=
k8s.io/api v0.19.0/go.mod h1:I1K45XlvTrDjmj5LoM5LuP/KYrhWbjUKT/SoPG0qTjw=
k8s.io/api v0.19.6/go.mod h1:Plxx44Nh4zVblkJrIgxVPgPre1mvng6tXf1Sj3bs0fU=
k8s.io/api v0.28.2/go.mod h1:RVnJBsjU8tcMq7C3iaRSGMeaKt2TWEUXcpIt/90fjEg=
k8s.io/api v0.28.3 h1:Gj1HtbSdB4P08C8rs9AR94MfSGpRhJgsS+GF9V26xMM=
k8s.io/api v0.28.3/go.mod h1:MRCV/jr1dW87/qJnZ57U5Pak65LGmQVkKTzf3AtKFHc=
k8s.io/apiextensions-apiserver v0.28.3 h1:Od7DEnhXHnHPZG+W9I97/fSQkVpVPQx2diy+2EtmY08=
Expand All @@ -640,16 +635,15 @@ k8s.io/apimachinery v0.18.3/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCk
k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig=
k8s.io/apimachinery v0.19.0/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
k8s.io/apimachinery v0.19.6/go.mod h1:6sRbGRAVY5DOCuZwB5XkqguBqpqLU6q/kOaOdk29z6Q=
k8s.io/apimachinery v0.28.2/go.mod h1:RdzF87y/ngqk9H4z3EL2Rppv5jj95vGS/HaFXrLDApU=
k8s.io/apimachinery v0.28.3 h1:B1wYx8txOaCQG0HmYF6nbpU8dg6HvA06x5tEffvOe7A=
k8s.io/apimachinery v0.28.3/go.mod h1:uQTKmIqs+rAYaq+DFaoD2X7pcjLOqbQX2AOiO0nIpb8=
k8s.io/apiserver v0.28.3 h1:8Ov47O1cMyeDzTXz0rwcfIIGAP/dP7L8rWbEljRcg5w=
k8s.io/apiserver v0.28.3/go.mod h1:YIpM+9wngNAv8Ctt0rHG4vQuX/I5rvkEMtZtsxW2rNM=
k8s.io/autoscaler/vertical-pod-autoscaler v0.9.0/go.mod h1:PwWTGRRCxefhAezrDbG/tRYSAW7etHjjMPAr8fXKVAA=
k8s.io/autoscaler/vertical-pod-autoscaler v1.0.0 h1:y0TgWoHaeYEv3L1MfLC+D2WVxyN1fGr6axURHXq+wHE=
k8s.io/autoscaler/vertical-pod-autoscaler v1.0.0/go.mod h1:w6/LjLR3DPQd57vlgvgbpzpuJKsCiily0+OzQI+nyfI=
k8s.io/client-go v0.28.2 h1:DNoYI1vGq0slMBN/SWKMZMw0Rq+0EQW6/AK4v9+3VeY=
k8s.io/client-go v0.28.2/go.mod h1:sMkApowspLuc7omj1FOSUxSoqjr+d5Q0Yc0LOFnYFJY=
k8s.io/client-go v0.28.3 h1:2OqNb72ZuTZPKCl+4gTKvqao0AMOl9f3o2ijbAj3LI4=
k8s.io/client-go v0.28.3/go.mod h1:LTykbBp9gsA7SwqirlCXBWtK0guzfhpoW4qSm7i9dxo=
k8s.io/code-generator v0.18.3/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
k8s.io/code-generator v0.19.0/go.mod h1:moqLn7w0t9cMs4+5CQyxnfA/HV8MF6aAVENF+WZZhgk=
k8s.io/component-base v0.18.3/go.mod h1:bp5GzGR0aGkYEfTj+eTY0AN/vXTgkJdQXjNTTVUaa3k=
Expand Down
6 changes: 2 additions & 4 deletions pkg/controller/backupbucket/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var _ = Describe("Backupbucket Reconcile", Ordered, func() {
))

By("ensuring backupbucket is delete successfully")
Expect(k8sClient.Delete(ctx, backupBucket)).To(Succeed())
Expect(k8sClient.Delete(ctx, backupBucket)).Should(Succeed())

By("waiting for the bucket to be gone")
Eventually(Get(bucket)).Should(Satisfy(apierrors.IsNotFound))
Expand All @@ -143,8 +143,6 @@ var _ = Describe("Backupbucket Reconcile", Ordered, func() {

By("validating backupbucketconfig is valid")
config.BucketClassName = "foo"
Expect(validateConfiguration(config)).To(BeNil())

Expect(validateConfiguration(config)).To(Succeed())
})

})
2 changes: 1 addition & 1 deletion pkg/controller/bastion/actuator_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var _ = Describe("Bastion Host Delete", func() {
}}
Expect(k8sClient.Status().Patch(ctx, bastionHost, client.MergeFrom(bastionHostBase))).To(Succeed())

Expect(k8sClient.Delete(ctx, bastion)).To(Succeed())
Expect(k8sClient.Delete(ctx, bastion)).Should(Succeed())

By("waiting for the bastion to be gone")
Eventually(Get(bastion)).Should(Satisfy(apierrors.IsNotFound))
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/bastion/actuator_reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,6 @@ var _ = Describe("Bastion Host Reconcile", func() {
Image: "bar",
}
err = validateConfiguration(bastionConfig)
Expect(err).To(BeNil())
Expect(err).NotTo(HaveOccurred())
})
})
2 changes: 1 addition & 1 deletion pkg/controller/infrastructure/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func SetupTest() *corev1.Namespace {
},
}
Expect(k8sClient.Create(ctx, cluster)).Should(Succeed())
Expect(k8sClient.Delete, cluster)
DeferCleanup(k8sClient.Delete, cluster)

mgr, err := manager.New(cfg, manager.Options{
Scheme: scheme.Scheme,
Expand Down
8 changes: 4 additions & 4 deletions pkg/webhook/controlplane/ensurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ var _ = Describe("Ensurer", func() {

It("should do nothing", func() {
deploymentBefore := deployment.DeepCopy()
Expect(ensurer.EnsureMachineControllerManagerDeployment(ctx, nil, deployment, nil)).To(BeNil())
Expect(ensurer.EnsureMachineControllerManagerDeployment(ctx, nil, deployment, nil)).To(Succeed())
Expect(deployment).To(Equal(deploymentBefore))
})
})
Expand All @@ -267,7 +267,7 @@ var _ = Describe("Ensurer", func() {

It("should inject the sidecar container", func() {
Expect(deployment.Spec.Template.Spec.Containers).To(BeEmpty())
Expect(ensurer.EnsureMachineControllerManagerDeployment(ctx, nil, deployment, nil)).To(BeNil())
Expect(ensurer.EnsureMachineControllerManagerDeployment(ctx, nil, deployment, nil)).To(Succeed())
Expect(deployment.Spec.Template.Spec.Containers).To(ConsistOf(corev1.Container{
Name: "machine-controller-manager-provider-onmetal",
Image: "foo:bar",
Expand Down Expand Up @@ -343,7 +343,7 @@ var _ = Describe("Ensurer", func() {

It("should do nothing", func() {
vpaBefore := vpa.DeepCopy()
Expect(ensurer.EnsureMachineControllerManagerVPA(ctx, nil, vpa, nil)).To(BeNil())
Expect(ensurer.EnsureMachineControllerManagerVPA(ctx, nil, vpa, nil)).To(Succeed())
Expect(vpa).To(Equal(vpaBefore))
})
})
Expand All @@ -355,7 +355,7 @@ var _ = Describe("Ensurer", func() {

It("should inject the sidecar container policy", func() {
Expect(vpa.Spec.ResourcePolicy).To(BeNil())
Expect(ensurer.EnsureMachineControllerManagerVPA(ctx, nil, vpa, nil)).To(BeNil())
Expect(ensurer.EnsureMachineControllerManagerVPA(ctx, nil, vpa, nil)).To(Succeed())

ccv := vpaautoscalingv1.ContainerControlledValuesRequestsOnly
Expect(vpa.Spec.ResourcePolicy.ContainerPolicies).To(ConsistOf(vpaautoscalingv1.ContainerResourcePolicy{
Expand Down

0 comments on commit 99e55fe

Please sign in to comment.