From 158b033326eb5ffbea4b6cc82d3f5324f9aec247 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine <5779804+AshleyDumaine@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:49:56 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20[cleanup]=20golangci-lint=20upda?= =?UTF-8?q?tes=20(#172)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add gci linter, apply lint fixes, remove nlreturn lint * remove gocyclo linter since it's abandoned, bump cyclop from, 15 to 17 --- .golangci.yml | 29 ++++++++++++++----- cloud/scope/object_storage_bucket.go | 2 +- cloud/services/loadbalancers.go | 5 ++-- cloud/services/object_storage_buckets.go | 3 +- cmd/main.go | 17 +++++------ controller/linodecluster_controller.go | 18 +++++------- controller/linodemachine_controller.go | 8 ++--- .../linodemachine_controller_helpers.go | 4 +-- .../linodeobjectstoragebucket_controller.go | 5 ++-- controller/linodevpc_controller.go | 5 ++-- controller/linodevpc_controller_helpers.go | 4 +-- controller/suite_test.go | 8 ++--- 12 files changed, 56 insertions(+), 52 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 89e2a8d1d..9dfcd57a0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 @@ -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 @@ -140,7 +144,7 @@ linters: - forbidigo - forcetypeassert # - funlen - # - gci + - gci - gocheckcompilerdirectives - gocognit - goconst @@ -151,7 +155,7 @@ linters: - gofmt - goimports - gomnd - - gocyclo + # - gocyclo - goprintffuncname - gosec - gosimple @@ -164,7 +168,7 @@ linters: - nestif - nilerr - nilnil - - nlreturn + # - nlreturn - noctx - nolintlint - paralleltest @@ -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. diff --git a/cloud/scope/object_storage_bucket.go b/cloud/scope/object_storage_bucket.go index 8ee8cc749..48de5a277 100644 --- a/cloud/scope/object_storage_bucket.go +++ b/cloud/scope/object_storage_bucket.go @@ -7,6 +7,7 @@ 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" @@ -14,7 +15,6 @@ import ( "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 { diff --git a/cloud/services/loadbalancers.go b/cloud/services/loadbalancers.go index 7c6b4bedd..e7123db46 100644 --- a/cloud/services/loadbalancers.go +++ b/cloud/services/loadbalancers.go @@ -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 ( diff --git a/cloud/services/object_storage_buckets.go b/cloud/services/object_storage_buckets.go index ac82f9deb..864ea5d4d 100644 --- a/cloud/services/object_storage_buckets.go +++ b/cloud/services/object_storage_buckets.go @@ -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" ) diff --git a/cmd/main.go b/cmd/main.go index c007012c4..ff661f4db 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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" @@ -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 ) diff --git a/controller/linodecluster_controller.go b/controller/linodecluster_controller.go index aa9e7b748..66abe2fb7 100644 --- a/controller/linodecluster_controller.go +++ b/controller/linodecluster_controller.go @@ -23,16 +23,11 @@ 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" @@ -40,14 +35,17 @@ import ( "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 diff --git a/controller/linodemachine_controller.go b/controller/linodemachine_controller.go index 198c62716..759fac361 100644 --- a/controller/linodemachine_controller.go +++ b/controller/linodemachine_controller.go @@ -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" @@ -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 @@ -94,8 +94,6 @@ type LinodeMachineReconciler struct { // // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.16.0/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() diff --git a/controller/linodemachine_controller_helpers.go b/controller/linodemachine_controller_helpers.go index 460b624ce..b9a5bac6a 100644 --- a/controller/linodemachine_controller_helpers.go +++ b/controller/linodemachine_controller_helpers.go @@ -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" @@ -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 diff --git a/controller/linodeobjectstoragebucket_controller.go b/controller/linodeobjectstoragebucket_controller.go index de012f8d8..f9c8fb5c1 100644 --- a/controller/linodeobjectstoragebucket_controller.go +++ b/controller/linodeobjectstoragebucket_controller.go @@ -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" @@ -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" diff --git a/controller/linodevpc_controller.go b/controller/linodevpc_controller.go index df77123c1..407fbb9c4 100644 --- a/controller/linodevpc_controller.go +++ b/controller/linodevpc_controller.go @@ -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" @@ -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 diff --git a/controller/linodevpc_controller_helpers.go b/controller/linodevpc_controller_helpers.go index feed349e5..99eaf3552 100644 --- a/controller/linodevpc_controller_helpers.go +++ b/controller/linodevpc_controller_helpers.go @@ -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 { diff --git a/controller/suite_test.go b/controller/suite_test.go index cd8951838..4fe9135e1 100644 --- a/controller/suite_test.go +++ b/controller/suite_test.go @@ -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" @@ -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