Skip to content

Commit 4f843ea

Browse files
authored
Merge pull request #1 from gianlucam76/init
K8s collector
2 parents 2fe33d0 + 813404b commit 4f843ea

28 files changed

+2322
-2
lines changed

.github/workflows/main.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: main
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'dev'
8+
pull_request:
9+
types: [opened, edited, synchronize, reopened]
10+
11+
12+
jobs:
13+
build-static-test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: checkout
17+
uses: actions/checkout@v4
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: 1.20.8
22+
- name: Build
23+
run: make build
24+
- name: FMT
25+
run: make fmt
26+
- name: VET
27+
run: make vet
28+
- name: LINT
29+
run: make lint
30+
env:
31+
LINT: true
32+
build-ut:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: checkout
36+
uses: actions/checkout@v4
37+
- name: Set up Go
38+
uses: actions/setup-go@v4
39+
with:
40+
go-version: 1.20.8
41+
- name: ut
42+
run: make test
43+
env:
44+
UT: true
45+
FV:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: checkout
49+
uses: actions/checkout@v4
50+
- name: Set up Go
51+
uses: actions/setup-go@v4
52+
with:
53+
go-version: 1.20.8
54+
- name: fv
55+
run: make create-cluster fv
56+
env:
57+
FV: true
58+

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111
# Test binary, built with `go test -c`
1212
*.test
1313

14+
# vim files
15+
*.swp
16+
1417
# Output of the go coverage tool, specifically when used with LiteIDE
1518
*.out
1619

20+
# Needed tools
21+
hack/tools/bin/
22+
1723
# Dependency directories (remove the comment below to include it)
1824
# vendor/
1925

.golangci.yaml

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
linters-settings:
2+
depguard:
3+
list-type: blacklist
4+
packages:
5+
# Following logging implementations are allowed:
6+
# k8s.io/klog
7+
# go.uber.org/zap
8+
# go-logr/logr
9+
#
10+
# note that the following list will grow.
11+
- github.com/google/glog
12+
- log
13+
- github.com/sirupsen/logrus
14+
- github.com/wojas/genericr
15+
- logfmt
16+
packages-with-error-message:
17+
- github.com/google/glog: "Use klog, zap, or logr for logging."
18+
- log: "Use klog, zap, or logr for logging."
19+
- github.com/sirupsen/logrus: "Use klog, zap, or logr for logging."
20+
- github.com/wojas/genericr: "Use klog, zap, or logr for logging."
21+
- logfmt: "Use klog, zap, or logr for logging."
22+
dupl:
23+
threshold: 200
24+
errorlint:
25+
# Use '%w' to format errors.
26+
errorf: true
27+
exhaustive:
28+
# Ignore auto-generated code.
29+
check-generated: false
30+
default-signifies-exhaustive: false
31+
forbidigo:
32+
forbid:
33+
# Forbid 'fmt.Print[|f|ln]() in shipping code.
34+
- 'fmt\.Print.*'
35+
funlen:
36+
lines: 100
37+
statements: 50
38+
goconst:
39+
min-len: 2
40+
min-occurrences: 2
41+
gocritic:
42+
enabled-tags:
43+
- diagnostic
44+
- experimental
45+
- opinionated
46+
- performance
47+
- style
48+
disabled-checks:
49+
- dupImport # https://github.com/go-critic/go-critic/issues/845
50+
- ifElseChain
51+
- octalLiteral
52+
- whyNoLint # conflicts with nolintlint config providing superset functionality
53+
- wrapperFunc
54+
gocyclo:
55+
min-complexity: 20
56+
goimports:
57+
local-prefixes: github.com/projectsveltos
58+
gomnd:
59+
settings:
60+
mnd:
61+
# don't include the "operation" and "assign"
62+
checks: argument,case,condition,return
63+
gomodguard:
64+
# Although this is almost empty, we will evolve the list below with the
65+
# modules we shouldn't use for technical and/or security reasons.
66+
blocked:
67+
modules:
68+
- k8s.io/kubernetes:
69+
reason: "There is no good, avoidable reason to use this package and often leads to issues such as https://bit.ly/3dlKScY. However, if you disagree please include @ravchama in code review highlighting the reason."
70+
versions:
71+
# Don't merge replace directives using local path.
72+
local_replace_directives: true
73+
govet:
74+
check-shadowing: true
75+
settings:
76+
printf:
77+
funcs:
78+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
79+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
80+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
81+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
82+
grouper:
83+
const-require-grouping: true
84+
import-require-single-import: true
85+
import-require-grouping: true
86+
var-require-grouping: true
87+
lll:
88+
line-length: 160
89+
maintidx:
90+
# check https://bit.ly/3tlJX3n for maintainability index.
91+
##
92+
# starting with 25 to begin with, with the plan to bump it to 40 eventuallly.
93+
##
94+
under: 25
95+
misspell:
96+
locale: US
97+
nolintlint:
98+
allow-unused: false # report any unused nolint directives
99+
require-explanation: true # require an explanation for nolint directives
100+
require-specific: true # require nolint directives to be specific about which linter is being skipped
101+
revive:
102+
ignore-generated-header: true
103+
# this is a new linter, so let's start with Warning instead of errors to
104+
# begin with.
105+
severity: warning
106+
whitespace:
107+
multi-if: true
108+
multi-func: true
109+
110+
linters:
111+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
112+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
113+
disable-all: true
114+
fast: false
115+
enable:
116+
- bidichk
117+
- containedctx
118+
- bodyclose
119+
- depguard
120+
- dogsled
121+
- dupl
122+
- durationcheck
123+
- errcheck
124+
- errname
125+
- errorlint
126+
- exhaustive
127+
- exportloopref
128+
- forbidigo
129+
- funlen
130+
- goconst
131+
- gocritic
132+
- gocyclo
133+
- gofmt
134+
- goimports
135+
- gomnd
136+
- gomodguard
137+
- goprintffuncname
138+
- gosec
139+
- gosimple
140+
- govet
141+
- grouper
142+
- ineffassign
143+
- lll
144+
- misspell
145+
- maintidx
146+
- nakedret
147+
- noctx
148+
- nolintlint
149+
- nosprintfhostport
150+
- predeclared
151+
- revive
152+
- staticcheck
153+
- typecheck
154+
- unconvert
155+
- unparam
156+
- unused
157+
- whitespace
158+
159+
# don't enable:
160+
# - asciicheck
161+
# - exhaustivestruct # applicable to special cases.
162+
# - gochecknoglobals
163+
# - gocognit
164+
# - godot
165+
# - godox
166+
# - goerr113
167+
# - golint # deprecated
168+
# - interfacer # deprecated
169+
# - maligned #deprecated
170+
# - nestif
171+
# - prealloc
172+
# - scopelint # deprecated
173+
# - testpackage
174+
# - wsl
175+
176+
issues:
177+
# Excluding configuration per path, per linter, per text and per-source
178+
exclude-rules:
179+
- path: _test\.go
180+
linters:
181+
- gomnd
182+
- grouper
183+
- maintidx
184+
185+
# https://github.com/go-critic/go-critic/issues/926
186+
- linters:
187+
- gocritic
188+
text: "unnecessaryDefer:"
189+
# Maximum issues count per one linter.
190+
# Set to 0 to disable.
191+
max-issues-per-linter: 0
192+
# Maximum count of issues with the same text.
193+
# Set to 0 to disable.
194+
max-same-issues: 0
195+
196+
run:
197+
# Allow multiple parallel golangci-lint instances running.
198+
allow-parallel-runners: true
199+
# Timeout for analysis
200+
timeout: 5m
201+
# files to skip: they will be analyzed, but issues from them won't be reported.
202+
skip-dirs:
203+
- cmd/example/gen

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build the manager binary
2+
FROM golang:1.20 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY cmd/ cmd
14+
COPY pkg/ pkg/
15+
16+
# Build
17+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o k8s-collector cmd/main.go
18+
19+
# Use distroless as minimal base image to package the manager binary
20+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
21+
FROM gcr.io/distroless/static:nonroot
22+
WORKDIR /
23+
COPY --from=builder /workspace/k8s-collector .
24+
USER nonroot:nonroot
25+
26+
ENTRYPOINT ["/k8s-collector"]
27+

0 commit comments

Comments
 (0)