mirror of
https://github.com/coreos/prometheus-operator.git
synced 2026-02-05 15:46:31 +01:00
Fully enable depguard (#6103)
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
This commit is contained in:
committed by
GitHub
parent
2d53c246eb
commit
0a2b02340a
@@ -17,12 +17,12 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
k8sYAML "k8s.io/apimachinery/pkg/util/yaml"
|
||||
@@ -103,10 +103,9 @@ func CMToRule(cm *v1.ConfigMap) ([]monitoringv1.PrometheusRule, error) {
|
||||
ruleSpec := monitoringv1.PrometheusRuleSpec{}
|
||||
|
||||
if err := k8sYAML.NewYAMLOrJSONDecoder(bytes.NewBufferString(content), 1000).Decode(&ruleSpec); err != nil {
|
||||
return []monitoringv1.PrometheusRule{}, errors.Wrapf(
|
||||
err,
|
||||
"unmarshal rules file %v in configmap '%v' in namespace '%v'",
|
||||
name, cm.Name, cm.Namespace,
|
||||
return []monitoringv1.PrometheusRule{}, fmt.Errorf(
|
||||
"unmarshal rules file %v in configmap '%v' in namespace '%v': %w",
|
||||
name, cm.Name, cm.Namespace, err,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ package framework
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -68,7 +68,10 @@ func (f *Framework) WaitForConfigMapExist(ctx context.Context, ns, name string)
|
||||
return true, nil
|
||||
})
|
||||
|
||||
return configMap, errors.Wrapf(err, "waiting for ConfigMap '%v' in namespace '%v'", name, ns)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("waiting for ConfigMap '%v' in namespace '%v': %w", name, ns, err)
|
||||
}
|
||||
return configMap, nil
|
||||
}
|
||||
|
||||
func (f *Framework) WaitForConfigMapNotExist(ctx context.Context, ns, name string) error {
|
||||
@@ -89,5 +92,8 @@ func (f *Framework) WaitForConfigMapNotExist(ctx context.Context, ns, name strin
|
||||
return false, nil
|
||||
})
|
||||
|
||||
return errors.Wrapf(err, "waiting for ConfigMap '%v' in namespace '%v' to not exist", name, ns)
|
||||
if err != nil {
|
||||
return fmt.Errorf("waiting for ConfigMap '%v' in namespace '%v' to not exist: %w", name, ns, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -43,7 +42,7 @@ func MakeDeployment(source string) (*appsv1.Deployment, error) {
|
||||
}
|
||||
deployment := appsv1.Deployment{}
|
||||
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&deployment); err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("failed to decode file %s", source))
|
||||
return nil, fmt.Errorf("failed to decode file %s: %w", source, err)
|
||||
}
|
||||
|
||||
return &deployment, nil
|
||||
@@ -53,7 +52,7 @@ func (f *Framework) CreateDeployment(ctx context.Context, namespace string, d *a
|
||||
d.Namespace = namespace
|
||||
_, err := f.KubeClient.AppsV1().Deployments(namespace).Create(ctx, d, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to create deployment %s", d.Name))
|
||||
return fmt.Errorf("failed to create deployment %s: %w", d.Name, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -62,30 +61,30 @@ func (f *Framework) CreateOrUpdateDeploymentAndWaitUntilReady(ctx context.Contex
|
||||
deployment.Namespace = namespace
|
||||
d, err := f.KubeClient.AppsV1().Deployments(namespace).Get(ctx, deployment.Name, metav1.GetOptions{})
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to get deployment %s", deployment.Name))
|
||||
return fmt.Errorf("failed to get deployment %s: %w", deployment.Name, err)
|
||||
}
|
||||
|
||||
if apierrors.IsNotFound(err) {
|
||||
// Deployment doesn't exists -> Create
|
||||
_, err = f.KubeClient.AppsV1().Deployments(namespace).Create(ctx, deployment, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to create deployment %s", deployment.Name))
|
||||
return fmt.Errorf("failed to create deployment %s: %w", deployment.Name, err)
|
||||
}
|
||||
|
||||
err = f.WaitForDeploymentReady(ctx, namespace, deployment.Name, 1)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("after create, waiting for deployment %v to become ready timed out", deployment.Name))
|
||||
return fmt.Errorf("after create, waiting for deployment %v to become ready timed out: %w", deployment.Name, err)
|
||||
}
|
||||
} else {
|
||||
// Deployment already exists -> Update
|
||||
_, err = f.KubeClient.AppsV1().Deployments(namespace).Update(ctx, deployment, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to update deployment %s", deployment.Name))
|
||||
return fmt.Errorf("failed to update deployment %s: %w", deployment.Name, err)
|
||||
}
|
||||
|
||||
err = f.WaitForDeploymentReady(ctx, namespace, deployment.Name, d.Status.ObservedGeneration+1)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("after update, waiting for deployment %v to become ready timed out", deployment.Name))
|
||||
return fmt.Errorf("after update, waiting for deployment %v to become ready timed out: %w", deployment.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/model/textparse"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
@@ -46,12 +45,12 @@ func SourceToIOReader(source string) (io.Reader, error) {
|
||||
func PathToOSFile(relativePath string) (*os.File, error) {
|
||||
path, err := filepath.Abs(relativePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("failed generate absolute file path of %s", relativePath))
|
||||
return nil, fmt.Errorf("failed generate absolute file path of %s: %w", relativePath, err)
|
||||
}
|
||||
|
||||
manifest, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("failed to open file %s", path))
|
||||
return nil, fmt.Errorf("failed to open file %s: %w", path, err)
|
||||
}
|
||||
|
||||
return manifest, nil
|
||||
@@ -71,11 +70,12 @@ func URLToIOReader(url string) (io.Reader, error) {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf(
|
||||
"waiting for %v to return a successful status code timed out. Last response from server was: %v",
|
||||
return nil, fmt.Errorf(
|
||||
"waiting for %v to return a successful status code timed out. Last response from server was: %v: %w",
|
||||
url,
|
||||
resp,
|
||||
))
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
return resp.Body, nil
|
||||
@@ -141,11 +141,15 @@ func WaitForHTTPSuccessStatusCode(timeout time.Duration, url string) error {
|
||||
return false, nil
|
||||
})
|
||||
|
||||
return errors.Wrap(err, fmt.Sprintf(
|
||||
"waiting for %v to return a successful status code timed out. Last response from server was: %v",
|
||||
url,
|
||||
resp,
|
||||
))
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"waiting for %v to return a successful status code timed out. Last response from server was: %v: %w",
|
||||
url,
|
||||
resp,
|
||||
err,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func podRunsImage(p v1.Pod, image string) bool {
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
networkv1 "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -60,39 +59,41 @@ func MakeBasicIngress(serviceName string, servicePort int) *networkv1.Ingress {
|
||||
}
|
||||
|
||||
func (f *Framework) CreateIngress(ctx context.Context, namespace string, i *networkv1.Ingress) error {
|
||||
_, err := f.KubeClient.NetworkingV1().Ingresses(namespace).Create(ctx, i, metav1.CreateOptions{})
|
||||
return errors.Wrap(err, fmt.Sprintf("creating ingress %v failed", i.Name))
|
||||
if _, err := f.KubeClient.NetworkingV1().Ingresses(namespace).Create(ctx, i, metav1.CreateOptions{}); err != nil {
|
||||
return fmt.Errorf("creating ingress %v failed: %w", i.Name, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Framework) SetupNginxIngressControllerIncDefaultBackend(ctx context.Context, namespace string) error {
|
||||
// Create Nginx Ingress Replication Controller
|
||||
if err := f.createReplicationControllerViaYml(ctx, namespace, "./framework/resources/nxginx-ingress-controller.yml"); err != nil {
|
||||
return errors.Wrap(err, "creating nginx ingress replication controller failed")
|
||||
return fmt.Errorf("creating nginx ingress replication controller failed: %w", err)
|
||||
}
|
||||
|
||||
// Create Default HTTP Backend Replication Controller
|
||||
if err := f.createReplicationControllerViaYml(ctx, namespace, "./framework/resources/default-http-backend.yml"); err != nil {
|
||||
return errors.Wrap(err, "creating default http backend replication controller failed")
|
||||
return fmt.Errorf("creating default http backend replication controller failed: %w", err)
|
||||
}
|
||||
|
||||
// Create Default HTTP Backend Service
|
||||
manifest, err := os.Open("./framework/resources/default-http-backend-service.yml")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "reading default http backend service yaml failed")
|
||||
return fmt.Errorf("reading default http backend service yaml failed: %w", err)
|
||||
}
|
||||
|
||||
service := v1.Service{}
|
||||
err = yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&service)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "decoding http backend service yaml failed")
|
||||
return fmt.Errorf("decoding http backend service yaml failed: %w", err)
|
||||
}
|
||||
|
||||
_, err = f.KubeClient.CoreV1().Services(namespace).Create(ctx, &service, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("creating http backend service %v failed", service.Name))
|
||||
return fmt.Errorf("creating http backend service %v failed: %w", service.Name, err)
|
||||
}
|
||||
if err := f.WaitForServiceReady(ctx, namespace, service.Name); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("waiting for http backend service %v timed out", service.Name))
|
||||
return fmt.Errorf("waiting for http backend service %v timed out: %w", service.Name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -101,28 +102,28 @@ func (f *Framework) SetupNginxIngressControllerIncDefaultBackend(ctx context.Con
|
||||
func (f *Framework) DeleteNginxIngressControllerIncDefaultBackend(ctx context.Context, namespace string) error {
|
||||
// Delete Nginx Ingress Replication Controller
|
||||
if err := f.deleteReplicationControllerViaYml(ctx, namespace, "./framework/resources/nxginx-ingress-controller.yml"); err != nil {
|
||||
return errors.Wrap(err, "deleting nginx ingress replication controller failed")
|
||||
return fmt.Errorf("deleting nginx ingress replication controller failed: %w", err)
|
||||
}
|
||||
|
||||
// Delete Default HTTP Backend Replication Controller
|
||||
if err := f.deleteReplicationControllerViaYml(ctx, namespace, "./framework/resources/default-http-backend.yml"); err != nil {
|
||||
return errors.Wrap(err, "deleting default http backend replication controller failed")
|
||||
return fmt.Errorf("deleting default http backend replication controller failed: %w", err)
|
||||
}
|
||||
|
||||
// Delete Default HTTP Backend Service
|
||||
manifest, err := os.Open("./framework/resources/default-http-backend-service.yml")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "reading default http backend service yaml failed")
|
||||
return fmt.Errorf("reading default http backend service yaml failed: %w", err)
|
||||
}
|
||||
|
||||
service := v1.Service{}
|
||||
err = yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&service)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "decoding http backend service yaml failed")
|
||||
return fmt.Errorf("decoding http backend service yaml failed: %w", err)
|
||||
}
|
||||
|
||||
if err := f.KubeClient.CoreV1().Services(namespace).Delete(ctx, service.Name, metav1.DeleteOptions{}); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("deleting http backend service %v failed", service.Name))
|
||||
return fmt.Errorf("deleting http backend service %v failed: %w", service.Name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -134,7 +135,7 @@ func (f *Framework) GetIngressIP(ctx context.Context, namespace string, ingressN
|
||||
var err error
|
||||
ingress, err = f.KubeClient.NetworkingV1().Ingresses(namespace).Get(ctx, ingressName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, fmt.Sprintf("requesting the ingress %v failed", ingressName))
|
||||
return false, fmt.Errorf("requesting the ingress %v failed: %w", ingressName, err)
|
||||
}
|
||||
ingresses := ingress.Status.LoadBalancer.Ingress
|
||||
if len(ingresses) != 0 {
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
@@ -33,7 +32,7 @@ func (f *Framework) CreateNamespace(ctx context.Context, t *testing.T, testCtx *
|
||||
rn := k8sutil.ResourceNamer{}
|
||||
name, err := rn.UniqueDNS1123Label(name)
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, fmt.Sprintf("failed to generate a namespace name %v", name)))
|
||||
t.Fatal(fmt.Errorf("failed to generate a namespace name %v: %w", name, err))
|
||||
}
|
||||
|
||||
_, err = f.KubeClient.CoreV1().Namespaces().Create(ctx, &v1.Namespace{
|
||||
@@ -43,7 +42,7 @@ func (f *Framework) CreateNamespace(ctx context.Context, t *testing.T, testCtx *
|
||||
}, metav1.CreateOptions{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, fmt.Sprintf("failed to create namespace with name %v", name)))
|
||||
t.Fatal(fmt.Errorf("failed to create namespace with name %v: %w", name, err))
|
||||
}
|
||||
|
||||
namespaceFinalizerFn := func() error {
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
kscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
@@ -37,14 +36,14 @@ import (
|
||||
func (f *Framework) PrintPodLogs(ctx context.Context, ns, p string) error {
|
||||
pod, err := f.KubeClient.CoreV1().Pods(ns).Get(ctx, p, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to print logs of pod '%v': failed to get pod", p)
|
||||
return fmt.Errorf("failed to print logs of pod '%v': failed to get pod: %w", p, err)
|
||||
}
|
||||
|
||||
for _, c := range pod.Spec.Containers {
|
||||
req := f.KubeClient.CoreV1().Pods(ns).GetLogs(p, &v1.PodLogOptions{Container: c.Name})
|
||||
resp, err := req.DoRaw(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to retrieve logs of pod '%v'", p)
|
||||
return fmt.Errorf("failed to retrieve logs of pod '%v': %w", p, err)
|
||||
}
|
||||
|
||||
fmt.Printf("=== Logs of %v/%v/%v:", ns, p, c.Name)
|
||||
@@ -59,7 +58,7 @@ func (f *Framework) PrintPodLogs(ctx context.Context, ns, p string) error {
|
||||
func (f *Framework) GetPodRestartCount(ctx context.Context, ns, podName string) (map[string]int32, error) {
|
||||
pod, err := f.KubeClient.CoreV1().Pods(ns).Get(ctx, podName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to retrieve pod to get restart count")
|
||||
return nil, fmt.Errorf("failed to retrieve pod to get restart count: %w", err)
|
||||
}
|
||||
|
||||
restarts := map[string]int32{}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -343,7 +342,7 @@ func (f *Framework) PatchPrometheus(ctx context.Context, name, ns string, spec m
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal Prometheus spec")
|
||||
return nil, fmt.Errorf("failed to marshal Prometheus spec: %w", err)
|
||||
}
|
||||
|
||||
p, err := f.MonClientV1.Prometheuses(ns).Patch(
|
||||
@@ -367,7 +366,7 @@ func (f *Framework) PatchPrometheus(ctx context.Context, name, ns string, spec m
|
||||
func (f *Framework) PatchPrometheusAndWaitUntilReady(ctx context.Context, name, ns string, spec monitoringv1.PrometheusSpec) (*monitoringv1.Prometheus, error) {
|
||||
p, err := f.PatchPrometheus(ctx, name, ns, spec)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to patch Prometheus %s/%s", ns, name)
|
||||
return nil, fmt.Errorf("failed to patch Prometheus %s/%s: %w", ns, name, err)
|
||||
}
|
||||
|
||||
if err := f.WaitForPrometheusReady(ctx, p, 5*time.Minute); err != nil {
|
||||
@@ -399,7 +398,7 @@ func (f *Framework) WaitForPrometheusReady(ctx context.Context, p *monitoringv1.
|
||||
},
|
||||
timeout,
|
||||
); err != nil {
|
||||
return errors.Wrapf(err, "prometheus %v/%v failed to become available", p.Namespace, p.Name)
|
||||
return fmt.Errorf("prometheus %v/%v failed to become available: %w", p.Namespace, p.Name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -408,11 +407,11 @@ func (f *Framework) WaitForPrometheusReady(ctx context.Context, p *monitoringv1.
|
||||
func (f *Framework) DeletePrometheusAndWaitUntilGone(ctx context.Context, ns, name string) error {
|
||||
_, err := f.MonClientV1.Prometheuses(ns).Get(ctx, name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("requesting Prometheus custom resource %v failed", name))
|
||||
return fmt.Errorf("requesting Prometheus custom resource %v failed: %w", name, err)
|
||||
}
|
||||
|
||||
if err := f.MonClientV1.Prometheuses(ns).Delete(ctx, name, metav1.DeleteOptions{}); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("deleting Prometheus custom resource %v failed", name))
|
||||
return fmt.Errorf("deleting Prometheus custom resource %v failed: %w", name, err)
|
||||
}
|
||||
|
||||
if err := f.WaitForPodsReady(
|
||||
@@ -422,10 +421,7 @@ func (f *Framework) DeletePrometheusAndWaitUntilGone(ctx context.Context, ns, na
|
||||
0,
|
||||
prometheus.ListOptions(name),
|
||||
); err != nil {
|
||||
return errors.Wrap(
|
||||
err,
|
||||
fmt.Sprintf("waiting for Prometheus custom resource (%s) to vanish timed out", name),
|
||||
)
|
||||
return fmt.Errorf("waiting for Prometheus custom resource (%s) to vanish timed out: %w", name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -487,7 +483,7 @@ func (f *Framework) WaitForHealthyTargets(ctx context.Context, ns, svcName strin
|
||||
return true, nil
|
||||
}
|
||||
|
||||
loopErr = errors.Errorf("expected %d, found %d healthy targets", amount, len(targets))
|
||||
loopErr = fmt.Errorf("expected %d, found %d healthy targets", amount, len(targets))
|
||||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -609,7 +605,7 @@ func (f *Framework) GetHealthyTargets(ctx context.Context, ns, svcName string) (
|
||||
case healthGood:
|
||||
healthyTargets = append(healthyTargets, target)
|
||||
case healthBad:
|
||||
return nil, errors.Errorf("target %q: %s", target.ScrapeURL, target.LastError)
|
||||
return nil, fmt.Errorf("target %q: %s", target.ScrapeURL, target.LastError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,7 +624,7 @@ func (f *Framework) CheckPrometheusFiringAlert(ctx context.Context, ns, svcName,
|
||||
}
|
||||
|
||||
if len(q.Data.Result) != 1 {
|
||||
return false, errors.Errorf("expected 1 query result but got %v", len(q.Data.Result))
|
||||
return false, fmt.Errorf("expected 1 query result but got %v", len(q.Data.Result))
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -680,7 +676,7 @@ func (f *Framework) WaitForPrometheusFiringAlert(ctx context.Context, ns, svcNam
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errors.Errorf(
|
||||
return fmt.Errorf(
|
||||
"waiting for alert '%v' to fire: %v: %v",
|
||||
alertName,
|
||||
err,
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -102,7 +101,7 @@ func (f *Framework) WaitForPrometheusAgentReady(ctx context.Context, p *monitori
|
||||
},
|
||||
timeout,
|
||||
); err != nil {
|
||||
return errors.Wrapf(err, "prometheus-agent %v/%v failed to become available", p.Namespace, p.Name)
|
||||
return fmt.Errorf("prometheus-agent %v/%v failed to become available: %w", p.Namespace, p.Name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -111,11 +110,11 @@ func (f *Framework) WaitForPrometheusAgentReady(ctx context.Context, p *monitori
|
||||
func (f *Framework) DeletePrometheusAgentAndWaitUntilGone(ctx context.Context, ns, name string) error {
|
||||
_, err := f.MonClientV1alpha1.PrometheusAgents(ns).Get(ctx, name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("requesting PrometheusAgent custom resource %v failed", name))
|
||||
return fmt.Errorf("requesting PrometheusAgent custom resource %v failed: %w", name, err)
|
||||
}
|
||||
|
||||
if err := f.MonClientV1alpha1.PrometheusAgents(ns).Delete(ctx, name, metav1.DeleteOptions{}); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("deleting PrometheusAgent custom resource %v failed", name))
|
||||
return fmt.Errorf("deleting PrometheusAgent custom resource %v failed: %w", name, err)
|
||||
}
|
||||
|
||||
if err := f.WaitForPodsReady(
|
||||
@@ -125,10 +124,7 @@ func (f *Framework) DeletePrometheusAgentAndWaitUntilGone(ctx context.Context, n
|
||||
0,
|
||||
prometheusagent.ListOptions(name),
|
||||
); err != nil {
|
||||
return errors.Wrap(
|
||||
err,
|
||||
fmt.Sprintf("waiting for PrometheusAgent custom resource (%s) to vanish timed out", name),
|
||||
)
|
||||
return fmt.Errorf("waiting for PrometheusAgent custom resource (%s) to vanish timed out: %w", name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -34,7 +33,7 @@ func MakeService(source string) (*v1.Service, error) {
|
||||
}
|
||||
resource := v1.Service{}
|
||||
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("failed to decode file %s", source))
|
||||
return nil, fmt.Errorf("failed to decode file %s: %w", source, err)
|
||||
}
|
||||
|
||||
return &resource, nil
|
||||
@@ -45,13 +44,13 @@ func (f *Framework) CreateOrUpdateServiceAndWaitUntilReady(ctx context.Context,
|
||||
|
||||
s, err := f.KubeClient.CoreV1().Services(namespace).Get(ctx, service.Name, metav1.GetOptions{})
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
return finalizerFn, errors.Wrap(err, fmt.Sprintf("getting service %v failed", service.Name))
|
||||
return finalizerFn, fmt.Errorf("getting service %v failed: %w", service.Name, err)
|
||||
}
|
||||
|
||||
if apierrors.IsNotFound(err) {
|
||||
// Service doesn't exists -> Create
|
||||
if _, err := f.KubeClient.CoreV1().Services(namespace).Create(ctx, service, metav1.CreateOptions{}); err != nil {
|
||||
return finalizerFn, errors.Wrap(err, fmt.Sprintf("creating service %v failed", service.Name))
|
||||
return finalizerFn, fmt.Errorf("creating service %v failed: %w", service.Name, err)
|
||||
}
|
||||
} else {
|
||||
// must set these immutable fields from the existing service to prevent update fail
|
||||
@@ -62,12 +61,12 @@ func (f *Framework) CreateOrUpdateServiceAndWaitUntilReady(ctx context.Context,
|
||||
|
||||
// Service already exists -> Update
|
||||
if _, err := f.KubeClient.CoreV1().Services(namespace).Update(ctx, service, metav1.UpdateOptions{}); err != nil {
|
||||
return finalizerFn, errors.Wrap(err, fmt.Sprintf("updating service %v failed", service.Name))
|
||||
return finalizerFn, fmt.Errorf("updating service %v failed: %w", service.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := f.WaitForServiceReady(ctx, namespace, service.Name); err != nil {
|
||||
return finalizerFn, errors.Wrap(err, fmt.Sprintf("waiting for service %v to become ready timed out", service.Name))
|
||||
return finalizerFn, fmt.Errorf("waiting for service %v to become ready timed out: %w", service.Name, err)
|
||||
}
|
||||
return finalizerFn, nil
|
||||
}
|
||||
@@ -88,7 +87,7 @@ func (f *Framework) WaitForServiceReady(ctx context.Context, namespace string, s
|
||||
|
||||
func (f *Framework) DeleteServiceAndWaitUntilGone(ctx context.Context, namespace string, serviceName string) error {
|
||||
if err := f.KubeClient.CoreV1().Services(namespace).Delete(ctx, serviceName, metav1.DeleteOptions{}); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("deleting service %v failed", serviceName))
|
||||
return fmt.Errorf("deleting service %v failed: %w", serviceName, err)
|
||||
}
|
||||
|
||||
err := wait.PollUntilContextTimeout(ctx, 5*time.Second, time.Minute, false, func(ctx context.Context) (bool, error) {
|
||||
@@ -99,7 +98,7 @@ func (f *Framework) DeleteServiceAndWaitUntilGone(ctx context.Context, namespace
|
||||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "waiting for service to go away failed")
|
||||
return fmt.Errorf("waiting for service to go away failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -108,7 +107,7 @@ func (f *Framework) DeleteServiceAndWaitUntilGone(ctx context.Context, namespace
|
||||
func (f *Framework) getEndpoints(ctx context.Context, namespace, serviceName string) (*v1.Endpoints, error) {
|
||||
endpoints, err := f.KubeClient.CoreV1().Endpoints(namespace).Get(ctx, serviceName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("requesting endpoints for service %v failed", serviceName))
|
||||
return nil, fmt.Errorf("requesting endpoints for service %v failed: %w", serviceName, err)
|
||||
}
|
||||
return endpoints, nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
@@ -60,7 +59,7 @@ func (f *Framework) WaitForResourceAvailable(ctx context.Context, getResourceSta
|
||||
}
|
||||
|
||||
if status.replicas != status.expectedReplicas {
|
||||
pollErr = errors.Errorf("expected %d replicas, got %d", status.expectedReplicas, status.replicas)
|
||||
pollErr = fmt.Errorf("expected %d replicas, got %d", status.expectedReplicas, status.replicas)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -77,7 +76,7 @@ func (f *Framework) WaitForResourceAvailable(ctx context.Context, getResourceSta
|
||||
reconciled = &cond
|
||||
}
|
||||
if cond.ObservedGeneration != status.generation {
|
||||
pollErr = errors.Errorf("observed generation %d for condition %s isn't equal to the state generation %d",
|
||||
pollErr = fmt.Errorf("observed generation %d for condition %s isn't equal to the state generation %d",
|
||||
cond.ObservedGeneration,
|
||||
cond.Type,
|
||||
status.generation)
|
||||
@@ -86,12 +85,12 @@ func (f *Framework) WaitForResourceAvailable(ctx context.Context, getResourceSta
|
||||
}
|
||||
|
||||
if reconciled == nil {
|
||||
pollErr = errors.Errorf("failed to find Reconciled condition in status subresource")
|
||||
pollErr = fmt.Errorf("failed to find Reconciled condition in status subresource")
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if reconciled.Status != monitoringv1.ConditionTrue {
|
||||
pollErr = errors.Errorf(
|
||||
pollErr = fmt.Errorf(
|
||||
"expected Reconciled condition to be 'True', got %q (reason %s, %q)",
|
||||
reconciled.Status,
|
||||
reconciled.Reason,
|
||||
@@ -101,12 +100,12 @@ func (f *Framework) WaitForResourceAvailable(ctx context.Context, getResourceSta
|
||||
}
|
||||
|
||||
if available == nil {
|
||||
pollErr = errors.Errorf("failed to find Available condition in status subresource")
|
||||
pollErr = fmt.Errorf("failed to find Available condition in status subresource")
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if available.Status != monitoringv1.ConditionTrue {
|
||||
pollErr = errors.Errorf(
|
||||
pollErr = fmt.Errorf(
|
||||
"expected Available condition to be 'True', got %q (reason %s, %q)",
|
||||
available.Status,
|
||||
available.Reason,
|
||||
@@ -116,7 +115,7 @@ func (f *Framework) WaitForResourceAvailable(ctx context.Context, getResourceSta
|
||||
}
|
||||
return true, nil
|
||||
}); err != nil {
|
||||
return errors.Wrapf(pollErr, "%v", err)
|
||||
return fmt.Errorf("%v: %w", pollErr, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
@@ -86,7 +85,7 @@ func (f *Framework) PatchThanosRuler(ctx context.Context, name, ns string, spec
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal ThanosRuler spec")
|
||||
return nil, fmt.Errorf("failed to marshal ThanosRuler spec: %w", err)
|
||||
}
|
||||
|
||||
tr, err := f.MonClientV1.ThanosRulers(ns).Patch(
|
||||
@@ -126,7 +125,7 @@ func (f *Framework) WaitForThanosRulerReady(ctx context.Context, ns string, tr *
|
||||
},
|
||||
timeout,
|
||||
); err != nil {
|
||||
return errors.Wrapf(err, "thanos ruler %v/%v failed to become available", tr.Namespace, tr.Name)
|
||||
return fmt.Errorf("thanos ruler %v/%v failed to become available: %w", tr.Namespace, tr.Name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -167,7 +166,7 @@ func (f *Framework) WaitForThanosFiringAlert(ctx context.Context, ns, svcName, a
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errors.Errorf(
|
||||
return fmt.Errorf(
|
||||
"waiting for alert '%v' to fire: %v: %v",
|
||||
alertName,
|
||||
err,
|
||||
@@ -186,12 +185,12 @@ func (f *Framework) CheckThanosFiringAlert(ctx context.Context, ns, svcName, ale
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to get Thanos service %s/%s", ns, svcName)
|
||||
return false, fmt.Errorf("failed to get Thanos service %s/%s: %w", ns, svcName, err)
|
||||
}
|
||||
|
||||
apiResponse := ThanosAlertsAPIResponse{}
|
||||
if err := json.NewDecoder(bytes.NewBuffer(response)).Decode(&apiResponse); err != nil {
|
||||
return false, errors.Wrap(err, "failed to decode alerts from Thanos ruler API")
|
||||
return false, fmt.Errorf("failed to decode alerts from Thanos ruler API: %w", err)
|
||||
}
|
||||
|
||||
for _, alert := range apiResponse.Data.Alerts {
|
||||
@@ -215,11 +214,11 @@ func (f *Framework) ThanosSVCGetRequest(ctx context.Context, ns, svcName, endpoi
|
||||
func (f *Framework) DeleteThanosRulerAndWaitUntilGone(ctx context.Context, ns, name string) error {
|
||||
_, err := f.MonClientV1.ThanosRulers(ns).Get(ctx, name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("requesting ThanosRuler custom resource %v failed", name))
|
||||
return fmt.Errorf("requesting ThanosRuler custom resource %v failed: %w", name, err)
|
||||
}
|
||||
|
||||
if err := f.MonClientV1.ThanosRulers(ns).Delete(ctx, name, metav1.DeleteOptions{}); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("deleting ThanosRuler custom resource %v failed", name))
|
||||
return fmt.Errorf("deleting ThanosRuler custom resource %v failed: %w", name, err)
|
||||
}
|
||||
|
||||
if err := f.WaitForPodsReady(
|
||||
@@ -229,10 +228,7 @@ func (f *Framework) DeleteThanosRulerAndWaitUntilGone(ctx context.Context, ns, n
|
||||
0,
|
||||
thanos.ListOptions(name),
|
||||
); err != nil {
|
||||
return errors.Wrap(
|
||||
err,
|
||||
fmt.Sprintf("waiting for Prometheus custom resource (%s) to vanish timed out", name),
|
||||
)
|
||||
return fmt.Errorf("waiting for Prometheus custom resource (%s) to vanish timed out: %w", name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user