Skip to content

Commit

Permalink
🧹 [cleanup] golangci-lint updates (#172)
Browse files Browse the repository at this point in the history
* add gci linter, apply lint fixes, remove nlreturn lint

* remove gocyclo linter since it's abandoned, bump cyclop from, 15 to 17
  • Loading branch information
AshleyDumaine authored Mar 8, 2024
1 parent 3ab8cb9 commit e1f809f
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 52 deletions.
29 changes: 21 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ linters-settings:
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
ignore: fmt:.*,io/ioutil:^Read.*

gci:
sections:
- standard
- default
- blank
- dot
- prefix(github.com/linode/cluster-api-provider-linode)

govet:
# report about shadowed variables
check-shadowing: false
Expand All @@ -42,12 +50,8 @@ linters-settings:
# it's a comma-separated list of prefixes
local-prefixes: github.com/crossplane/provider-template

gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 15

cyclop:
max-complexity: 15
max-complexity: 17

maligned:
# print struct with more effective memory layout or not, false by default
Expand Down Expand Up @@ -140,7 +144,7 @@ linters:
- forbidigo
- forcetypeassert
# - funlen
# - gci
- gci
- gocheckcompilerdirectives
- gocognit
- goconst
Expand All @@ -151,7 +155,7 @@ linters:
- gofmt
- goimports
- gomnd
- gocyclo
# - gocyclo
- goprintffuncname
- gosec
- gosimple
Expand All @@ -164,7 +168,7 @@ linters:
- nestif
- nilerr
- nilnil
- nlreturn
# - nlreturn
- noctx
- nolintlint
- paralleltest
Expand Down Expand Up @@ -210,6 +214,15 @@ issues:
linters:
- gocritic

# Exclude gci check for //+kubebuilder:scaffold:imports comments. Waiting to
# resolve https://github.com/daixiang0/gci/issues/135
- path: cmd/main.go
linters:
- gci
- path: controller/suite_test.go
linters:
- gci

# These are performance optimisations rather than style issues per se.
# They warn when function arguments or range values copy a lot of memory
# rather than using a pointer.
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/object_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"fmt"

"github.com/go-logr/logr"
"github.com/linode/linodego"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/linodego"
)

type ObjectStorageBucketScopeParams struct {
Expand Down
5 changes: 3 additions & 2 deletions cloud/services/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"slices"

"github.com/go-logr/logr"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/linodego"
kutil "sigs.k8s.io/cluster-api/util"

"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
)

const (
Expand Down
3 changes: 1 addition & 2 deletions cloud/services/object_storage_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"fmt"
"net/http"

"github.com/linode/linodego"
corev1 "k8s.io/api/core/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"

"github.com/linode/linodego"

"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
)
Expand Down
17 changes: 7 additions & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ import (
"fmt"
"os"

"github.com/linode/cluster-api-provider-linode/version"

_ "go.uber.org/automaxprocs"

controller2 "github.com/linode/cluster-api-provider-linode/controller"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -42,6 +32,13 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

infrastructurev1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
controller2 "github.com/linode/cluster-api-provider-linode/controller"
"github.com/linode/cluster-api-provider-linode/version"

_ "go.uber.org/automaxprocs"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
// +kubebuilder:scaffold:imports
)

Expand Down
18 changes: 8 additions & 10 deletions controller/linodecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,29 @@ import (
"net/http"
"time"

apierrors "k8s.io/apimachinery/pkg/api/errors"
utilerrors "k8s.io/apimachinery/pkg/util/errors"

"github.com/go-logr/logr"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/cloud/services"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/cluster-api-provider-linode/util/reconciler"
"github.com/linode/linodego"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
cerrs "sigs.k8s.io/cluster-api/errors"
kutil "sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/predicates"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/cloud/services"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/cluster-api-provider-linode/util/reconciler"
)

// LinodeClusterReconciler reconciles a LinodeCluster object
Expand Down
8 changes: 3 additions & 5 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/cluster-api-provider-linode/util/reconciler"
"github.com/linode/linodego"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -46,7 +43,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/cloud/services"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/cluster-api-provider-linode/util/reconciler"
)

// default etcd Disk size in MB
Expand Down Expand Up @@ -94,8 +94,6 @@ type LinodeMachineReconciler struct {
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
//
//nolint:gocyclo,cyclop // As simple as possible.
func (r *LinodeMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultedLoopTimeout(r.ReconcileTimeout))
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions controller/linodemachine_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (

"github.com/go-logr/logr"
"github.com/google/uuid"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util/reconciler"
"github.com/linode/linodego"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -39,7 +37,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"

infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/cluster-api-provider-linode/util/reconciler"
)

// Size limit in bytes on the decoded metadata.user_data for cloud-init
Expand Down
5 changes: 2 additions & 3 deletions controller/linodeobjectstoragebucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
"fmt"
"time"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"

"k8s.io/apimachinery/pkg/runtime"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/conditions"
Expand All @@ -36,7 +36,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/go-logr/logr"
infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/cloud/services"
Expand Down
5 changes: 2 additions & 3 deletions controller/linodevpc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"time"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -38,12 +39,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/go-logr/logr"
infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/cluster-api-provider-linode/util/reconciler"

infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
)

// LinodeVPCReconciler reconciles a LinodeVPC object
Expand Down
4 changes: 2 additions & 2 deletions controller/linodevpc_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"errors"

"github.com/go-logr/logr"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/linodego"

infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
)

func (r *LinodeVPCReconciler) reconcileVPC(ctx context.Context, vpcScope *scope.VPCScope, logger logr.Logger) error {
Expand Down
8 changes: 4 additions & 4 deletions controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
"runtime"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -33,7 +30,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

infrastructurev1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
//+kubebuilder:scaffold:imports

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
// +kubebuilder:scaffold:imports
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down

0 comments on commit e1f809f

Please sign in to comment.