mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
update to remove github.com/pkg/errors
This commit is contained in:
parent
56efa75173
commit
674802147c
@ -26,7 +26,6 @@ import (
|
||||
|
||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
networkingv1 "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -84,18 +83,18 @@ func (k *kubeManager) initializeCluster(model *Model) error {
|
||||
return err
|
||||
}
|
||||
if k8sPod == nil {
|
||||
return errors.Errorf("unable to find pod in ns %s with key/val pod=%s", podString.Namespace(), podString.PodName())
|
||||
return fmt.Errorf("unable to find pod in ns %s with key/val pod=%s", podString.Namespace(), podString.PodName())
|
||||
}
|
||||
err = e2epod.WaitForPodNameRunningInNamespace(k.clientSet, k8sPod.Name, k8sPod.Namespace)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to wait for pod %s/%s", podString.Namespace(), podString.PodName())
|
||||
return fmt.Errorf("unable to wait for pod %s/%s: %w", podString.Namespace(), podString.PodName(), err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, createdPod := range createdPods {
|
||||
err := e2epod.WaitForPodRunningInNamespace(k.clientSet, createdPod)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to wait for pod %s/%s", createdPod.Namespace, createdPod.Name)
|
||||
return fmt.Errorf("unable to wait for pod %s/%s: %w", createdPod.Namespace, createdPod.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,7 +105,7 @@ func (k *kubeManager) initializeCluster(model *Model) error {
|
||||
func (k *kubeManager) getPod(ns string, name string) (*v1.Pod, error) {
|
||||
kubePod, err := k.clientSet.CoreV1().Pods(ns).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to get pod %s/%s", ns, name)
|
||||
return nil, fmt.Errorf("unable to get pod %s/%s: %w", ns, name, err)
|
||||
}
|
||||
return kubePod, nil
|
||||
}
|
||||
@ -158,7 +157,7 @@ func (k *kubeManager) executeRemoteCommand(namespace string, pod string, contain
|
||||
func (k *kubeManager) createNamespace(ns *v1.Namespace) (*v1.Namespace, error) {
|
||||
createdNamespace, err := k.clientSet.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to update namespace %s", ns.Name)
|
||||
return nil, fmt.Errorf("unable to update namespace %s: %w", ns.Name, err)
|
||||
}
|
||||
return createdNamespace, nil
|
||||
}
|
||||
@ -170,7 +169,7 @@ func (k *kubeManager) createService(service *v1.Service) (*v1.Service, error) {
|
||||
|
||||
createdService, err := k.clientSet.CoreV1().Services(ns).Create(context.TODO(), service, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to create service %s/%s", ns, name)
|
||||
return nil, fmt.Errorf("unable to create service %s/%s: %w", ns, name, err)
|
||||
}
|
||||
return createdService, nil
|
||||
}
|
||||
@ -182,7 +181,7 @@ func (k *kubeManager) createPod(pod *v1.Pod) (*v1.Pod, error) {
|
||||
|
||||
createdPod, err := k.clientSet.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to update pod %s/%s", ns, pod.Name)
|
||||
return nil, fmt.Errorf("unable to update pod %s/%s: %w", ns, pod.Name, err)
|
||||
}
|
||||
return createdPod, nil
|
||||
}
|
||||
@ -193,13 +192,13 @@ func (k *kubeManager) cleanNetworkPolicies(namespaces []string) error {
|
||||
framework.Logf("deleting policies in %s ..........", ns)
|
||||
l, err := k.clientSet.NetworkingV1().NetworkPolicies(ns).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to list network policies in ns %s", ns)
|
||||
return fmt.Errorf("unable to list network policies in ns %s: %w", ns, err)
|
||||
}
|
||||
for _, np := range l.Items {
|
||||
framework.Logf("deleting network policy %s/%s", ns, np.Name)
|
||||
err = k.clientSet.NetworkingV1().NetworkPolicies(ns).Delete(context.TODO(), np.Name, metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to delete network policy %s/%s", ns, np.Name)
|
||||
return fmt.Errorf("unable to delete network policy %s/%s: %w", ns, np.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,7 +211,7 @@ func (k *kubeManager) createNetworkPolicy(ns string, netpol *networkingv1.Networ
|
||||
netpol.ObjectMeta.Namespace = ns
|
||||
np, err := k.clientSet.NetworkingV1().NetworkPolicies(ns).Create(context.TODO(), netpol, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to create network policy %s/%s", ns, netpol.Name)
|
||||
return nil, fmt.Errorf("unable to create network policy %s/%s: %w", ns, netpol.Name, err)
|
||||
}
|
||||
return np, nil
|
||||
}
|
||||
@ -223,7 +222,7 @@ func (k *kubeManager) updateNetworkPolicy(ns string, netpol *networkingv1.Networ
|
||||
netpol.ObjectMeta.Namespace = ns
|
||||
np, err := k.clientSet.NetworkingV1().NetworkPolicies(ns).Update(context.TODO(), netpol, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return np, errors.Wrapf(err, "unable to update network policy %s/%s", ns, netpol.Name)
|
||||
return np, fmt.Errorf("unable to update network policy %s/%s: %w", ns, netpol.Name, err)
|
||||
}
|
||||
return np, nil
|
||||
}
|
||||
@ -232,7 +231,7 @@ func (k *kubeManager) updateNetworkPolicy(ns string, netpol *networkingv1.Networ
|
||||
func (k *kubeManager) getNamespace(ns string) (*v1.Namespace, error) {
|
||||
selectedNameSpace, err := k.clientSet.CoreV1().Namespaces().Get(context.TODO(), ns, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to get namespace %s", ns)
|
||||
return nil, fmt.Errorf("unable to get namespace %s: %w", ns, err)
|
||||
}
|
||||
return selectedNameSpace, nil
|
||||
}
|
||||
@ -245,7 +244,10 @@ func (k *kubeManager) setNamespaceLabels(ns string, labels map[string]string) er
|
||||
}
|
||||
selectedNameSpace.ObjectMeta.Labels = labels
|
||||
_, err = k.clientSet.CoreV1().Namespaces().Update(context.TODO(), selectedNameSpace, metav1.UpdateOptions{})
|
||||
return errors.Wrapf(err, "unable to update namespace %s", ns)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to update namespace %s: %w", ns, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteNamespaces removes a namespace from kubernetes.
|
||||
@ -253,7 +255,7 @@ func (k *kubeManager) deleteNamespaces(namespaces []string) error {
|
||||
for _, ns := range namespaces {
|
||||
err := k.clientSet.CoreV1().Namespaces().Delete(context.TODO(), ns, metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to delete namespace %s", ns)
|
||||
return fmt.Errorf("unable to delete namespace %s: %w", ns, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -298,5 +300,5 @@ func (k *kubeManager) waitForHTTPServers(model *Model) error {
|
||||
}
|
||||
time.Sleep(waitInterval)
|
||||
}
|
||||
return errors.Errorf("after %d tries, %d HTTP servers are not ready", maxTries, len(notReady))
|
||||
return fmt.Errorf("after %d tries, %d HTTP servers are not ready", maxTries, len(notReady))
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
@ -149,7 +148,7 @@ func (m *Model) FindPod(ns string, name string) (*Pod, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, errors.Errorf("unable to find pod %s/%s", ns, name)
|
||||
return nil, fmt.Errorf("unable to find pod %s/%s", ns, name)
|
||||
}
|
||||
|
||||
// Namespace is the abstract representation of what matters to network policy
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -81,12 +80,12 @@ func (i *IPerfResults) ToTSV() string {
|
||||
// NewIPerf parses an IPerf CSV output line into an IPerfCSVResult.
|
||||
func NewIPerf(csvLine string) (*IPerfCSVResult, error) {
|
||||
if len(csvLine) == 0 {
|
||||
return nil, errors.New("No iperf output received in csv line")
|
||||
return nil, fmt.Errorf("No iperf output received in csv line")
|
||||
}
|
||||
csvLine = strings.Trim(csvLine, "\n")
|
||||
slice := StrSlice(strings.Split(csvLine, ","))
|
||||
if len(slice) != 9 {
|
||||
return nil, errors.Errorf("Incorrect fields in the output: %v (%v out of 9)", slice, len(slice))
|
||||
return nil, fmt.Errorf("Incorrect fields in the output: %v (%v out of 9)", slice, len(slice))
|
||||
}
|
||||
i := IPerfCSVResult{}
|
||||
i.date = slice.get(0)
|
||||
@ -149,7 +148,7 @@ func ParseIPerf2EnhancedResultsFromCSV(output string) (*IPerf2EnhancedCSVResults
|
||||
parsedResults = append(parsedResults, parsed)
|
||||
}
|
||||
if parsedResults == nil || len(parsedResults) == 0 {
|
||||
return nil, errors.New("no results parsed from iperf2 output")
|
||||
return nil, fmt.Errorf("no results parsed from iperf2 output")
|
||||
}
|
||||
// format:
|
||||
// all but last lines are intervals
|
||||
|
Loading…
Reference in New Issue
Block a user