From b4c59f10020fd77d2eab601e333970b8ea208661 Mon Sep 17 00:00:00 2001 From: Bastian Krol Date: Wed, 9 Oct 2024 14:14:59 +0200 Subject: [PATCH] chore: fix linting (#15) * chore: fix linting * pin the Go version used to run golangci-lint to Go 1.22 * fix linting issues reported by golangci-lint (superfluos nil checks for slices) * remove redundant package aliases Signed-off-by: Bastian Krol * ci: udpate perses GH action and golangci-lint Signed-off-by: Bastian Krol --------- Signed-off-by: Bastian Krol --- .github/workflows/go.yml | 8 +++++--- controllers/dashboard_controller_test.go | 4 ++-- controllers/dashboards/dasboard_controller.go | 4 ++-- controllers/dashboards/persesdashboard_controller.go | 6 +++--- controllers/datasource_controller_test.go | 4 ++-- controllers/datasources/datasource_controller.go | 4 ++-- controllers/datasources/persesdatasource_controller.go | 6 +++--- controllers/perses/configmap_controller.go | 4 ++-- controllers/perses/deployment_controller.go | 4 ++-- controllers/perses/perses_controller.go | 6 +++--- controllers/perses/service_controller.go | 4 ++-- controllers/perses_controller_test.go | 6 +++--- internal/perses/common/perses_client_factory.go | 2 +- 13 files changed, 32 insertions(+), 30 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4c57a06..41dd36b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -46,15 +46,17 @@ jobs: steps: - name: checkout uses: actions/checkout@v4 - - uses: perses/github-actions@v0.1.0 + - uses: perses/github-actions@v0.6.0 - uses: ./.github/perses-ci/actions/setup_environment with: enable_go: true + enable_go_cache: false + enable_npm: false - name: generate files run: make generate - name: golangci-lint - uses: golangci/golangci-lint-action@v3.7.0 + uses: golangci/golangci-lint-action@v6.1.0 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.54.2 + version: v1.61.0 args: --timeout 5m diff --git a/controllers/dashboard_controller_test.go b/controllers/dashboard_controller_test.go index 14e0079..fec659b 100644 --- a/controllers/dashboard_controller_test.go +++ b/controllers/dashboard_controller_test.go @@ -11,7 +11,7 @@ import ( persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1" dashboardcontroller "github.com/perses/perses-operator/controllers/dashboards" internal "github.com/perses/perses-operator/internal/perses" - common "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/perses/common" "github.com/perses/perses/pkg/client/perseshttp" persesv1 "github.com/perses/perses/pkg/model/api/v1" persescommon "github.com/perses/perses/pkg/model/api/v1/common" @@ -171,7 +171,7 @@ var _ = Describe("Dashboard controller", func() { dashboardWithStatus := &persesv1alpha1.PersesDashboard{} err = k8sClient.Get(ctx, dashboardNamespaceName, dashboardWithStatus) - if dashboardWithStatus.Status.Conditions == nil || len(dashboardWithStatus.Status.Conditions) == 0 { + if len(dashboardWithStatus.Status.Conditions) == 0 { return fmt.Errorf("No status condition was added to the perses dashboard instance") } else { latestStatusCondition := dashboardWithStatus.Status.Conditions[len(dashboardWithStatus.Status.Conditions)-1] diff --git a/controllers/dashboards/dasboard_controller.go b/controllers/dashboards/dasboard_controller.go index c069e15..2cb0dd6 100644 --- a/controllers/dashboards/dasboard_controller.go +++ b/controllers/dashboards/dasboard_controller.go @@ -22,8 +22,8 @@ import ( "time" persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1" - subreconciler "github.com/perses/perses-operator/internal/subreconciler" - perseshttp "github.com/perses/perses/pkg/client/perseshttp" + "github.com/perses/perses-operator/internal/subreconciler" + "github.com/perses/perses/pkg/client/perseshttp" persesv1 "github.com/perses/perses/pkg/model/api/v1" logger "github.com/sirupsen/logrus" ctrl "sigs.k8s.io/controller-runtime" diff --git a/controllers/dashboards/persesdashboard_controller.go b/controllers/dashboards/persesdashboard_controller.go index eddb6a6..6386d00 100644 --- a/controllers/dashboards/persesdashboard_controller.go +++ b/controllers/dashboards/persesdashboard_controller.go @@ -30,8 +30,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1" - common "github.com/perses/perses-operator/internal/perses/common" - subreconciler "github.com/perses/perses-operator/internal/subreconciler" + "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/subreconciler" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -103,7 +103,7 @@ func (r *PersesDashboardReconciler) setStatusToUnknown(ctx context.Context, req return r, err } - if dashboard.Status.Conditions == nil || len(dashboard.Status.Conditions) == 0 { + if len(dashboard.Status.Conditions) == 0 { meta.SetStatusCondition(&dashboard.Status.Conditions, metav1.Condition{Type: common.TypeAvailablePerses, Status: metav1.ConditionUnknown, Reason: "Reconciling", Message: "Starting reconciliation"}) if err := r.Status().Update(ctx, dashboard); err != nil { log.WithError(err).Error("Failed to update Perses dashboard status") diff --git a/controllers/datasource_controller_test.go b/controllers/datasource_controller_test.go index 3245730..2aa9252 100644 --- a/controllers/datasource_controller_test.go +++ b/controllers/datasource_controller_test.go @@ -11,7 +11,7 @@ import ( persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1" datasourcecontroller "github.com/perses/perses-operator/controllers/datasources" internal "github.com/perses/perses-operator/internal/perses" - common "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/perses/common" "github.com/perses/perses/pkg/client/perseshttp" persesv1 "github.com/perses/perses/pkg/model/api/v1" persescommon "github.com/perses/perses/pkg/model/api/v1/common" @@ -160,7 +160,7 @@ var _ = Describe("Datasource controller", func() { datasourceWithStatus := &persesv1alpha1.PersesDatasource{} err = k8sClient.Get(ctx, datasourceNamespaceName, datasourceWithStatus) - if datasourceWithStatus.Status.Conditions == nil || len(datasourceWithStatus.Status.Conditions) == 0 { + if len(datasourceWithStatus.Status.Conditions) == 0 { return fmt.Errorf("No status condition was added to the perses datasource instance") } else { latestStatusCondition := datasourceWithStatus.Status.Conditions[len(datasourceWithStatus.Status.Conditions)-1] diff --git a/controllers/datasources/datasource_controller.go b/controllers/datasources/datasource_controller.go index 896534f..726cb9c 100644 --- a/controllers/datasources/datasource_controller.go +++ b/controllers/datasources/datasource_controller.go @@ -22,8 +22,8 @@ import ( "time" persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1" - subreconciler "github.com/perses/perses-operator/internal/subreconciler" - perseshttp "github.com/perses/perses/pkg/client/perseshttp" + "github.com/perses/perses-operator/internal/subreconciler" + "github.com/perses/perses/pkg/client/perseshttp" persesv1 "github.com/perses/perses/pkg/model/api/v1" logger "github.com/sirupsen/logrus" ctrl "sigs.k8s.io/controller-runtime" diff --git a/controllers/datasources/persesdatasource_controller.go b/controllers/datasources/persesdatasource_controller.go index 990b074..7437e9d 100644 --- a/controllers/datasources/persesdatasource_controller.go +++ b/controllers/datasources/persesdatasource_controller.go @@ -30,8 +30,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1" - common "github.com/perses/perses-operator/internal/perses/common" - subreconciler "github.com/perses/perses-operator/internal/subreconciler" + "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/subreconciler" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -103,7 +103,7 @@ func (r *PersesDatasourceReconciler) setStatusToUnknown(ctx context.Context, req return r, err } - if datasource.Status.Conditions == nil || len(datasource.Status.Conditions) == 0 { + if len(datasource.Status.Conditions) == 0 { meta.SetStatusCondition(&datasource.Status.Conditions, metav1.Condition{Type: common.TypeAvailablePerses, Status: metav1.ConditionUnknown, Reason: "Reconciling", Message: "Starting reconciliation"}) if err := r.Status().Update(ctx, datasource); err != nil { log.WithError(err).Error("Failed to update Perses datasource status") diff --git a/controllers/perses/configmap_controller.go b/controllers/perses/configmap_controller.go index 6cb5a0a..5909a6f 100644 --- a/controllers/perses/configmap_controller.go +++ b/controllers/perses/configmap_controller.go @@ -22,8 +22,8 @@ import ( "time" "github.com/perses/perses-operator/api/v1alpha1" - common "github.com/perses/perses-operator/internal/perses/common" - subreconciler "github.com/perses/perses-operator/internal/subreconciler" + "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/subreconciler" logger "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" corev1 "k8s.io/api/core/v1" diff --git a/controllers/perses/deployment_controller.go b/controllers/perses/deployment_controller.go index b061dc3..8d87f5d 100644 --- a/controllers/perses/deployment_controller.go +++ b/controllers/perses/deployment_controller.go @@ -22,8 +22,8 @@ import ( "time" "github.com/perses/perses-operator/api/v1alpha1" - common "github.com/perses/perses-operator/internal/perses/common" - subreconciler "github.com/perses/perses-operator/internal/subreconciler" + "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/subreconciler" logger "github.com/sirupsen/logrus" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" diff --git a/controllers/perses/perses_controller.go b/controllers/perses/perses_controller.go index 2e56aba..7286011 100644 --- a/controllers/perses/perses_controller.go +++ b/controllers/perses/perses_controller.go @@ -22,8 +22,8 @@ import ( "time" "github.com/perses/perses-operator/api/v1alpha1" - common "github.com/perses/perses-operator/internal/perses/common" - subreconciler "github.com/perses/perses-operator/internal/subreconciler" + "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/subreconciler" logger "github.com/sirupsen/logrus" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -106,7 +106,7 @@ func (r *PersesReconciler) setStatusToUnknown(ctx context.Context, req ctrl.Requ } // Let's just set the status as Unknown when no status are available - if perses.Status.Conditions == nil || len(perses.Status.Conditions) == 0 { + if len(perses.Status.Conditions) == 0 { meta.SetStatusCondition(&perses.Status.Conditions, metav1.Condition{Type: common.TypeAvailablePerses, Status: metav1.ConditionUnknown, Reason: "Reconciling", Message: "Starting reconciliation"}) if err := r.Status().Update(ctx, perses); err != nil { log.WithError(err).Error("Failed to update Perses status") diff --git a/controllers/perses/service_controller.go b/controllers/perses/service_controller.go index 53f0e2c..69b4866 100644 --- a/controllers/perses/service_controller.go +++ b/controllers/perses/service_controller.go @@ -22,8 +22,8 @@ import ( "time" "github.com/perses/perses-operator/api/v1alpha1" - common "github.com/perses/perses-operator/internal/perses/common" - subreconciler "github.com/perses/perses-operator/internal/subreconciler" + "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/subreconciler" logger "github.com/sirupsen/logrus" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" diff --git a/controllers/perses_controller_test.go b/controllers/perses_controller_test.go index db192bd..536daa8 100644 --- a/controllers/perses_controller_test.go +++ b/controllers/perses_controller_test.go @@ -10,7 +10,7 @@ import ( . "github.com/onsi/gomega" persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1" persescontroller "github.com/perses/perses-operator/controllers/perses" - common "github.com/perses/perses-operator/internal/perses/common" + "github.com/perses/perses-operator/internal/perses/common" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -144,7 +144,7 @@ var _ = Describe("Perses controller", func() { By("Checking the latest Status Condition added to the Perses instance") Eventually(func() error { - if perses.Status.Conditions != nil && len(perses.Status.Conditions) != 0 { + if len(perses.Status.Conditions) != 0 { latestStatusCondition := perses.Status.Conditions[len(perses.Status.Conditions)-1] expectedLatestStatusCondition := metav1.Condition{Type: common.TypeAvailablePerses, Status: metav1.ConditionTrue, Reason: "Reconciling", @@ -184,7 +184,7 @@ var _ = Describe("Perses controller", func() { By("Checking the latest Status Condition added to the Perses instance") Eventually(func() error { - if perses.Status.Conditions != nil && len(perses.Status.Conditions) != 0 { + if len(perses.Status.Conditions) != 0 { latestStatusCondition := perses.Status.Conditions[len(perses.Status.Conditions)-1] expectedLatestStatusCondition := metav1.Condition{Type: common.TypeAvailablePerses, Status: metav1.ConditionTrue, Reason: "Finalizing", diff --git a/internal/perses/common/perses_client_factory.go b/internal/perses/common/perses_client_factory.go index 7345206..43bbcb0 100644 --- a/internal/perses/common/perses_client_factory.go +++ b/internal/perses/common/perses_client_factory.go @@ -5,7 +5,7 @@ import ( persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1" v1 "github.com/perses/perses/pkg/client/api/v1" - perseshttp "github.com/perses/perses/pkg/client/perseshttp" + "github.com/perses/perses/pkg/client/perseshttp" ) type PersesClientFactory interface {