Replace pkg/errors with stdlib errors
github.com/pkg/errors is archived and not maintained anymore. Replace it with stdlib functions. Signed-off-by: Manuel Rüger <manuel@rueg.eu>
This commit is contained in:
parent
767af98d2f
commit
2f20203c09
2
go.mod
2
go.mod
|
|
@ -9,7 +9,6 @@ require (
|
|||
github.com/google/go-jsonnet v0.18.0
|
||||
github.com/jsonnet-bundler/jsonnet-bundler v0.4.1-0.20200708074244-ada055a225fa
|
||||
github.com/oklog/run v1.1.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.12.2
|
||||
github.com/prometheus/client_model v0.2.0
|
||||
github.com/prometheus/common v0.34.0
|
||||
|
|
@ -73,6 +72,7 @@ require (
|
|||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
|
||||
github.com/onsi/ginkgo v1.16.5 // indirect
|
||||
github.com/onsi/gomega v1.17.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ package store
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
|
|
@ -93,7 +93,7 @@ func (b *Builder) WithMetrics(r prometheus.Registerer) {
|
|||
func (b *Builder) WithEnabledResources(r []string) error {
|
||||
for _, col := range r {
|
||||
if !resourceExists(col) {
|
||||
return errors.Errorf("resource %s does not exist. Available resources: %s", col, strings.Join(availableResources(), ","))
|
||||
return fmt.Errorf("resource %s does not exist. Available resources: %s", col, strings.Join(availableResources(), ","))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@ package store
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/robfig/cron/v3"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
|
@ -329,7 +330,7 @@ func createCronJobListWatch(kubeClient clientset.Interface, ns string, fieldSele
|
|||
func getNextScheduledTime(schedule string, lastScheduleTime *metav1.Time, createdTime metav1.Time) (time.Time, error) {
|
||||
sched, err := cron.ParseStandard(schedule)
|
||||
if err != nil {
|
||||
return time.Time{}, errors.Wrapf(err, "Failed to parse cron job schedule '%s'", schedule)
|
||||
return time.Time{}, fmt.Errorf("Failed to parse cron job schedule '%s': %w", schedule, err)
|
||||
}
|
||||
if !lastScheduleTime.IsZero() {
|
||||
return sched.Next(lastScheduleTime.Time), nil
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"k8s.io/kube-state-metrics/v2/pkg/metric"
|
||||
)
|
||||
|
|
@ -54,7 +53,7 @@ func (testCase *generateMetricsTestCase) run() error {
|
|||
out := headers + "\n" + metrics
|
||||
|
||||
if err := compareOutput(testCase.Want, out); err != nil {
|
||||
return errors.Wrap(err, "expected wanted output to equal output")
|
||||
return fmt.Errorf("expected wanted output to equal output: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -70,7 +69,7 @@ func compareOutput(expected, actual string) error {
|
|||
}
|
||||
|
||||
if diff := cmp.Diff(entities[0], entities[1]); diff != "" {
|
||||
return errors.Errorf("(-want, +got):\n%s", diff)
|
||||
return fmt.Errorf("(-want, +got):\n%s", diff)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -17,12 +17,11 @@ limitations under the License.
|
|||
package allowdenylist
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// AllowDenyList encapsulates the logic needed to filter based on a string.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/oklog/run"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
|
|
@ -250,7 +249,7 @@ func createKubeClient(apiserver string, kubeconfig string, factories ...customre
|
|||
klog.Infof("Testing communication with server")
|
||||
v, err := kubeClient.Discovery().ServerVersion()
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, "error while trying to communicate with apiserver")
|
||||
return nil, nil, nil, fmt.Errorf("error while trying to communicate with apiserver: %w", err)
|
||||
}
|
||||
klog.Infof("Running with Kubernetes cluster version: v%s.%s. git version: %s. git tree state: %s. commit: %s. platform: %s",
|
||||
v.Major, v.Minor, v.GitVersion, v.GitTreeState, v.GitCommit, v.Platform)
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@ package metricshandler
|
|||
import (
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
|
|
@ -103,7 +104,7 @@ func (m *MetricsHandler) Run(ctx context.Context) error {
|
|||
klog.Infof("Auto detecting sharding settings.")
|
||||
ss, err := detectStatefulSet(m.kubeClient, m.opts.Pod, m.opts.Namespace)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "detect StatefulSet")
|
||||
return fmt.Errorf("detect StatefulSet: %w", err)
|
||||
}
|
||||
statefulSetName := ss.Name
|
||||
|
||||
|
|
@ -211,7 +212,7 @@ func (m *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
func shardingSettingsFromStatefulSet(ss *appsv1.StatefulSet, podName string) (nominal int32, totalReplicas int, err error) {
|
||||
nominal, err = detectNominalFromPod(ss.Name, podName)
|
||||
if err != nil {
|
||||
return 0, 0, errors.Wrap(err, "detecting Pod nominal")
|
||||
return 0, 0, fmt.Errorf("detecting Pod nominal: %w", err)
|
||||
}
|
||||
|
||||
totalReplicas = 1
|
||||
|
|
@ -227,7 +228,7 @@ func detectNominalFromPod(statefulSetName, podName string) (int32, error) {
|
|||
nominalString := strings.TrimPrefix(podName, statefulSetName+"-")
|
||||
nominal, err := strconv.Atoi(nominalString)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to detect shard index for Pod %s of StatefulSet %s, parsed %s", podName, statefulSetName, nominalString)
|
||||
return 0, fmt.Errorf("failed to detect shard index for Pod %s of StatefulSet %s, parsed %s: %w", podName, statefulSetName, nominalString, err)
|
||||
}
|
||||
|
||||
return int32(nominal), nil
|
||||
|
|
@ -236,7 +237,7 @@ func detectNominalFromPod(statefulSetName, podName string) (int32, error) {
|
|||
func detectStatefulSet(kubeClient kubernetes.Interface, podName, namespaceName string) (*appsv1.StatefulSet, error) {
|
||||
p, err := kubeClient.CoreV1().Pods(namespaceName).Get(context.TODO(), podName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "retrieve pod %s for sharding", podName)
|
||||
return nil, fmt.Errorf("retrieve pod %s for sharding: %w", podName, err)
|
||||
}
|
||||
|
||||
owners := p.GetOwnerReferences()
|
||||
|
|
@ -247,11 +248,11 @@ func detectStatefulSet(kubeClient kubernetes.Interface, podName, namespaceName s
|
|||
|
||||
ss, err := kubeClient.AppsV1().StatefulSets(namespaceName).Get(context.TODO(), o.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "retrieve shard's StatefulSet: %s/%s", namespaceName, o.Name)
|
||||
return nil, fmt.Errorf("retrieve shard's StatefulSet: %s/%s: %w", namespaceName, o.Name, err)
|
||||
}
|
||||
|
||||
return ss, nil
|
||||
}
|
||||
|
||||
return nil, errors.Errorf("no suitable statefulset found for auto detecting sharding for Pod %s/%s", namespaceName, podName)
|
||||
return nil, fmt.Errorf("no suitable statefulset found for auto detecting sharding for Pod %s/%s", namespaceName, podName)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package framework
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
@ -25,7 +26,6 @@ import (
|
|||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/expfmt"
|
||||
)
|
||||
|
|
@ -165,7 +165,7 @@ func (f *Framework) ParseMetrics(metrics func(io.Writer) error) (map[string]*dto
|
|||
buf := &bytes.Buffer{}
|
||||
err := metrics(buf)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Failed to get metrics")
|
||||
return nil, fmt.Errorf("Failed to get metrics: %w", err)
|
||||
}
|
||||
|
||||
parser := &expfmt.TextParser{}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus/testutil/promlint"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
|
||||
|
|
@ -148,7 +147,7 @@ func getLabelsDocumentation() (map[string][]string, error) {
|
|||
docPath := "../../docs/"
|
||||
docFiles, err := os.ReadDir(docPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read documentation directory")
|
||||
return nil, fmt.Errorf("failed to read documentation directory: %w", err)
|
||||
}
|
||||
|
||||
// Match file names such as daemonset-metrics.md
|
||||
|
|
@ -168,7 +167,7 @@ func getLabelsDocumentation() (map[string][]string, error) {
|
|||
filePath := path.Join(docPath, file.Name())
|
||||
f, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cannot read file %s", filePath)
|
||||
return nil, fmt.Errorf("cannot read file %s: %w", filePath, err)
|
||||
}
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
|
|
@ -183,7 +182,7 @@ func getLabelsDocumentation() (map[string][]string, error) {
|
|||
labelPatterns := make([]string, len(labels))
|
||||
for i, l := range labels {
|
||||
if len(l) <= 1 {
|
||||
return nil, errors.Errorf("Label documentation %s did not match regex", labelsDoc)
|
||||
return nil, fmt.Errorf("Label documentation %s did not match regex", labelsDoc)
|
||||
}
|
||||
labelPatterns[i] = patternRe.ReplaceAllString(l[1], "_.*")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue