diff --git a/.golangci.yml b/.golangci.yml index b5e1907a8c..32f2aafca0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,13 @@ linters-settings: lll: line-length: 120 + gci: + sections: + - standard + - default + - prefix(github.com/cloudnative-pg/cloudnative-pg) + - blank + - dot linters: # please, do not use `enable-all`: it's deprecated and will be removed soon. @@ -16,6 +23,7 @@ linters: - durationcheck - errcheck - exportloopref + - gci - gocognit - goconst - gocritic @@ -75,7 +83,6 @@ linters: # - exhaustive # - exhaustivestruct # - funlen - # - gci # - gochecknoglobals # - gochecknoinits # - godot diff --git a/api/v1/cluster_configuration_test.go b/api/v1/cluster_configuration_test.go index 32f2e8d873..f9d443f87b 100644 --- a/api/v1/cluster_configuration_test.go +++ b/api/v1/cluster_configuration_test.go @@ -17,10 +17,10 @@ limitations under the License. package v1 import ( + "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" ) var _ = Describe("ensuring the correctness of synchronous replica data calculation", func() { diff --git a/api/v1/cluster_webhook_test.go b/api/v1/cluster_webhook_test.go index afc2054a6a..1948a40a4c 100644 --- a/api/v1/cluster_webhook_test.go +++ b/api/v1/cluster_webhook_test.go @@ -19,13 +19,14 @@ package v1 import ( "strings" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation/field" "github.com/cloudnative-pg/cloudnative-pg/internal/configuration" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("bootstrap methods validation", func() { diff --git a/api/v1/scheduledbackup_types_test.go b/api/v1/scheduledbackup_types_test.go index 3b28c9f938..71673f6a56 100644 --- a/api/v1/scheduledbackup_types_test.go +++ b/api/v1/scheduledbackup_types_test.go @@ -17,10 +17,10 @@ limitations under the License. package v1 import ( + "github.com/cloudnative-pg/cloudnative-pg/internal/configuration" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "github.com/cloudnative-pg/cloudnative-pg/internal/configuration" ) var _ = Describe("Scheduled backup", func() { diff --git a/api/v1/suite_test.go b/api/v1/suite_test.go index b736078018..0a904c5e1f 100644 --- a/api/v1/suite_test.go +++ b/api/v1/suite_test.go @@ -20,10 +20,10 @@ import ( "fmt" "testing" + "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" ) func TestApi(t *testing.T) { diff --git a/cmd/kubectl-cnpg/main.go b/cmd/kubectl-cnpg/main.go index 9026e79df1..4ef45016ee 100644 --- a/cmd/kubectl-cnpg/main.go +++ b/cmd/kubectl-cnpg/main.go @@ -19,21 +19,21 @@ package main import ( "os" - "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/maintenance" - "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" - _ "k8s.io/client-go/plugin/pkg/client/auth" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/certificate" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/fence" + "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/maintenance" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/promote" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/reload" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/report" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/restart" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin/status" "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/versions" + + _ "k8s.io/client-go/plugin/pkg/client/auth" ) func main() { diff --git a/controllers/cluster_delete_test.go b/controllers/cluster_delete_test.go index 92359ef3df..56e8b9537e 100644 --- a/controllers/cluster_delete_test.go +++ b/controllers/cluster_delete_test.go @@ -20,9 +20,6 @@ import ( "context" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -30,6 +27,9 @@ import ( apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" "github.com/cloudnative-pg/cloudnative-pg/internal/configuration" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("ensures that deleteDanglingMonitoringQueries works correctly", func() { diff --git a/controllers/cluster_status_test.go b/controllers/cluster_status_test.go index 69e8bf3633..c493600a55 100644 --- a/controllers/cluster_status_test.go +++ b/controllers/cluster_status_test.go @@ -19,9 +19,6 @@ package controllers import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" @@ -30,6 +27,9 @@ import ( v1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" "github.com/cloudnative-pg/cloudnative-pg/pkg/certs" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("cluster_status unit tests", func() { diff --git a/controllers/pooler_controller_test.go b/controllers/pooler_controller_test.go index 024ea26794..8541ca6a87 100644 --- a/controllers/pooler_controller_test.go +++ b/controllers/pooler_controller_test.go @@ -19,9 +19,6 @@ package controllers import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -29,6 +26,9 @@ import ( v1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("pooler_controller unit tests", func() { diff --git a/controllers/pooler_predicates_test.go b/controllers/pooler_predicates_test.go index 9d362fbd4e..069a5a59fc 100644 --- a/controllers/pooler_predicates_test.go +++ b/controllers/pooler_predicates_test.go @@ -17,9 +17,6 @@ limitations under the License. package controllers import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/rand" @@ -27,6 +24,9 @@ import ( "github.com/cloudnative-pg/cloudnative-pg/pkg/specs" "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("pooler_predicates unit tests", func() { diff --git a/controllers/pooler_resources_test.go b/controllers/pooler_resources_test.go index 8c90bd945c..e3e9eb8018 100644 --- a/controllers/pooler_resources_test.go +++ b/controllers/pooler_resources_test.go @@ -19,14 +19,14 @@ package controllers import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/cloudnative-pg/cloudnative-pg/pkg/specs/pgbouncer" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("pooler_resources unit tests", func() { diff --git a/controllers/pooler_status_test.go b/controllers/pooler_status_test.go index 0558265150..0d006d8313 100644 --- a/controllers/pooler_status_test.go +++ b/controllers/pooler_status_test.go @@ -19,15 +19,15 @@ package controllers import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" v1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" "github.com/cloudnative-pg/cloudnative-pg/pkg/specs/pgbouncer" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("pooler_status unit tests", func() { diff --git a/controllers/pooler_update_test.go b/controllers/pooler_update_test.go index 65ab20835c..4d37ef4d4b 100644 --- a/controllers/pooler_update_test.go +++ b/controllers/pooler_update_test.go @@ -19,9 +19,6 @@ package controllers import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -31,6 +28,9 @@ import ( "github.com/cloudnative-pg/cloudnative-pg/internal/configuration" "github.com/cloudnative-pg/cloudnative-pg/pkg/specs/pgbouncer" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("unit test of pooler_update reconciliation logic", func() { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 41224fa218..788a0c3aab 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -43,13 +43,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" // +kubebuilder:scaffold:imports - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" "github.com/cloudnative-pg/cloudnative-pg/pkg/certs" "github.com/cloudnative-pg/cloudnative-pg/pkg/specs" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to diff --git a/internal/cmd/manager/manager.go b/internal/cmd/manager/manager.go index 6a84c15e86..ce6fa625b7 100644 --- a/internal/cmd/manager/manager.go +++ b/internal/cmd/manager/manager.go @@ -26,7 +26,6 @@ import ( "github.com/spf13/pflag" "go.uber.org/zap/zapcore" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" diff --git a/internal/cmd/manager/show/cmd.go b/internal/cmd/manager/show/cmd.go index 893244267e..b21af7f97a 100644 --- a/internal/cmd/manager/show/cmd.go +++ b/internal/cmd/manager/show/cmd.go @@ -18,8 +18,9 @@ limitations under the License. package show import ( - "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/manager/show/walarchivequeue" "github.com/spf13/cobra" + + "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/manager/show/walarchivequeue" ) // NewCmd creates the new cobra command diff --git a/internal/cmd/manager/walarchive/cmd.go b/internal/cmd/manager/walarchive/cmd.go index da6b250689..f3ebb1692a 100644 --- a/internal/cmd/manager/walarchive/cmd.go +++ b/internal/cmd/manager/walarchive/cmd.go @@ -29,7 +29,6 @@ import ( "time" "github.com/spf13/cobra" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/internal/cmd/manager/walrestore/cmd_test.go b/internal/cmd/manager/walrestore/cmd_test.go index b5fdcfb441..b66c446c8c 100644 --- a/internal/cmd/manager/walrestore/cmd_test.go +++ b/internal/cmd/manager/walrestore/cmd_test.go @@ -18,6 +18,7 @@ package walrestore import ( apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/internal/cmd/plugin/maintenance/maintenance.go b/internal/cmd/plugin/maintenance/maintenance.go index 982dc49fda..7060d87375 100644 --- a/internal/cmd/plugin/maintenance/maintenance.go +++ b/internal/cmd/plugin/maintenance/maintenance.go @@ -27,9 +27,8 @@ import ( "github.com/cheynewallace/tabby" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin" - v1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" + "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin" ) // Maintenance command implementation diff --git a/internal/cmd/plugin/report/logs.go b/internal/cmd/plugin/report/logs.go index f0e7b411e5..9b5b32d314 100644 --- a/internal/cmd/plugin/report/logs.go +++ b/internal/cmd/plugin/report/logs.go @@ -23,13 +23,13 @@ import ( "io" "path/filepath" - "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin" - "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" - batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/cloudnative-pg/cloudnative-pg/internal/cmd/plugin" + "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" ) const jobMatcherLabel = "job-name" diff --git a/internal/management/controller/instance_controller.go b/internal/management/controller/instance_controller.go index 79cc4c6c5e..4aee358be0 100644 --- a/internal/management/controller/instance_controller.go +++ b/internal/management/controller/instance_controller.go @@ -27,7 +27,6 @@ import ( "time" "github.com/lib/pq" - corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" diff --git a/internal/management/controller/manager.go b/internal/management/controller/manager.go index e0afbea65a..2e74e1a4b2 100644 --- a/internal/management/controller/manager.go +++ b/internal/management/controller/manager.go @@ -22,9 +22,8 @@ import ( "context" "fmt" - corev1 "k8s.io/api/core/v1" - "go.uber.org/atomic" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/pkg/management/barman/credentials/env.go b/pkg/management/barman/credentials/env.go index 6168fb3cf7..735313c198 100644 --- a/pkg/management/barman/credentials/env.go +++ b/pkg/management/barman/credentials/env.go @@ -21,12 +21,11 @@ import ( "context" "fmt" - "github.com/cloudnative-pg/cloudnative-pg/pkg/fileutils" - corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" + "github.com/cloudnative-pg/cloudnative-pg/pkg/fileutils" "github.com/cloudnative-pg/cloudnative-pg/pkg/postgres" ) diff --git a/pkg/management/pgbouncer/config/config.go b/pkg/management/pgbouncer/config/config.go index ea097430bf..3dd09964a6 100644 --- a/pkg/management/pgbouncer/config/config.go +++ b/pkg/management/pgbouncer/config/config.go @@ -23,10 +23,11 @@ import ( "strings" "text/template" + corev1 "k8s.io/api/core/v1" + apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" "github.com/cloudnative-pg/cloudnative-pg/pkg/certs" "github.com/cloudnative-pg/cloudnative-pg/pkg/postgres" - corev1 "k8s.io/api/core/v1" ) const ( diff --git a/pkg/management/pgbouncer/config/secrets_test.go b/pkg/management/pgbouncer/config/secrets_test.go index 58b4104e8f..d3361bda4f 100644 --- a/pkg/management/pgbouncer/config/secrets_test.go +++ b/pkg/management/pgbouncer/config/secrets_test.go @@ -17,10 +17,10 @@ limitations under the License. package config import ( + corev1 "k8s.io/api/core/v1" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - corev1 "k8s.io/api/core/v1" ) var _ = Describe("Secret type detection", func() { diff --git a/pkg/management/postgres/configuration_test.go b/pkg/management/postgres/configuration_test.go index e8225ab796..12ee84329b 100644 --- a/pkg/management/postgres/configuration_test.go +++ b/pkg/management/postgres/configuration_test.go @@ -19,12 +19,13 @@ package postgres import ( "fmt" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) const ( diff --git a/pkg/postgres/status_test.go b/pkg/postgres/status_test.go index 7f2dd616f9..ced5f7e125 100644 --- a/pkg/postgres/status_test.go +++ b/pkg/postgres/status_test.go @@ -22,10 +22,11 @@ import ( "os" "sort" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("PostgreSQL status", func() { diff --git a/pkg/specs/jobs_test.go b/pkg/specs/jobs_test.go index 482ca59341..c83e18fee3 100644 --- a/pkg/specs/jobs_test.go +++ b/pkg/specs/jobs_test.go @@ -17,13 +17,14 @@ limitations under the License. package specs import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" v1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("Barman endpoint CA", func() { diff --git a/pkg/specs/pods_test.go b/pkg/specs/pods_test.go index 837ef405fd..b255979352 100644 --- a/pkg/specs/pods_test.go +++ b/pkg/specs/pods_test.go @@ -17,12 +17,13 @@ limitations under the License. package specs import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) func pointerToBool(b bool) *bool { diff --git a/pkg/utils/hash/hash.go b/pkg/utils/hash/hash.go index 07f5c80570..06dd79b475 100644 --- a/pkg/utils/hash/hash.go +++ b/pkg/utils/hash/hash.go @@ -31,7 +31,6 @@ import ( "hash/fnv" "github.com/davecgh/go-spew/spew" - "k8s.io/apimachinery/pkg/util/rand" ) diff --git a/pkg/utils/job_conditions_test.go b/pkg/utils/job_conditions_test.go index f35129adc4..73ddd2b990 100644 --- a/pkg/utils/job_conditions_test.go +++ b/pkg/utils/job_conditions_test.go @@ -17,9 +17,10 @@ limitations under the License. package utils import ( + batchv1 "k8s.io/api/batch/v1" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - batchv1 "k8s.io/api/batch/v1" ) var _ = Describe("Job conditions", func() { diff --git a/pkg/utils/labels_annotations_test.go b/pkg/utils/labels_annotations_test.go index 5f5fb8c2f8..9989a56e49 100644 --- a/pkg/utils/labels_annotations_test.go +++ b/pkg/utils/labels_annotations_test.go @@ -17,13 +17,13 @@ limitations under the License. package utils import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/cloudnative-pg/cloudnative-pg/internal/configuration" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("Operator version annotation management", func() { diff --git a/pkg/utils/ownership.go b/pkg/utils/ownership.go index 7661ca74ba..833a1e470b 100644 --- a/pkg/utils/ownership.go +++ b/pkg/utils/ownership.go @@ -21,7 +21,6 @@ import ( "fmt" v1 "k8s.io/api/apps/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" ) diff --git a/pkg/utils/time.go b/pkg/utils/time.go index 1b94e3c74f..fbc6547eb9 100644 --- a/pkg/utils/time.go +++ b/pkg/utils/time.go @@ -20,7 +20,6 @@ import ( "time" "github.com/lib/pq" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/pkg/utils/time_test.go b/pkg/utils/time_test.go index c03d6d77f4..c2bbf0ae50 100644 --- a/pkg/utils/time_test.go +++ b/pkg/utils/time_test.go @@ -19,9 +19,10 @@ package utils import ( "time" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var _ = Describe("Time conversion", func() {