Skip to content

Commit

Permalink
Merge pull request #2133 from vincepri/add-more-linters2
Browse files Browse the repository at this point in the history
🌱 Add more linters
  • Loading branch information
k8s-ci-robot authored Jan 18, 2023
2 parents ce9f5c0 + d16fa68 commit 16f7965
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
11 changes: 10 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- errchkjson
- errorlint
- exhaustive
- exportloopref
- goconst
- gocritic
Expand All @@ -19,15 +24,16 @@ linters:
- govet
- importas
- ineffassign
- makezero
- misspell
- nakedret
- nilerr
- nolintlint
- prealloc
- revive
- rowserrcheck
- staticcheck
- stylecheck
- tagliatelle
- typecheck
- unconvert
- unparam
Expand Down Expand Up @@ -127,6 +133,9 @@ issues:
- linters:
- revive
text: "package-comments: should have a package comment"
- linters:
- dupl
path: _test\.go

run:
timeout: 10m
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (a *ReplicaSetReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// Update the ReplicaSet
rs.Labels["pod-count"] = fmt.Sprintf("%v", len(pods.Items))
err = a.Update(context.TODO(), rs)
err = a.Update(ctx, rs)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
},
},
}
err := mgr.GetClient().Create(context.TODO(), dep)
err := mgr.GetClient().Create(ctx, dep)
Expect(err).NotTo(HaveOccurred())

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

By("Waiting for the ReplicaSet Reconcile")
Expand Down
4 changes: 3 additions & 1 deletion pkg/certwatcher/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func Example() {
// Start goroutine for handling server shutdown.
go func() {
<-ctx.Done()
if err := srv.Shutdown(context.Background()); err != nil {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
panic(err)
}
}()
Expand Down
2 changes: 0 additions & 2 deletions pkg/predicate/predicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ var _ = Describe("Predicate", func() {

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

// LabelChangedPredicates has almost identical test cases as AnnotationChangedPredicates,
// so the duplication linter should be muted on both two test suites.
//nolint:dupl
Describe("When checking a LabelChangedPredicate", func() {
instance := predicate.LabelChangedPredicate{}
Context("Where the old object is missing", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/admission/admissiontest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// or passes if ErrorToReturn is nil.
type FakeValidator struct {
// ErrorToReturn is the error for which the FakeValidator rejects all requests
ErrorToReturn error `json:"ErrorToReturn,omitempty"`
ErrorToReturn error `json:"errorToReturn,omitempty"`
// GVKToReturn is the GroupVersionKind that the webhook operates on
GVKToReturn schema.GroupVersionKind
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/webhook/admission/validator_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (h *validatorForType) Handle(ctx context.Context, req Request) Response {

var err error
switch req.Operation {
case v1.Connect:
// No validation for connect requests.
// TODO(vincepri): Should we validate CONNECT requests? In what cases?
case v1.Create:
if err := h.decoder.Decode(req, obj); err != nil {
return Errored(http.StatusBadRequest, err)
Expand Down
7 changes: 4 additions & 3 deletions pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ func (s *Server) Start(ctx context.Context) error {
idleConnsClosed := make(chan struct{})
go func() {
<-ctx.Done()
log.Info("shutting down webhook server")
log.Info("Shutting down webhook server with timeout of 1 minute")

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

0 comments on commit 16f7965

Please sign in to comment.