1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 19:49:46 +00:00

*: fix staticcheck errors

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2021-03-14 23:11:05 +01:00
parent 25e085a357
commit 430e29d2a4
15 changed files with 56 additions and 29 deletions

View file

@ -6,4 +6,5 @@ linters:
enable:
- golint
- govet
- staticcheck
- unused

View file

@ -455,7 +455,7 @@ func Main() int {
wg.Go(serveTLS(srv, l, logger))
}
term := make(chan os.Signal)
term := make(chan os.Signal, 1)
signal.Notify(term, os.Interrupt, syscall.SIGTERM)
select {

4
go.mod
View file

@ -11,8 +11,7 @@ require (
github.com/go-kit/kit v0.10.0
github.com/go-openapi/swag v0.19.12
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.4.3
github.com/google/go-cmp v0.5.4
github.com/google/go-cmp v0.5.5
github.com/hashicorp/go-version v1.2.1
github.com/kylelemons/godebug v1.1.0
github.com/mitchellh/hashstructure v1.0.1-0.20200508175121-8fdbea448aa6
@ -28,6 +27,7 @@ require (
github.com/stretchr/testify v1.6.1
github.com/thanos-io/thanos v0.17.2
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
google.golang.org/protobuf v1.26.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.20.1

7
go.sum
View file

@ -552,6 +552,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@ -573,6 +575,8 @@ github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
@ -1748,6 +1752,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=

View file

@ -43,6 +43,9 @@ func loadCfg(s string) (*alertmanagerConfig, error) {
cfg := &alertmanagerConfig{}
err = yaml.UnmarshalStrict([]byte(s), cfg)
if err != nil {
return nil, err
}
return cfg, nil
}

View file

@ -620,6 +620,7 @@ func subPathForStorage(s *monitoringv1.StorageSpec) string {
return ""
}
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
if s.DisableMountSubPath {
return ""
}

View file

@ -1262,9 +1262,12 @@ func (c *Operator) sync(ctx context.Context, key string) error {
propagationPolicy := metav1.DeletePropagationForeground
if err := ssetClient.Delete(context.TODO(), s.GetName(), metav1.DeleteOptions{PropagationPolicy: &propagationPolicy}); err != nil {
level.Error(c.logger).Log("failed to delete StatefulSet to cleanup")
level.Error(c.logger).Log("err", err, "name", s.GetName(), "namespace", s.GetNamespace())
}
})
if err != nil {
return errors.Wrap(err, "listing StatefulSet resources failed")
}
return nil
}

View file

@ -547,16 +547,17 @@ func (cg *configGenerator) generatePodMonitorConfig(
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_container_port_name"}},
{Key: "regex", Value: ep.Port},
})
} else if ep.TargetPort != nil {
} else if ep.TargetPort != nil { //nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
level.Warn(cg.logger).Log("msg", "PodMonitor 'targetPort' is deprecated, use 'port' instead.",
"podMonitor", m.Name)
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
if ep.TargetPort.StrVal != "" {
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_container_port_name"}},
{Key: "regex", Value: ep.TargetPort.String()},
})
} else if ep.TargetPort.IntVal != 0 {
} else if ep.TargetPort.IntVal != 0 { //nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_container_port_number"}},
@ -615,10 +616,10 @@ func (cg *configGenerator) generatePodMonitorConfig(
{Key: "target_label", Value: "endpoint"},
{Key: "replacement", Value: ep.Port},
})
} else if ep.TargetPort != nil && ep.TargetPort.String() != "" {
} else if ep.TargetPort != nil && ep.TargetPort.String() != "" { //nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
relabelings = append(relabelings, yaml.MapSlice{
{Key: "target_label", Value: "endpoint"},
{Key: "replacement", Value: ep.TargetPort.String()},
{Key: "replacement", Value: ep.TargetPort.String()}, //nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
})
}

View file

@ -864,6 +864,7 @@ func prefixedName(name string) string {
}
func subPathForStorage(s *monitoringv1.StorageSpec) string {
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
if s == nil || s.DisableMountSubPath {
return ""
}

View file

@ -24,6 +24,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@ -34,7 +35,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
"github.com/golang/protobuf/proto"
"github.com/prometheus-operator/prometheus-operator/pkg/alertmanager"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
@ -114,7 +114,7 @@ func testAMVersionMigration(t *testing.T) {
}
am.Spec.Version = "v0.16.2"
am, err = framework.UpdateAlertmanagerAndWaitUntilReady(ns, am)
_, err = framework.UpdateAlertmanagerAndWaitUntilReady(ns, am)
if err != nil {
t.Fatal(err)
}
@ -150,7 +150,7 @@ func testAMStorageUpdate(t *testing.T) {
},
}
am, err = framework.MonClientV1.Alertmanagers(ns).Update(context.TODO(), am, metav1.UpdateOptions{})
_, err = framework.MonClientV1.Alertmanagers(ns).Update(context.TODO(), am, metav1.UpdateOptions{})
if err != nil {
t.Fatal(err)
}
@ -1273,7 +1273,7 @@ func testAMPreserveUserAddedMetadata(t *testing.T) {
// Ensure resource reconciles
alertManager.Spec.Replicas = proto.Int32(2)
alertManager, err = framework.UpdateAlertmanagerAndWaitUntilReady(ns, alertManager)
_, err = framework.UpdateAlertmanagerAndWaitUntilReady(ns, alertManager)
if err != nil {
t.Fatal(err)
}

View file

@ -55,7 +55,7 @@ func testDenyPrometheus(t *testing.T) {
for _, allowed := range allowedNamespaces {
ctx.SetupPrometheusRBAC(t, allowed, framework.KubeClient)
p := framework.MakeBasicPrometheus(allowed, "allowed", "allowed", 1)
p, err = framework.CreatePrometheusAndWaitUntilReady(allowed, p)
_, err = framework.CreatePrometheusAndWaitUntilReady(allowed, p)
if err != nil {
t.Fatal(err)
}
@ -150,7 +150,7 @@ func testDenyServiceMonitor(t *testing.T) {
for _, allowed := range allowedNamespaces {
ctx.SetupPrometheusRBAC(t, allowed, framework.KubeClient)
p := framework.MakeBasicPrometheus(allowed, "allowed", "allowed", 1)
p, err = framework.CreatePrometheusAndWaitUntilReady(allowed, p)
_, err = framework.CreatePrometheusAndWaitUntilReady(allowed, p)
if err != nil {
t.Fatal(err)
}

View file

@ -306,6 +306,9 @@ func testPrometheusInstanceNamespacesAllowList(t *testing.T) {
// assert that no prometheus target points to the "instance" namespace
targets, err := framework.GetActiveTargets(instanceNs, "prometheus-instance")
if err != nil {
t.Fatal(err)
}
for _, target := range targets {
for k, v := range target.Labels {
if k == "namespace" && v == instanceNs {

View file

@ -32,6 +32,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
"google.golang.org/protobuf/proto"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
@ -46,7 +47,6 @@ import (
"github.com/prometheus-operator/prometheus-operator/pkg/prometheus"
testFramework "github.com/prometheus-operator/prometheus-operator/test/framework"
"github.com/golang/protobuf/proto"
"github.com/kylelemons/godebug/pretty"
"github.com/pkg/errors"
)
@ -826,7 +826,7 @@ func testPromScaleUpDownCluster(t *testing.T) {
}
p.Spec.Replicas = proto.Int32(2)
p, err = framework.UpdatePrometheusAndWaitUntilReady(ns, p)
_, err = framework.UpdatePrometheusAndWaitUntilReady(ns, p)
if err != nil {
t.Fatal(err)
}
@ -1048,7 +1048,7 @@ func testPromStorageUpdate(t *testing.T) {
},
},
}
p, err = framework.MonClientV1.Prometheuses(ns).Update(context.TODO(), p, metav1.UpdateOptions{})
_, err = framework.MonClientV1.Prometheuses(ns).Update(context.TODO(), p, metav1.UpdateOptions{})
if err != nil {
t.Fatal(err)
}
@ -1356,7 +1356,7 @@ func testPromReloadRules(t *testing.T) {
},
},
}
ruleFile, err = framework.UpdateRule(ns, ruleFile)
_, err = framework.UpdateRule(ns, ruleFile)
if err != nil {
t.Fatal(err)
}
@ -1728,6 +1728,7 @@ func testPromOnlyUpdatedOnRelevantChanges(t *testing.T) {
resourceDefinitions[i].Versions = map[string]interface{}{}
}
errc := make(chan error, 1)
go func() {
for {
select {
@ -1743,7 +1744,8 @@ func testPromOnlyUpdatedOnRelevantChanges(t *testing.T) {
}
if err != nil {
cancel()
t.Fatal(err)
errc <- err
return
}
resourceDefinitions[i].Versions[resource.GetResourceVersion()] = resource
@ -1790,6 +1792,12 @@ func testPromOnlyUpdatedOnRelevantChanges(t *testing.T) {
cancel()
select {
case err := <-errc:
t.Fatal(err)
default:
}
for _, resource := range resourceDefinitions {
if len(resource.Versions) > resource.MaxExpectedChanges || len(resource.Versions) < 1 {
var previous interface{}
@ -1902,7 +1910,7 @@ func testPromPreserveUserAddedMetadata(t *testing.T) {
// Ensure resource reconciles
prometheusCRD.Spec.Replicas = proto.Int32(2)
prometheusCRD, err = framework.UpdatePrometheusAndWaitUntilReady(ns, prometheusCRD)
_, err = framework.UpdatePrometheusAndWaitUntilReady(ns, prometheusCRD)
if err != nil {
t.Fatal(err)
}
@ -2047,7 +2055,7 @@ func testPromDiscovery(t *testing.T) {
}
p := framework.MakeBasicPrometheus(ns, prometheusName, group, 1)
p, err := framework.CreatePrometheusAndWaitUntilReady(ns, p)
_, err := framework.CreatePrometheusAndWaitUntilReady(ns, p)
if err != nil {
t.Fatal(err)
}
@ -2085,7 +2093,7 @@ func testPromSharedResourcesReconciliation(t *testing.T) {
// Create 2 Prometheus different Prometheus instances that watch the service monitor created above.
for _, prometheusName := range []string{"test", "test2"} {
p := framework.MakeBasicPrometheus(ns, prometheusName, "reconcile-test", 1)
p, err := framework.CreatePrometheusAndWaitUntilReady(ns, p)
_, err := framework.CreatePrometheusAndWaitUntilReady(ns, p)
if err != nil {
t.Fatal(err)
}
@ -2142,7 +2150,7 @@ func testShardingProvisioning(t *testing.T) {
p := framework.MakeBasicPrometheus(ns, prometheusName, group, 1)
shards := int32(2)
p.Spec.Shards = &shards
p, err := framework.CreatePrometheusAndWaitUntilReady(ns, p)
_, err := framework.CreatePrometheusAndWaitUntilReady(ns, p)
if err != nil {
t.Fatal(err)
}
@ -2283,7 +2291,7 @@ func testPromAlertmanagerDiscovery(t *testing.T) {
p := framework.MakeBasicPrometheus(ns, prometheusName, group, 1)
framework.AddAlertingToPrometheus(p, ns, alertmanagerName)
p, err := framework.CreatePrometheusAndWaitUntilReady(ns, p)
_, err := framework.CreatePrometheusAndWaitUntilReady(ns, p)
if err != nil {
t.Fatal(err)
}

View file

@ -15,11 +15,10 @@
package e2e
import (
"github.com/golang/protobuf/proto"
"context"
"testing"
"google.golang.org/protobuf/proto"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@ -109,7 +108,7 @@ func testTRPreserveUserAddedMetadata(t *testing.T) {
// Ensure resource reconciles
thanosRuler.Spec.Replicas = proto.Int32(2)
thanosRuler, err = framework.UpdateThanosRulerAndWaitUntilReady(ns, thanosRuler)
_, err = framework.UpdateThanosRulerAndWaitUntilReady(ns, thanosRuler)
if err != nil {
t.Fatal(err)
}

View file

@ -75,8 +75,8 @@ func main() {
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, time.Now().String())
fmt.Fprintf(w, "\nAppVersion:"+os.Getenv("VERSION"))
fmt.Fprint(w, time.Now().String())
fmt.Fprint(w, "\nAppVersion:"+os.Getenv("VERSION"))
}
func checkBasicAuth(w http.ResponseWriter, r *http.Request) bool {