Skip to content

Commit 7bcbe86

Browse files
Merge pull request #835 from simonpasquier/add-golangci-lint
NO-JIRA: add golangci-lint
2 parents 5cc3d0d + f2e2d1d commit 7bcbe86

6 files changed

Lines changed: 52 additions & 20 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ dist/
1414
.devspace
1515
web/po-files/
1616
.claude/commands/configs
17+
_output/

.golangci-lint.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# List of all configuration options at https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml
2+
version: "2"
3+
4+
linters:
5+
settings:
6+
errcheck:
7+
exclude-functions:
8+
- (net/http.ResponseWriter).Write
9+
exclusions:
10+
generated: strict
11+
rules:
12+
# Disable errcheck linter for test files.
13+
- linters:
14+
- errcheck
15+
path: _test.go
16+
17+
formatters:
18+
enable:
19+
- gci
20+
- gofmt
21+
settings:
22+
gci:
23+
sections:
24+
- standard
25+
- default
26+
- prefix(github.com/openshift/monitoring-plugin)

Makefile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PLUGIN_NAME ?=monitoring-plugin
55
IMAGE ?= quay.io/${ORG}/${PLUGIN_NAME}:${VERSION}
66
FEATURES ?=incidents,perses-dashboards,dev-config
77

8+
GOLANGCI_LINT = $(shell pwd)/_output/tools/bin/golangci-lint
9+
GOLANGCI_LINT_VERSION ?= v2.11.3
10+
811
export NODE_OPTIONS?=--max_old_space_size=4096
912

1013
.PHONY: install-frontend
@@ -39,12 +42,6 @@ i18n-frontend:
3942
lint-frontend:
4043
cd web && npm run lint
4144

42-
.PHONY: lint-backend
43-
lint-backend:
44-
go mod tidy
45-
go fmt ./cmd/
46-
go fmt ./pkg/
47-
4845
.PHONY: install-backend
4946
install-backend:
5047
go mod download
@@ -69,7 +66,6 @@ test-frontend:
6966
build-image:
7067
./scripts/build-image.sh
7168

72-
7369
.PHONY: install
7470
install:
7571
make install-frontend && make install-backend
@@ -79,8 +75,7 @@ update-plugin-name:
7975
./scripts/update-plugin-name.sh
8076

8177
.PHONY: deploy
82-
deploy:
83-
make lint-backend
78+
deploy: lint-backend
8479
PUSH=1 scripts/build-image.sh
8580
helm uninstall $(PLUGIN_NAME) -n $(PLUGIN_NAME)-ns || true
8681
helm install $(PLUGIN_NAME) charts/openshift-console-plugin -n monitoring-plugin-ns --create-namespace --set plugin.image=$(IMAGE)
@@ -89,6 +84,19 @@ deploy:
8984
deploy-acm:
9085
./scripts/deploy-acm.sh
9186

87+
# Download and install golangci-lint if not already installed
88+
.PHONY: golangci-lint
89+
golangci-lint:
90+
@[ -f $(GOLANGCI_LINT) ] || { \
91+
set -e ;\
92+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
93+
}
94+
95+
.PHONY: lint-backend
96+
lint-backend: golangci-lint
97+
go mod tidy
98+
$(GOLANGCI_LINT) -c $(shell pwd)/.golangci-lint.yaml run --verbose
99+
92100
.PHONY: build-mcp-image
93101
build-mcp-image:
94102
DOCKER_FILE_NAME="Dockerfile.mcp" REPO="monitoring-console-plugin" scripts/build-image.sh

cmd/plugin-backend.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"strconv"
99
"strings"
1010

11-
server "github.com/openshift/monitoring-plugin/pkg"
1211
"github.com/sirupsen/logrus"
12+
13+
server "github.com/openshift/monitoring-plugin/pkg"
1314
)
1415

1516
var (

pkg/proxy/proxy.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ func getProxy(kind KindType, proxyUrlString string, serviceCAfile string) (*http
130130
return proxy, nil
131131
}
132132

133-
func handleError(w http.ResponseWriter, code int, err error) {
134-
log.Error(err)
135-
http.Error(w, err.Error(), code)
136-
}
137-
138133
func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
139134
h.proxy.ServeHTTP(w, r)
140135
}

pkg/server.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/gorilla/handlers"
1414
"github.com/gorilla/mux"
15-
"github.com/openshift/monitoring-plugin/pkg/proxy"
1615
"github.com/sirupsen/logrus"
1716
"gopkg.in/yaml.v2"
1817
v1 "k8s.io/api/core/v1"
@@ -21,6 +20,8 @@ import (
2120
"k8s.io/client-go/kubernetes/scheme"
2221
"k8s.io/client-go/rest"
2322
"k8s.io/client-go/tools/record"
23+
24+
"github.com/openshift/monitoring-plugin/pkg/proxy"
2425
)
2526

2627
var log = logrus.WithField("module", "server")
@@ -88,11 +89,11 @@ func CreateServer(ctx context.Context, cfg *Config) (*PluginServer, error) {
8889

8990
func (s *PluginServer) StartHTTPServer() error {
9091
if s.Config.IsTLSEnabled() {
91-
log.Infof("listening for https on %s", s.Server.Addr)
92-
return s.Server.ListenAndServeTLS(s.Config.CertFile, s.Config.PrivateKeyFile)
92+
log.Infof("listening for https on %s", s.Addr)
93+
return s.ListenAndServeTLS(s.Config.CertFile, s.Config.PrivateKeyFile)
9394
}
94-
log.Infof("listening for http on %s", s.Server.Addr)
95-
return s.Server.ListenAndServe()
95+
log.Infof("listening for http on %s", s.Addr)
96+
return s.ListenAndServe()
9697
}
9798

9899
func (s *PluginServer) Shutdown(ctx context.Context) error {

0 commit comments

Comments
 (0)