Skip to content

Commit

Permalink
Fix lint warnings in e2e package (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpiritXIII authored Sep 20, 2023
1 parent 2a05ea2 commit cc4002b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 6 additions & 8 deletions e2e/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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",
},
Expand Down
6 changes: 3 additions & 3 deletions e2e/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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",
},
Expand Down
23 changes: 13 additions & 10 deletions e2e/operator_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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)
}
}
Expand Down
7 changes: 3 additions & 4 deletions e2e/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand Down

0 comments on commit cc4002b

Please sign in to comment.