Skip to content

Commit

Permalink
Add revive to golanci
Browse files Browse the repository at this point in the history
This PR replace deprecated go-linter using
revive (https://golangci-lint.run/usage/linters/#revive).

We will add "ginkgolinter" in follow up patch once we merged add pre-commit job in openshift/releases.

If we add "ginkgolinter" in this patch then it's causes below issue [1]

```
level=info msg="[config_reader] Config search paths: [./ /home/prow/go/src/github.com/openstack-k8s-operators/dataplane-operator /home/prow/go/src/github.com/openstack-k8s-operators /home/prow/go/src/github.com /home/prow/go/src /home/prow/go /home/prow /home /]"
level=info msg="[config_reader] Used config file .golangci.yaml"
level=error msg="Running error: unknown linters: 'ginkgolinter', run 'golangci-lint help linters' to see the list of supported linters"
```

This patch also Remove fmt dependency from make tidy as per [2]:

The fmt dependency cannot be run if the go.mod file needs an update:
```
 $ make tidy
 go fmt ./...
 go: updates to go.mod needed; to update it:
        go mod tidy
 make: *** [Makefile:103: fmt] Error 1
```

I have also made some changes as per the comment given here [3]

[1]: https://gcsweb-ci.apps.ci.l2s4.p1.openshiftapps.com/gcs/origin-ci-test/pr-logs/pull/openstack-k8s-operators_dataplane-operator/147/pull-ci-openstack-k8s-operators-dataplane-operator-main-golangci/1643555465537261568/artifacts/test/build-log.txt
[2]: openstack-k8s-operators/placement-operator#153
[3]: openstack-k8s-operators/cinder-operator#147 (comment)
  • Loading branch information
bshewale committed Apr 19, 2023
1 parent b5843d9 commit 64c0cd6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
17 changes: 17 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
linters:
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- errorlint
- revive
- gofmt
- govet
linters-settings:
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: true
run:
timeout: 5m
25 changes: 6 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@ repos:

- repo: local
hooks:
- id: golangci-lint
name: golangci-lint
language: golang
types: [go]
entry: make
args: ["golangci-lint"]
pass_filenames: false
- id: gofmt
name: gofmt
language: system
entry: make
args: ["fmt"]
pass_filenames: false
- id: govet
name: govet
language: system
entry: make
args: ["vet"]
pass_filenames: false
- id: gotidy
name: gotidy
language: system
Expand Down Expand Up @@ -84,3 +65,9 @@ repos:
# error will be discovered in execution anyway)
# E020: Function declaration not in format ^function name {$
# E012: here doc didn't end before EOF

- repo: https://github.com/golangci/golangci-lint
rev: v1.52.2
hooks:
- id: golangci-lint
args: ["-v"]
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,10 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

APIPATH ?= $(shell pwd)/api
.PHONY: tidy
tidy: ## Run go mod tidy on every mod file in the repo
go mod tidy; \
pushd $(APIPATH); \
go mod tidy; \
popd
go mod tidy
cd ./api && go mod tidy

.PHONY: golangci-lint
golangci-lint:
Expand Down
4 changes: 3 additions & 1 deletion pkg/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"io"

"errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -125,7 +126,8 @@ func PodExec(
Stderr: &stderr,
})
if err != nil {
if exitError, ok := err.(exec.ExitError); ok {
var exitError exec.ExitError
if errors.As(err, &exitError) {
result.ExitStatus = exitError.ExitStatus()
} else {
return nil, fmt.Errorf("Executing remote command: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ovndbcluster/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func StatefulSet(
ownerRef := metav1.NewControllerRef(instance, instance.GroupVersionKind())
ownerRef.BlockOwnerDeletion = &blockOwnerDeletion
statefulset.Spec.VolumeClaimTemplates = []corev1.PersistentVolumeClaim{
corev1.PersistentVolumeClaim{
{
ObjectMeta: metav1.ObjectMeta{
Name: instance.Name + PvcSuffixEtcOvn,
Namespace: instance.Namespace,
Expand Down

0 comments on commit 64c0cd6

Please sign in to comment.