From cc4002bb11367ef80e40a4d3e381d392fcf11426 Mon Sep 17 00:00:00 2001 From: Daniel Hrabovcak Date: Wed, 20 Sep 2023 16:03:29 -0400 Subject: [PATCH] Fix lint warnings in e2e package (#572) --- Makefile | 2 +- e2e/alertmanager_test.go | 14 ++++++-------- e2e/collector_test.go | 6 +++--- e2e/operator_context_test.go | 23 +++++++++++++---------- e2e/ruler_test.go | 7 +++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index e3b22088cf..4c7a22d5bf 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ clean: ## Clean build time resources, primarily, unused docker images. lint: ## Lint code. ## @echo ">> linting code" - DOCKER_BUILDKIT=1 docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.43.0 golangci-lint run -v --timeout=5m + DOCKER_BUILDKIT=1 docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run -v --timeout=5m $(GOCMDS): ## Build go binary from cmd/ (e.g. 'operator'). ## The following env variables configure the build, and are mutually exclusive: diff --git a/e2e/alertmanager_test.go b/e2e/alertmanager_test.go index b05d6a585b..080514cc16 100644 --- a/e2e/alertmanager_test.go +++ b/e2e/alertmanager_test.go @@ -28,8 +28,6 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" - - v1 "k8s.io/api/core/v1" ) func TestAlertmanagerDefault(t *testing.T) { @@ -41,7 +39,7 @@ receivers: route: receiver: "foobar" ` - secret := &v1.Secret{ + secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Name: operator.AlertmanagerPublicSecretName}, Data: map[string][]byte{ operator.AlertmanagerPublicSecretKey: []byte(alertmanagerConfig), @@ -61,14 +59,14 @@ route: receiver: "foobar" ` spec := &monitoringv1.ManagedAlertmanagerSpec{ - ConfigSecret: &v1.SecretKeySelector{ - LocalObjectReference: v1.LocalObjectReference{ - "my-secret-name", + ConfigSecret: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "my-secret-name", }, Key: "my-secret-key", }, } - secret := &v1.Secret{ + secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Name: "my-secret-name"}, Data: map[string][]byte{ "my-secret-key": []byte(alertmanagerConfig), @@ -129,7 +127,7 @@ func testAlertmanagerDeployed(spec *monitoringv1.ManagedAlertmanagerSpec) func(c ManagedAlertmanager: spec, } if gcpServiceAccount != "" { - opCfg.Collection.Credentials = &v1.SecretKeySelector{ + opCfg.Collection.Credentials = &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "user-gcp-service-account", }, diff --git a/e2e/collector_test.go b/e2e/collector_test.go index 6045cb9a4f..2142f07a5e 100644 --- a/e2e/collector_test.go +++ b/e2e/collector_test.go @@ -23,16 +23,16 @@ import ( "time" gcm "cloud.google.com/go/monitoring/apiv3/v2" + gcmpb "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb" "github.com/google/go-cmp/cmp" "google.golang.org/api/iterator" - gcmpb "google.golang.org/genproto/googleapis/monitoring/v3" "google.golang.org/protobuf/types/known/timestamppb" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/wait" + // Blank import required to register GCP auth handlers to talk to GKE clusters. _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" @@ -75,7 +75,7 @@ func testCollectorDeployed(ctx context.Context, t *OperatorContext) { }, } if gcpServiceAccount != "" { - opCfg.Collection.Credentials = &v1.SecretKeySelector{ + opCfg.Collection.Credentials = &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "user-gcp-service-account", }, diff --git a/e2e/operator_context_test.go b/e2e/operator_context_test.go index b0aa813a2f..ff74f20e59 100644 --- a/e2e/operator_context_test.go +++ b/e2e/operator_context_test.go @@ -288,6 +288,9 @@ func (tctx *OperatorContext) createBaseResources(ctx context.Context) ([]metav1. return nil, fmt.Errorf("read collector YAML: %w", err) } obj, _, err := scheme.Codecs.UniversalDeserializer().Decode(collectorBytes, nil, nil) + if err != nil { + return nil, fmt.Errorf("decode collector: %w", err) + } collector := obj.(*appsv1.DaemonSet) collector.Namespace = tctx.namespace @@ -301,6 +304,9 @@ func (tctx *OperatorContext) createBaseResources(ctx context.Context) ([]metav1. } obj, _, err = scheme.Codecs.UniversalDeserializer().Decode(evaluatorBytes, nil, nil) + if err != nil { + return nil, fmt.Errorf("decode evaluator: %w", err) + } evaluator := obj.(*appsv1.Deployment) evaluator.Namespace = tctx.namespace @@ -318,23 +324,20 @@ func (tctx *OperatorContext) createBaseResources(ctx context.Context) ([]metav1. if err != nil { return nil, fmt.Errorf("deserializing alertmanager manifest: %w", err) } - switch obj.(type) { + switch obj := obj.(type) { case *appsv1.StatefulSet: - alertmanager := obj.(*appsv1.StatefulSet) - alertmanager.Namespace = tctx.namespace - if _, err := tctx.kubeClient.AppsV1().StatefulSets(tctx.namespace).Create(ctx, alertmanager, metav1.CreateOptions{}); err != nil { + obj.Namespace = tctx.namespace + if _, err := tctx.kubeClient.AppsV1().StatefulSets(tctx.namespace).Create(ctx, obj, metav1.CreateOptions{}); err != nil { return nil, fmt.Errorf("create alertmanager statefulset: %w", err) } case *corev1.Secret: - amSecret := obj.(*corev1.Secret) - amSecret.Namespace = tctx.namespace - if _, err := tctx.kubeClient.CoreV1().Secrets(tctx.namespace).Create(ctx, amSecret, metav1.CreateOptions{}); err != nil { + obj.Namespace = tctx.namespace + if _, err := tctx.kubeClient.CoreV1().Secrets(tctx.namespace).Create(ctx, obj, metav1.CreateOptions{}); err != nil { return nil, fmt.Errorf("create alertmanager secret: %w", err) } case *corev1.Service: - amSvc := obj.(*corev1.Service) - amSvc.Namespace = tctx.namespace - if _, err := tctx.kubeClient.CoreV1().Services(tctx.namespace).Create(ctx, amSvc, metav1.CreateOptions{}); err != nil { + obj.Namespace = tctx.namespace + if _, err := tctx.kubeClient.CoreV1().Services(tctx.namespace).Create(ctx, obj, metav1.CreateOptions{}); err != nil { return nil, fmt.Errorf("create alertmanager service: %w", err) } } diff --git a/e2e/ruler_test.go b/e2e/ruler_test.go index 0096181825..9fc933ae6e 100644 --- a/e2e/ruler_test.go +++ b/e2e/ruler_test.go @@ -22,14 +22,13 @@ import ( "time" gcm "cloud.google.com/go/monitoring/apiv3/v2" + gcmpb "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb" "github.com/GoogleCloudPlatform/prometheus-engine/pkg/operator" monitoringv1 "github.com/GoogleCloudPlatform/prometheus-engine/pkg/operator/apis/monitoring/v1" "github.com/google/go-cmp/cmp" "google.golang.org/api/iterator" - gcmpb "google.golang.org/genproto/googleapis/monitoring/v3" "google.golang.org/protobuf/types/known/timestamppb" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -98,7 +97,7 @@ func testRuleEvaluatorOperatorConfig(ctx context.Context, t *OperatorContext) { Scheme: "https", Authorization: &monitoringv1.Authorization{ Type: "Bearer", - Credentials: &v1.SecretKeySelector{ + Credentials: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "alertmanager-authorization", }, @@ -117,7 +116,7 @@ func testRuleEvaluatorOperatorConfig(ctx context.Context, t *OperatorContext) { }, } if gcpServiceAccount != "" { - opCfg.Rules.Credentials = &v1.SecretKeySelector{ + opCfg.Rules.Credentials = &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "user-gcp-service-account", },