Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Update golangci-linter version to make it compatible with go 1.20
Browse files Browse the repository at this point in the history
Three linters are removed because of they're deprecated since v1.49.0
and replaced by unused: structcheck, deadcode and varcheck.

depguard is also removed because it generates a bunch of false-positives
as below:
- import 'k8s.io/klog/v2' is not allowed from list 'Main' (depguard).
- import 'sigs.k8s.io/controller-runtime' is not allowed from list 'Main' (depguard)

It also fixes other linter issues.

Change-Id: I07ddf005ed806fd263785fab356e4a050f739165
GitOrigin-RevId: 422ad15749d44969467213a3f66e4ee64d739f2f
  • Loading branch information
Config Sync Team authored and copybara-github committed Sep 13, 2023
1 parent 405b750 commit 4fd78e2
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 16 deletions.
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
Expand All @@ -28,14 +26,12 @@ linters:
- misspell
- nakedret
- staticcheck
- structcheck
- stylecheck
- revive
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace


Expand Down
2 changes: 1 addition & 1 deletion Makefile.deps
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CONTROLLER_GEN := $(GOBIN)/controller-gen
ADDLICENSE_VERSION := v1.0.0
ADDLICENSE := $(GOBIN)/addlicense

GOLINT_VERSION := v1.46.2
GOLINT_VERSION := v1.54.2
GOLINT := $(GOBIN)/golangci-lint

KIND_VERSION := v0.14.0
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/kpt.dev_resourcegroups.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion controllers/handler/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (e *EnqueueEventToChannel) OnAdd(obj interface{}) {
}

// Update implements EventHandler
func (e *EnqueueEventToChannel) OnUpdate(oldObj, newObj interface{}) {
func (e *EnqueueEventToChannel) OnUpdate(_, newObj interface{}) {
e.Log.V(5).Info("received an update event")
e.enqueueEvent(newObj)
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/handler/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ func NewThrottler(d time.Duration) *Throttler {
}

// Create implements EventHandler. All create events are ignored.
func (e *Throttler) Create(evt event.CreateEvent, q workqueue.RateLimitingInterface) {
func (e *Throttler) Create(event.CreateEvent, workqueue.RateLimitingInterface) {
}

// Update implements EventHandler. All update events are ignored.
func (e *Throttler) Update(evt event.UpdateEvent, q workqueue.RateLimitingInterface) {
func (e *Throttler) Update(event.UpdateEvent, workqueue.RateLimitingInterface) {
}

// Delete implements EventHandler. All delete events are ignored.
func (e *Throttler) Delete(evt event.DeleteEvent, q workqueue.RateLimitingInterface) {
func (e *Throttler) Delete(event.DeleteEvent, workqueue.RateLimitingInterface) {
}

// Generic implements EventHandler.
Expand Down
6 changes: 5 additions & 1 deletion controllers/metrics/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const (
RepoSyncName = "repo-sync"
// RootSyncName is the expected name of any RootSync CR.
RootSyncName = "root-sync"

//nolint:gosec // ignore the false-positive alert for G101: Potential hardcoded credentials
// CMSNamespace is the name of the Config Sync controller's namespace
CMSNamespace = "config-management-system"
)

// RecordReconcileDuration produces a measurement for the ReconcileDuration view.
Expand Down Expand Up @@ -108,7 +112,7 @@ func RecordPipelineError(ctx context.Context, nn types.NamespacedName, component

// ComputeReconcilerName computes the reconciler name from the ResourceGroup CR name
func ComputeReconcilerNameType(nn types.NamespacedName) (reconcilerName, reconcilerType string) {
if nn.Namespace == "config-management-system" {
if nn.Namespace == CMSNamespace {
if nn.Name == RootSyncName {
return RootReconcilerPrefix, RootSyncName
}
Expand Down
7 changes: 6 additions & 1 deletion controllers/profiler/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

//nolint:gosec // pprof init() registers handlers, which we serve with ListenAndServe
_ "net/http/pprof"
"time"

"k8s.io/klog/v2"
)
Expand All @@ -34,7 +35,11 @@ func Service() {
go func() {
klog.Infof("Starting profiling on port %d", *profilerPort)
addr := fmt.Sprintf(":%d", *profilerPort)
err := http.ListenAndServe(addr, nil)
server := &http.Server{
Addr: addr,
ReadHeaderTimeout: 30 * time.Second,
}
err := server.ListenAndServe()
if err != nil {
klog.Fatalf("Profiler server failed to start: %+v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/root/root_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ type NoGenericEventPredicate struct {
}

// Generic skips all generic events
func (NoGenericEventPredicate) Generic(e event.GenericEvent) bool {
func (NoGenericEventPredicate) Generic(event.GenericEvent) bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/typeresolver/typeresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *TypeResolver) Resolve(gk schema.GroupKind) (schema.GroupVersionKind, bo

// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch

func (r *TypeResolver) Reconcile(c context.Context, req ctrl.Request) (ctrl.Result, error) {
func (r *TypeResolver) Reconcile(context.Context, ctrl.Request) (ctrl.Result, error) {
logger := r.log
logger.Info("refreshing type resolver")
r.Refresh()
Expand Down
2 changes: 1 addition & 1 deletion controllers/watch/filteredwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func waitUntilNextRetry(retries int) {
// Run reads the event from the base watch interface,
// filters the event and pushes the object contained
// in the event to the controller work queue.
func (w *filteredWatcher) Run(ctx context.Context) error {
func (w *filteredWatcher) Run(context.Context) error {
klog.Infof("Watch started for %s", w.gvk)
var resourceVersion string
var retriesForWatchError int
Expand Down
2 changes: 1 addition & 1 deletion controllers/watch/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func fakeRunnable(ctx context.Context) Runnable {
}

func fakeError(gvk schema.GroupVersionKind) error {
return errors.New("failed")
return errors.Errorf("failed error for %q", gvk)
}

func testRunnables(_ context.Context, errOnType map[schema.GroupVersionKind]bool) func(context.Context, watcherConfig) (Runnable, error) {
Expand Down

0 comments on commit 4fd78e2

Please sign in to comment.