Skip to content

Commit

Permalink
remove github.com/pkg/errors
Browse files Browse the repository at this point in the history
Signed-off-by: chengzw <[email protected]>
  • Loading branch information
cr7258 committed Jul 26, 2023
1 parent 102e760 commit 4390eb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.8
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.5
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/common v0.44.0
Expand Down Expand Up @@ -185,6 +184,7 @@ require (
github.com/pion/logging v0.2.2 // indirect
github.com/pion/transport/v2 v2.0.0 // indirect
github.com/pion/udp v0.1.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
Expand Down
50 changes: 25 additions & 25 deletions test/e2e/k8s_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package e2e

import (
"context"
"errors"
"fmt"
"strconv"
"strings"
"sync"
"testing"
"time"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -95,7 +95,7 @@ var ErrPodNotFound = errors.New("Pod not found")
func (k *KubernetesUtils) GetPodByLabel(ns string, name string) (*v1.Pod, error) {
pods, err := k.getPodsUncached(ns, "pod", name)
if err != nil {
return nil, errors.Wrapf(err, "unable to get Pod in Namespace %s with label pod=%s", ns, name)
return nil, fmt.Errorf("unable to get Pod in Namespace %s with label pod=%s: %w", ns, name, err)
}
if len(pods) == 0 {
return nil, ErrPodNotFound
Expand All @@ -108,7 +108,7 @@ func (k *KubernetesUtils) getPodsUncached(ns string, key, val string) ([]v1.Pod,
LabelSelector: fmt.Sprintf("%v=%v", key, val),
})
if err != nil {
return nil, errors.WithMessage(err, "unable to list pods")
return nil, fmt.Errorf("unable to list pods: %w", err)
}
return v1PodList.Items, nil
}
Expand All @@ -123,7 +123,7 @@ func (k *KubernetesUtils) GetPodsByLabel(ns string, key string, val string) ([]v

v1PodList, err := k.getPodsUncached(ns, key, val)
if err != nil {
return nil, errors.WithMessage(err, "unable to list pods")
return nil, fmt.Errorf("unable to list pods: %w", err)
}
k.podCache[fmt.Sprintf("%v_%v_%v", ns, key, val)] = v1PodList
return v1PodList, nil
Expand Down Expand Up @@ -629,7 +629,7 @@ func (data *TestData) DeleteService(ns, name string) error {
log.Infof("Deleting Service %s in ns %s", name, ns)
err := data.clientset.CoreV1().Services(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete Service %s", name)
return fmt.Errorf("unable to delete Service %s: %w", name, err)
}
return nil
}
Expand All @@ -639,7 +639,7 @@ func (data *TestData) CleanServices(namespaces map[string]string) error {
for _, ns := range namespaces {
l, err := data.clientset.CoreV1().Services(ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list Services in ns %s", ns)
return fmt.Errorf("unable to list Services in ns %s: %w", ns, err)
}
for _, svc := range l.Items {
if err := data.DeleteService(svc.Namespace, svc.Name); err != nil {
Expand Down Expand Up @@ -690,7 +690,7 @@ func (data *TestData) DeleteServiceAccount(ns, name string) error {
log.Infof("Deleting ServiceAccount %s in ns %s", name, ns)
err := data.clientset.CoreV1().ServiceAccounts(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete ServiceAccount %s in ns %s", name, ns)
return fmt.Errorf("unable to delete ServiceAccount %s in ns %s: %w", name, ns, err)
}
return nil
}
Expand Down Expand Up @@ -722,7 +722,7 @@ func (data *TestData) DeleteNetworkPolicy(ns, name string) error {
log.Infof("Deleting NetworkPolicy '%s/%s'", ns, name)
err := data.clientset.NetworkingV1().NetworkPolicies(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete NetworkPolicy '%s'", name)
return fmt.Errorf("unable to delete NetworkPolicy '%s': %w", name, err)
}
return nil
}
Expand All @@ -732,7 +732,7 @@ func (data *TestData) CleanNetworkPolicies(namespaces map[string]string) error {
for _, ns := range namespaces {
l, err := data.clientset.NetworkingV1().NetworkPolicies(ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list NetworkPolicy in Namespace '%s'", ns)
return fmt.Errorf("unable to list NetworkPolicy in Namespace '%s': %w", ns, err)
}
for _, np := range l.Items {
if err = data.DeleteNetworkPolicy(np.Namespace, np.Name); err != nil {
Expand Down Expand Up @@ -777,11 +777,11 @@ func (data *TestData) UpdateTier(tier *crdv1beta1.Tier) (*crdv1beta1.Tier, error
func (data *TestData) DeleteTier(name string) error {
_, err := data.crdClient.CrdV1beta1().Tiers().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return errors.Wrapf(err, "unable to get tier %s", name)
return fmt.Errorf("unable to get tier %s: %w", name, err)
}
log.Infof("Deleting tier %s", name)
if err = data.crdClient.CrdV1beta1().Tiers().Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil {
return errors.Wrapf(err, "unable to delete tier %s", name)
return fmt.Errorf("unable to delete tier %s: %w", name, err)
}
return nil
}
Expand Down Expand Up @@ -849,7 +849,7 @@ func (data *TestData) DeleteCG(name string) error {
log.Infof("deleting ClusterGroup %s", name)
err := data.crdClient.CrdV1beta1().ClusterGroups().Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete ClusterGroup %s", name)
return fmt.Errorf("unable to delete ClusterGroup %s: %w", name, err)
}
return nil
}
Expand All @@ -859,7 +859,7 @@ func (k *KubernetesUtils) DeleteGroup(namespace, name string) error {
log.Infof("deleting Group %s/%s", namespace, name)
err := k.crdClient.CrdV1beta1().Groups(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete Group %s/%s", namespace, name)
return fmt.Errorf("unable to delete Group %s/%s: %w", namespace, name, err)
}
return nil
}
Expand All @@ -868,7 +868,7 @@ func (k *KubernetesUtils) DeleteGroup(namespace, name string) error {
func (data *TestData) CleanCGs() error {
l, err := data.crdClient.CrdV1beta1().ClusterGroups().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list ClusterGroups in v1beta1")
return fmt.Errorf("unable to list ClusterGroups in v1beta1: %w", err)
}
for _, cg := range l.Items {
if err := data.DeleteCG(cg.Name); err != nil {
Expand All @@ -882,7 +882,7 @@ func (data *TestData) CleanCGs() error {
func (k *KubernetesUtils) CleanGroups(namespace string) error {
l, err := k.crdClient.CrdV1beta1().Groups(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list Groups in v1beta1")
return fmt.Errorf("unable to list Groups in v1beta1: %w", err)
}
for _, g := range l.Items {
if err := k.DeleteGroup(namespace, g.Name); err != nil {
Expand Down Expand Up @@ -926,7 +926,7 @@ func (data *TestData) DeleteACNP(name string) error {
log.Infof("Deleting AntreaClusterNetworkPolicies %s", name)
err := data.crdClient.CrdV1alpha1().ClusterNetworkPolicies().Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete ClusterNetworkPolicy %s", name)
return fmt.Errorf("unable to delete ClusterNetworkPolicy %s: %w", name, err)
}
return nil
}
Expand All @@ -935,7 +935,7 @@ func (data *TestData) DeleteACNP(name string) error {
func (data *TestData) CleanACNPs() error {
l, err := data.crdClient.CrdV1alpha1().ClusterNetworkPolicies().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list AntreaClusterNetworkPolicies")
return fmt.Errorf("unable to list AntreaClusterNetworkPolicies: %w", err)
}
for _, cnp := range l.Items {
if err = data.DeleteACNP(cnp.Name); err != nil {
Expand Down Expand Up @@ -974,7 +974,7 @@ func (data *TestData) DeleteANNP(ns, name string) error {
log.Infof("Deleting Antrea NetworkPolicy '%s/%s'", ns, name)
err := data.crdClient.CrdV1alpha1().NetworkPolicies(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete Antrea NetworkPolicy %s", name)
return fmt.Errorf("unable to delete Antrea NetworkPolicy %s: %w", name, err)
}
return nil
}
Expand All @@ -984,7 +984,7 @@ func (data *TestData) CleanANNPs(namespaces []string) error {
for _, ns := range namespaces {
l, err := data.crdClient.CrdV1alpha1().NetworkPolicies(ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list Antrea NetworkPolicies in ns %s", ns)
return fmt.Errorf("unable to list Antrea NetworkPolicies in ns %s: %w", ns, err)
}
for _, annp := range l.Items {
if err = data.DeleteANNP(annp.Namespace, annp.Name); err != nil {
Expand Down Expand Up @@ -1028,12 +1028,12 @@ func (k *KubernetesUtils) waitForPodInNamespace(ns string, pod string) ([]string
for {
k8sPod, err := k.GetPodByLabel(ns, pod)
if err != nil && err != ErrPodNotFound {
return nil, errors.WithMessagef(err, "unable to get Pod '%s/%s'", ns, pod)
return nil, fmt.Errorf("unable to get Pod '%s/%s': %w", ns, pod, err)
}

if k8sPod != nil && k8sPod.Status.Phase == v1.PodRunning {
if k8sPod.Status.PodIP == "" {
return nil, errors.WithMessagef(err, "unable to get IP of Pod '%s/%s'", ns, pod)
return nil, fmt.Errorf("unable to get IP of Pod '%s/%s': %w", ns, pod, err)
}
var podIPs []string
for _, podIP := range k8sPod.Status.PodIPs {
Expand Down Expand Up @@ -1078,7 +1078,7 @@ func (k *KubernetesUtils) waitForHTTPServers(allPods []Pod) error {
}
time.Sleep(defaultInterval)
}
return errors.Errorf("after %d tries, HTTP servers are not ready", maxTries)
return fmt.Errorf("after %d tries, HTTP servers are not ready", maxTries)
}

func (k *KubernetesUtils) validateOnePort(allPods []Pod, reachability *Reachability, port int32, protocol utils.AntreaPolicyProtocol) {
Expand Down Expand Up @@ -1165,15 +1165,15 @@ func (k *KubernetesUtils) Bootstrap(namespaces map[string]string, pods []string,
if createNamespaces {
_, err := k.CreateOrUpdateNamespace(ns, map[string]string{"ns": ns})
if err != nil {
return nil, errors.WithMessagef(err, "unable to create/update ns %s", ns)
return nil, fmt.Errorf("unable to create/update ns %s: %w", ns, err)
}
}
for _, pod := range pods {
log.Infof("Creating/updating Pod '%s/%s'", ns, pod)
deployment := ns + pod
_, err := k.CreateOrUpdateDeployment(ns, deployment, 1, map[string]string{"pod": pod, "app": pod})
if err != nil {
return nil, errors.WithMessagef(err, "unable to create/update Deployment '%s/%s'", ns, pod)
return nil, fmt.Errorf("unable to create/update Deployment '%s/%s': %w", ns, pod, err)
}
}
}
Expand All @@ -1187,7 +1187,7 @@ func (k *KubernetesUtils) Bootstrap(namespaces map[string]string, pods []string,
for _, pod := range allPods {
ips, err := k.waitForPodInNamespace(pod.Namespace(), pod.PodName())
if ips == nil || err != nil {
return nil, errors.WithMessagef(err, "unable to wait for Pod '%s/%s'", pod.Namespace(), pod.PodName())
return nil, fmt.Errorf("unable to wait for Pod '%s/%s': %w", pod.Namespace(), pod.PodName(), err)
}
podIPs[pod.String()] = ips
}
Expand Down

0 comments on commit 4390eb7

Please sign in to comment.