Skip to content

Commit d16fa68

Browse files
committedJan 17, 2023
Enable more linters
Signed-off-by: Vince Prignano <vincepri@redhat.com>
1 parent e1fd8e7 commit d16fa68

File tree

8 files changed

+24
-11
lines changed

8 files changed

+24
-11
lines changed
 

‎.golangci.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
linters:
22
disable-all: true
33
enable:
4+
- asasalint
45
- asciicheck
6+
- bidichk
57
- bodyclose
68
- depguard
79
- dogsled
10+
- dupl
811
- errcheck
12+
- errchkjson
913
- errorlint
14+
- exhaustive
1015
- exportloopref
1116
- goconst
1217
- gocritic
@@ -19,15 +24,16 @@ linters:
1924
- govet
2025
- importas
2126
- ineffassign
27+
- makezero
2228
- misspell
2329
- nakedret
2430
- nilerr
2531
- nolintlint
2632
- prealloc
2733
- revive
28-
- rowserrcheck
2934
- staticcheck
3035
- stylecheck
36+
- tagliatelle
3137
- typecheck
3238
- unconvert
3339
- unparam
@@ -127,6 +133,9 @@ issues:
127133
- linters:
128134
- revive
129135
text: "package-comments: should have a package comment"
136+
- linters:
137+
- dupl
138+
path: _test\.go
130139

131140
run:
132141
timeout: 10m

‎example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (a *ReplicaSetReconciler) Reconcile(ctx context.Context, req ctrl.Request)
138138

139139
// Update the ReplicaSet
140140
rs.Labels["pod-count"] = fmt.Sprintf("%v", len(pods.Items))
141-
err = a.Update(context.TODO(), rs)
141+
err = a.Update(ctx, rs)
142142
if err != nil {
143143
return ctrl.Result{}, err
144144
}

‎pkg/builder/controller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
634634
},
635635
},
636636
}
637-
err := mgr.GetClient().Create(context.TODO(), dep)
637+
err := mgr.GetClient().Create(ctx, dep)
638638
Expect(err).NotTo(HaveOccurred())
639639

640640
By("Waiting for the Deployment Reconcile")
@@ -664,7 +664,7 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
664664
Template: dep.Spec.Template,
665665
},
666666
}
667-
err = mgr.GetClient().Create(context.TODO(), rs)
667+
err = mgr.GetClient().Create(ctx, rs)
668668
Expect(err).NotTo(HaveOccurred())
669669

670670
By("Waiting for the ReplicaSet Reconcile")

‎pkg/certwatcher/example_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ func Example() {
6464
// Start goroutine for handling server shutdown.
6565
go func() {
6666
<-ctx.Done()
67-
if err := srv.Shutdown(context.Background()); err != nil {
67+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
68+
defer cancel()
69+
if err := srv.Shutdown(ctx); err != nil {
6870
panic(err)
6971
}
7072
}()

‎pkg/predicate/predicate_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ var _ = Describe("Predicate", func() {
413413

414414
// AnnotationChangedPredicate has almost identical test cases as LabelChangedPredicates,
415415
// so the duplication linter should be muted on both two test suites.
416-
//nolint:dupl
417416
Describe("When checking an AnnotationChangedPredicate", func() {
418417
instance := predicate.AnnotationChangedPredicate{}
419418
Context("Where the old object is missing", func() {
@@ -612,7 +611,6 @@ var _ = Describe("Predicate", func() {
612611

613612
// LabelChangedPredicates has almost identical test cases as AnnotationChangedPredicates,
614613
// so the duplication linter should be muted on both two test suites.
615-
//nolint:dupl
616614
Describe("When checking a LabelChangedPredicate", func() {
617615
instance := predicate.LabelChangedPredicate{}
618616
Context("Where the old object is missing", func() {

‎pkg/webhook/admission/admissiontest/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
// or passes if ErrorToReturn is nil.
2828
type FakeValidator struct {
2929
// ErrorToReturn is the error for which the FakeValidator rejects all requests
30-
ErrorToReturn error `json:"ErrorToReturn,omitempty"`
30+
ErrorToReturn error `json:"errorToReturn,omitempty"`
3131
// GVKToReturn is the GroupVersionKind that the webhook operates on
3232
GVKToReturn schema.GroupVersionKind
3333
}

‎pkg/webhook/admission/validator_custom.go

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func (h *validatorForType) Handle(ctx context.Context, req Request) Response {
7171

7272
var err error
7373
switch req.Operation {
74+
case v1.Connect:
75+
// No validation for connect requests.
76+
// TODO(vincepri): Should we validate CONNECT requests? In what cases?
7477
case v1.Create:
7578
if err := h.decoder.Decode(req, obj); err != nil {
7679
return Errored(http.StatusBadRequest, err)

‎pkg/webhook/server.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@ func (s *Server) Start(ctx context.Context) error {
275275
idleConnsClosed := make(chan struct{})
276276
go func() {
277277
<-ctx.Done()
278-
log.Info("shutting down webhook server")
278+
log.Info("Shutting down webhook server with timeout of 1 minute")
279279

280-
// TODO: use a context with reasonable timeout
281-
if err := srv.Shutdown(context.Background()); err != nil {
280+
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
281+
defer cancel()
282+
if err := srv.Shutdown(ctx); err != nil {
282283
// Error from closing listeners, or context timeout
283284
log.Error(err, "error shutting down the HTTP server")
284285
}

0 commit comments

Comments
 (0)