Skip to content

Commit fb3c86a

Browse files
committed
Added Contextual Logging check by logcheck
1 parent ef47f0f commit fb3c86a

File tree

8 files changed

+1256
-3
lines changed

8 files changed

+1256
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor
22
Gopkg.toml
33
Gopkg.lock
44
**/*.pyc
5+
hack/tools/bin

.golangci.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
run:
2+
timeout: 30m
3+
4+
output:
5+
sort-results: true
6+
7+
issues:
8+
max-issues-per-linter: 0
9+
max-same-issues: 0
10+
linters:
11+
disable-all: true
12+
enable: # please keep this alphabetized
13+
- logcheck
14+
15+
linters-settings: # please keep this alphabetized
16+
custom:
17+
logcheck:
18+
# Installed there by Makefile.
19+
path: hack/tools/bin/logcheck.so
20+
description: structured logging checker
21+
original-url: k8s.io/logtools/logcheck

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,24 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
all: verify test
15+
GOBIN=$(shell pwd)/hack/tools/bin
16+
17+
all: install-tools verify golangci-lint test
1618

1719
dep:
1820
go mod tidy
21+
cd hack/tools && go mod tidy
22+
23+
install-tools: $(GOBIN)
24+
cd hack/tools \
25+
&& GOBIN=$(GOBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint \
26+
&& go build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin
27+
28+
$(GOBIN):
29+
mkdir $@
30+
31+
golangci-lint:
32+
LOGCHECK_CONFIG="hack/logcheck.conf" "${GOBIN}/golangci-lint" run
1933

2034
verify: dep
2135
# todo gometalinter is DEPRECATED, Use https://github.com/golangci/golangci-lint

controller/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ func (ctrl *ProvisionController) rescheduleProvisioning(ctx context.Context, cla
13761376
func (ctrl *ProvisionController) provisionClaimOperation(ctx context.Context, claim *v1.PersistentVolumeClaim) (ProvisioningState, error) {
13771377
// Most code here is identical to that found in controller.go of kube's PV controller...
13781378
claimClass := util.GetPersistentVolumeClaimClass(claim)
1379-
logger := klog.FromContext(ctx).WithValues("PVC", klog.KObj(claim), "StorageClass", claimClass)
1379+
logger := klog.LoggerWithValues(klog.FromContext(ctx), "PVC", klog.KObj(claim), "StorageClass", claimClass)
13801380
logger.Info("Started")
13811381

13821382
// A previous doProvisionClaim may just have finished while we were waiting for
@@ -1522,7 +1522,7 @@ func (ctrl *ProvisionController) provisionVolumeErrorHandling(ctx context.Contex
15221522
// volume. Returns error, which indicates whether deletion should be retried
15231523
// (requeue the volume) or not
15241524
func (ctrl *ProvisionController) deleteVolumeOperation(ctx context.Context, volume *v1.PersistentVolume) error {
1525-
logger := klog.FromContext(ctx).WithValues("PV", volume.Name)
1525+
logger := klog.LoggerWithValues(klog.FromContext(ctx), "PV", volume.Name)
15261526
logger.Info("Started")
15271527

15281528
err := ctrl.provisioner.Delete(ctx, volume)

hack/logcheck.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# At this point we don't enforce the usage structured logging calls except in
2+
# those packages that were migrated. This disables the check for other files.
3+
# -structured .*
4+
5+
# Now enable it again for migrated packages.
6+
# structured .*
7+
8+
# The following packages have been migrated to contextual logging.
9+
# Packages matched here do not have to be listed above because
10+
# "contextual" implies "structured".
11+
# TODO next: contextual k8s.io/kubernetes/pkg/scheduler/.*
12+
# A few files involved in startup migrated already to contextual
13+
# We can't enable contextual logcheck until all are migrated
14+
contextual .*
15+
16+
# As long as contextual logging is alpha or beta, all WithName, WithValues,
17+
# NewContext calls have to go through klog. Once it is GA, we can lift
18+
# this restriction. Whether we then do a global search/replace remains
19+
# to be decided.
20+
with-helpers .*

hack/tools/go.mod

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
module sigs.k8s.io/sig-storage-lib-external-provisioner/v9/hack/tools
2+
3+
go 1.19
4+
5+
require (
6+
github.com/golangci/golangci-lint v1.54.1
7+
sigs.k8s.io/logtools v0.7.0
8+
)
9+
10+
require (
11+
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
12+
4d63.com/gochecknoglobals v0.2.1 // indirect
13+
github.com/4meepo/tagalign v1.3.2 // indirect
14+
github.com/Abirdcfly/dupword v0.0.12 // indirect
15+
github.com/Antonboom/errname v0.1.10 // indirect
16+
github.com/Antonboom/nilnil v0.1.5 // indirect
17+
github.com/BurntSushi/toml v1.3.2 // indirect
18+
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
19+
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.1.0 // indirect
20+
github.com/Masterminds/semver v1.5.0 // indirect
21+
github.com/OpenPeeDeeP/depguard/v2 v2.1.0 // indirect
22+
github.com/alexkohler/nakedret/v2 v2.0.2 // indirect
23+
github.com/alexkohler/prealloc v1.0.0 // indirect
24+
github.com/alingse/asasalint v0.0.11 // indirect
25+
github.com/ashanbrown/forbidigo v1.6.0 // indirect
26+
github.com/ashanbrown/makezero v1.1.1 // indirect
27+
github.com/beorn7/perks v1.0.1 // indirect
28+
github.com/bkielbasa/cyclop v1.2.1 // indirect
29+
github.com/blizzy78/varnamelen v0.8.0 // indirect
30+
github.com/bombsimon/wsl/v3 v3.4.0 // indirect
31+
github.com/breml/bidichk v0.2.4 // indirect
32+
github.com/breml/errchkjson v0.3.1 // indirect
33+
github.com/butuzov/ireturn v0.2.0 // indirect
34+
github.com/butuzov/mirror v1.1.0 // indirect
35+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
36+
github.com/charithe/durationcheck v0.0.10 // indirect
37+
github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8 // indirect
38+
github.com/curioswitch/go-reassign v0.2.0 // indirect
39+
github.com/daixiang0/gci v0.11.0 // indirect
40+
github.com/davecgh/go-spew v1.1.1 // indirect
41+
github.com/denis-tingaikin/go-header v0.4.3 // indirect
42+
github.com/esimonov/ifshort v1.0.4 // indirect
43+
github.com/ettle/strcase v0.1.1 // indirect
44+
github.com/fatih/color v1.15.0 // indirect
45+
github.com/fatih/structtag v1.2.0 // indirect
46+
github.com/firefart/nonamedreturns v1.0.4 // indirect
47+
github.com/fsnotify/fsnotify v1.5.4 // indirect
48+
github.com/fzipp/gocyclo v0.6.0 // indirect
49+
github.com/go-critic/go-critic v0.9.0 // indirect
50+
github.com/go-toolsmith/astcast v1.1.0 // indirect
51+
github.com/go-toolsmith/astcopy v1.1.0 // indirect
52+
github.com/go-toolsmith/astequal v1.1.0 // indirect
53+
github.com/go-toolsmith/astfmt v1.1.0 // indirect
54+
github.com/go-toolsmith/astp v1.1.0 // indirect
55+
github.com/go-toolsmith/strparse v1.1.0 // indirect
56+
github.com/go-toolsmith/typep v1.1.0 // indirect
57+
github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect
58+
github.com/gobwas/glob v0.2.3 // indirect
59+
github.com/gofrs/flock v0.8.1 // indirect
60+
github.com/golang/protobuf v1.5.2 // indirect
61+
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 // indirect
62+
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect
63+
github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe // indirect
64+
github.com/golangci/gofmt v0.0.0-20220901101216-f2edd75033f2 // indirect
65+
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 // indirect
66+
github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca // indirect
67+
github.com/golangci/misspell v0.4.1 // indirect
68+
github.com/golangci/revgrep v0.0.0-20220804021717-745bb2f7c2e6 // indirect
69+
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 // indirect
70+
github.com/google/go-cmp v0.5.9 // indirect
71+
github.com/gordonklaus/ineffassign v0.0.0-20230610083614-0e73809eb601 // indirect
72+
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
73+
github.com/gostaticanalysis/comment v1.4.2 // indirect
74+
github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect
75+
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
76+
github.com/hashicorp/errwrap v1.0.0 // indirect
77+
github.com/hashicorp/go-multierror v1.1.1 // indirect
78+
github.com/hashicorp/go-version v1.6.0 // indirect
79+
github.com/hashicorp/hcl v1.0.0 // indirect
80+
github.com/hexops/gotextdiff v1.0.3 // indirect
81+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
82+
github.com/jgautheron/goconst v1.5.1 // indirect
83+
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
84+
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
85+
github.com/julz/importas v0.1.0 // indirect
86+
github.com/kisielk/errcheck v1.6.3 // indirect
87+
github.com/kisielk/gotool v1.0.0 // indirect
88+
github.com/kkHAIKE/contextcheck v1.1.4 // indirect
89+
github.com/kulti/thelper v0.6.3 // indirect
90+
github.com/kunwardeep/paralleltest v1.0.8 // indirect
91+
github.com/kyoh86/exportloopref v0.1.11 // indirect
92+
github.com/ldez/gomoddirectives v0.2.3 // indirect
93+
github.com/ldez/tagliatelle v0.5.0 // indirect
94+
github.com/leonklingele/grouper v1.1.1 // indirect
95+
github.com/lufeee/execinquery v1.2.1 // indirect
96+
github.com/magiconair/properties v1.8.6 // indirect
97+
github.com/maratori/testableexamples v1.0.0 // indirect
98+
github.com/maratori/testpackage v1.1.1 // indirect
99+
github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 // indirect
100+
github.com/mattn/go-colorable v0.1.13 // indirect
101+
github.com/mattn/go-isatty v0.0.17 // indirect
102+
github.com/mattn/go-runewidth v0.0.9 // indirect
103+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
104+
github.com/mbilski/exhaustivestruct v1.2.0 // indirect
105+
github.com/mgechev/revive v1.3.2 // indirect
106+
github.com/mitchellh/go-homedir v1.1.0 // indirect
107+
github.com/mitchellh/mapstructure v1.5.0 // indirect
108+
github.com/moricho/tparallel v0.3.1 // indirect
109+
github.com/nakabonne/nestif v0.3.1 // indirect
110+
github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354 // indirect
111+
github.com/nishanths/exhaustive v0.11.0 // indirect
112+
github.com/nishanths/predeclared v0.2.2 // indirect
113+
github.com/nunnatsa/ginkgolinter v0.13.3 // indirect
114+
github.com/olekukonko/tablewriter v0.0.5 // indirect
115+
github.com/pelletier/go-toml v1.9.5 // indirect
116+
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
117+
github.com/pmezard/go-difflib v1.0.0 // indirect
118+
github.com/polyfloyd/go-errorlint v1.4.3 // indirect
119+
github.com/prometheus/client_golang v1.12.1 // indirect
120+
github.com/prometheus/client_model v0.2.0 // indirect
121+
github.com/prometheus/common v0.32.1 // indirect
122+
github.com/prometheus/procfs v0.7.3 // indirect
123+
github.com/quasilyte/go-ruleguard v0.4.0 // indirect
124+
github.com/quasilyte/gogrep v0.5.0 // indirect
125+
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
126+
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
127+
github.com/ryancurrah/gomodguard v1.3.0 // indirect
128+
github.com/ryanrolds/sqlclosecheck v0.4.0 // indirect
129+
github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect
130+
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
131+
github.com/sashamelentyev/usestdlibvars v1.23.0 // indirect
132+
github.com/securego/gosec/v2 v2.16.0 // indirect
133+
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
134+
github.com/sirupsen/logrus v1.9.3 // indirect
135+
github.com/sivchari/containedctx v1.0.3 // indirect
136+
github.com/sivchari/nosnakecase v1.7.0 // indirect
137+
github.com/sivchari/tenv v1.7.1 // indirect
138+
github.com/sonatard/noctx v0.0.2 // indirect
139+
github.com/sourcegraph/go-diff v0.7.0 // indirect
140+
github.com/spf13/afero v1.8.2 // indirect
141+
github.com/spf13/cast v1.5.0 // indirect
142+
github.com/spf13/cobra v1.7.0 // indirect
143+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
144+
github.com/spf13/pflag v1.0.5 // indirect
145+
github.com/spf13/viper v1.12.0 // indirect
146+
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
147+
github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
148+
github.com/stretchr/objx v0.5.0 // indirect
149+
github.com/stretchr/testify v1.8.4 // indirect
150+
github.com/subosito/gotenv v1.4.1 // indirect
151+
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
152+
github.com/tdakkota/asciicheck v0.2.0 // indirect
153+
github.com/tetafro/godot v1.4.11 // indirect
154+
github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 // indirect
155+
github.com/timonwong/loggercheck v0.9.4 // indirect
156+
github.com/tomarrell/wrapcheck/v2 v2.8.1 // indirect
157+
github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
158+
github.com/ultraware/funlen v0.1.0 // indirect
159+
github.com/ultraware/whitespace v0.0.5 // indirect
160+
github.com/uudashr/gocognit v1.0.7 // indirect
161+
github.com/xen0n/gosmopolitan v1.2.1 // indirect
162+
github.com/yagipy/maintidx v1.0.0 // indirect
163+
github.com/yeya24/promlinter v0.2.0 // indirect
164+
github.com/ykadowak/zerologlint v0.1.3 // indirect
165+
gitlab.com/bosi/decorder v0.4.0 // indirect
166+
go.tmz.dev/musttag v0.7.1 // indirect
167+
go.uber.org/atomic v1.7.0 // indirect
168+
go.uber.org/multierr v1.6.0 // indirect
169+
go.uber.org/zap v1.24.0 // indirect
170+
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de // indirect
171+
golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 // indirect
172+
golang.org/x/mod v0.12.0 // indirect
173+
golang.org/x/sync v0.3.0 // indirect
174+
golang.org/x/sys v0.11.0 // indirect
175+
golang.org/x/text v0.12.0 // indirect
176+
golang.org/x/tools v0.12.0 // indirect
177+
google.golang.org/protobuf v1.28.0 // indirect
178+
gopkg.in/ini.v1 v1.67.0 // indirect
179+
gopkg.in/yaml.v2 v2.4.0 // indirect
180+
gopkg.in/yaml.v3 v3.0.1 // indirect
181+
honnef.co/go/tools v0.4.3 // indirect
182+
mvdan.cc/gofumpt v0.5.0 // indirect
183+
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed // indirect
184+
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect
185+
mvdan.cc/unparam v0.0.0-20221223090309-7455f1af531d // indirect
186+
)

0 commit comments

Comments
 (0)