mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-02-14 09:59:56 +00:00
enable linter on repository
This commit is contained in:
15
.github/workflows/lint.yml
vendored
Normal file
15
.github/workflows/lint.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: golangci-lint
|
||||
on:
|
||||
pull_request:
|
||||
jobs:
|
||||
golangci:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.24
|
||||
- name: golangci-lint
|
||||
run: make lint
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
/bin/
|
||||
.bin
|
||||
/test/bin/
|
||||
/*.tar.gz*
|
||||
ci.env
|
||||
|
||||
27
.golangci.yml
Normal file
27
.golangci.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
version: "2"
|
||||
run:
|
||||
tests: true
|
||||
# build-tags:
|
||||
# - journald
|
||||
linters:
|
||||
default: none
|
||||
enable:
|
||||
- ineffassign
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- vendor
|
||||
- third_party
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
issues:
|
||||
max-issues-per-linter: 0
|
||||
max-same-issues: 0
|
||||
formatters:
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
@@ -4,7 +4,7 @@ repos:
|
||||
hooks:
|
||||
- id: gitleaks
|
||||
- repo: https://github.com/golangci/golangci-lint
|
||||
rev: v1.52.2
|
||||
rev: v2.3.1
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
- repo: https://github.com/jumanjihouse/pre-commit-hooks
|
||||
|
||||
14
Makefile
14
Makefile
@@ -15,7 +15,7 @@
|
||||
# Build the node-problem-detector image.
|
||||
|
||||
.PHONY: all \
|
||||
vet fmt version test e2e-test \
|
||||
lint vet fmt version test e2e-test \
|
||||
build-binaries build-container build-tar build \
|
||||
docker-builder build-in-docker \
|
||||
push-container push-tar push release clean depup \
|
||||
@@ -113,6 +113,18 @@ else
|
||||
LOGCOUNTER=*dont-include-log-counter
|
||||
endif
|
||||
|
||||
GOLANGCI_LINT_VERSION := v2.2.0
|
||||
GOLANGCI_LINT := ./.bin/golangci-lint
|
||||
|
||||
lint: $(GOLANGCI_LINT)
|
||||
$(GOLANGCI_LINT) run --config .golangci.yml ./...
|
||||
|
||||
$(GOLANGCI_LINT):
|
||||
@echo "golangci-lint not found, downloading..."
|
||||
@mkdir -p ./.bin
|
||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./.bin $(GOLANGCI_LINT_VERSION)
|
||||
|
||||
|
||||
vet:
|
||||
go list -tags "$(HOST_PLATFORM_BUILD_TAGS)" ./... | \
|
||||
grep -v "./vendor/*" | \
|
||||
|
||||
@@ -14,8 +14,10 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package types contains the types for log counter.
|
||||
package types
|
||||
|
||||
// LogCounter is the interface for a log counter.
|
||||
type LogCounter interface {
|
||||
Count() (int, error)
|
||||
}
|
||||
|
||||
@@ -62,6 +62,10 @@ func (cc *cpuCollector) recordSystemStats() {
|
||||
}
|
||||
|
||||
fs, err := procfs.NewFS(cc.procPath)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to open procfs: %v", err)
|
||||
return
|
||||
}
|
||||
stats, err := fs.Stat()
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to retrieve cpu/process stats: %v", err)
|
||||
|
||||
@@ -219,6 +219,10 @@ func (nc *netCollector) mustRegisterMetric(metricID metrics.MetricID, descriptio
|
||||
|
||||
func (nc *netCollector) recordNetDev() {
|
||||
fs, err := procfs.NewFS(nc.procPath)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to open procfs: %v", err)
|
||||
return
|
||||
}
|
||||
stats, err := fs.NetDev()
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to retrieve net dev stat: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user