Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps(*) move from github.com/pkg/errors to 'errors' and 'fmt' #4486

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ linters-settings:
modules:
- github.com/go-errors/errors:
recommendations:
- github.com/pkg/errors
- fmt
- errors
- github.com/pkg/errors:
recommendations:
- fmt
- errors
misspell:
locale: US
ignore-words:
Expand Down
6 changes: 2 additions & 4 deletions api/mesh/v1alpha1/dataplane_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"sort"
"strconv"
"strings"

"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -49,7 +47,7 @@ func (t ProxyType) IsValid() error {
case DataplaneProxyType, IngressProxyType, EgressProxyType:
return nil
}
return errors.Errorf("%s is not a valid proxy type", t)
return fmt.Errorf("%s is not a valid proxy type", t)
}

type InboundInterface struct {
Expand Down Expand Up @@ -125,7 +123,7 @@ func (n *Dataplane_Networking) GetInboundInterface(service string) (*InboundInte
iface := n.ToInboundInterface(inbound)
return &iface, nil
}
return nil, errors.Errorf("Dataplane has no Inbound Interface for service %q", service)
return nil, fmt.Errorf("Dataplane has no Inbound Interface for service %q", service)
}

func (n *Dataplane_Networking) GetInboundInterfaces() []InboundInterface {
Expand Down
5 changes: 2 additions & 3 deletions api/mesh/v1alpha1/dataplane_insight_helpers.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package v1alpha1

import (
"fmt"
"strings"
"time"

"github.com/pkg/errors"

"github.com/kumahq/kuma/api/generic"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
)
Expand Down Expand Up @@ -91,7 +90,7 @@ func (x *DataplaneInsight) UpdateSubscription(s generic.Subscription) error {
}
discoverySubscription, ok := s.(*DiscoverySubscription)
if !ok {
return errors.Errorf("invalid type %T for DataplaneInsight", s)
return fmt.Errorf("invalid type %T for DataplaneInsight", s)
}
i, old := x.GetSubscription(discoverySubscription.Id)
if old != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/mesh/v1alpha1/zone_ingress_insight_helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1alpha1

import (
"github.com/pkg/errors"
"fmt"

"github.com/kumahq/kuma/api/generic"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
Expand All @@ -24,7 +24,7 @@ func (x *ZoneIngressInsight) UpdateSubscription(s generic.Subscription) error {
}
discoverySubscription, ok := s.(*DiscoverySubscription)
if !ok {
return errors.Errorf("invalid type %T for ZoneIngressInsight", s)
return fmt.Errorf("invalid type %T for ZoneIngressInsight", s)
}
i, old := x.GetSubscription(discoverySubscription.Id)
if old != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/mesh/v1alpha1/zoneegressinsight_helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1alpha1

import (
"github.com/pkg/errors"
"fmt"

"github.com/kumahq/kuma/api/generic"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
Expand All @@ -24,7 +24,7 @@ func (x *ZoneEgressInsight) UpdateSubscription(s generic.Subscription) error {
}
discoverySubscription, ok := s.(*DiscoverySubscription)
if !ok {
return errors.Errorf("invalid type %T for ZoneEgressInsight", s)
return fmt.Errorf("invalid type %T for ZoneEgressInsight", s)
}
i, old := x.GetSubscription(discoverySubscription.Id)
if old != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/system/v1alpha1/zone_insight_helpers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package v1alpha1

import (
"fmt"
"time"

"github.com/pkg/errors"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"

"github.com/kumahq/kuma/api/generic"
Expand Down Expand Up @@ -62,7 +62,7 @@ func (x *ZoneInsight) UpdateSubscription(s generic.Subscription) error {
}
kdsSubscription, ok := s.(*KDSSubscription)
if !ok {
return errors.Errorf("invalid type %T for ZoneInsight", s)
return fmt.Errorf("invalid type %T for ZoneInsight", s)
}
i, old := x.GetSubscription(kdsSubscription.Id)
if old != nil {
Expand Down
10 changes: 6 additions & 4 deletions app/kuma-cp/cmd/migrate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"github.com/pkg/errors"
"errors"
"fmt"

"github.com/spf13/cobra"

"github.com/kumahq/kuma/pkg/config"
Expand Down Expand Up @@ -40,7 +42,7 @@ func newMigrateUpCmd() *cobra.Command {
}

if err := migrate(cfg); err != nil {
if err == core_plugins.AlreadyMigrated {
if errors.Is(err, core_plugins.AlreadyMigrated) {
cmd.Printf("DB has already been migrated for Kuma %s\n", version.Build.Version)
} else {
return err
Expand Down Expand Up @@ -70,11 +72,11 @@ func migrate(cfg kuma_cp.Config) error {
pluginName = core_plugins.Postgres
pluginConfig = cfg.Store.Postgres
default:
return errors.Errorf("unknown store type %s", cfg.Store.Type)
return fmt.Errorf("unknown store type %s", cfg.Store.Type)
}
plugin, err := core_plugins.Plugins().ResourceStore(pluginName)
if err != nil {
return errors.Wrapf(err, "could not retrieve store %s plugin", pluginName)
return fmt.Errorf("could not retrieve store %s plugin: %w", pluginName, err)
}
_, err = plugin.Migrate(nil, pluginConfig)
return err
Expand Down
4 changes: 2 additions & 2 deletions app/kuma-dp/cmd/dataplane.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cmd

import (
"fmt"
"io"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"

kuma_dp "github.com/kumahq/kuma/pkg/config/app/kuma-dp"
Expand All @@ -30,7 +30,7 @@ func readResource(cmd *cobra.Command, r *kuma_dp.DataplaneRuntime) (model.Resour
}
default:
if b, err = os.ReadFile(r.ResourcePath); err != nil {
return nil, errors.Wrap(err, "error while reading provided file")
return nil, fmt.Errorf("error while reading provided file: %w", err)
}
}

Expand Down
21 changes: 11 additions & 10 deletions app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cmd

import (
"errors"
"fmt"
"os"
"path/filepath"
"time"

"github.com/pkg/errors"
"github.com/spf13/cobra"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
Expand Down Expand Up @@ -72,7 +73,7 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {
}

if _, ok := proxyTypeMap[cfg.Dataplane.ProxyType]; !ok {
return errors.Errorf("invalid proxy type %q", cfg.Dataplane.ProxyType)
return fmt.Errorf("invalid proxy type %q", cfg.Dataplane.ProxyType)
}

if cfg.DataplaneRuntime.EnvoyLogLevel == "" {
Expand All @@ -88,7 +89,7 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {

if proxyResource != nil {
if resType := proxyTypeMap[cfg.Dataplane.ProxyType]; resType != proxyResource.Descriptor().Name {
return errors.Errorf("invalid proxy resource type %q, expected %s",
return fmt.Errorf("invalid proxy resource type %q, expected %s",
proxyResource.Descriptor().Name, resType)
}

Expand All @@ -104,7 +105,7 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {
// unless a user has explicitly opted out of Envoy Admin API, pick a free port from the range
adminPort, err := util_net.PickTCPPort("127.0.0.1", cfg.Dataplane.AdminPort.Lowest(), cfg.Dataplane.AdminPort.Highest())
if err != nil {
return errors.Wrapf(err, "unable to find a free port in the range %q for Envoy Admin API to listen on", cfg.Dataplane.AdminPort)
return fmt.Errorf("unable to find a free port in the range %q for Envoy Admin API to listen on: %w", cfg.Dataplane.AdminPort, err)
}
cfg.Dataplane.AdminPort = config_types.MustExactPort(adminPort)
runLog.Info("picked a free port for Envoy Admin API to listen on", "port", cfg.Dataplane.AdminPort)
Expand All @@ -130,7 +131,7 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {

if cfg.DataplaneRuntime.Token != "" {
path := filepath.Join(cfg.DataplaneRuntime.ConfigDir, cfg.Dataplane.Name)
if err := writeFile(path, []byte(cfg.DataplaneRuntime.Token), 0600); err != nil {
if err := writeFile(path, []byte(cfg.DataplaneRuntime.Token), 0o600); err != nil {
runLog.Error(err, "unable to create file with dataplane token")
return err
}
Expand All @@ -139,14 +140,14 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {

if cfg.DataplaneRuntime.TokenPath != "" {
if err := kumadp_config.ValidateTokenPath(cfg.DataplaneRuntime.TokenPath); err != nil {
return errors.Wrapf(err, "dataplane token is invalid, in Kubernetes you must mount a serviceAccount token, in universal you must start your proxy with a generated token.")
return fmt.Errorf("dataplane token is invalid, in Kubernetes you must mount a serviceAccount token, in universal you must start your proxy with a generated token.: %w", err)
}
}

if cfg.ControlPlane.CaCert == "" && cfg.ControlPlane.CaCertFile != "" {
cert, err := os.ReadFile(cfg.ControlPlane.CaCertFile)
if err != nil {
return errors.Wrapf(err, "could not read certificate file %s", cfg.ControlPlane.CaCertFile)
return fmt.Errorf("could not read certificate file %s: %w", cfg.ControlPlane.CaCertFile, err)
}
cfg.ControlPlane.CaCert = string(cert)
}
Expand Down Expand Up @@ -202,7 +203,7 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {

envoyVersion, err := envoy.GetEnvoyVersion(opts.Config.DataplaneRuntime.BinaryPath)
if err != nil {
return errors.Wrap(err, "failed to get Envoy version")
return fmt.Errorf("failed to get Envoy version: %w", err)
}

if envoyVersion.KumaDpCompatible, err = envoy.EnvoyVersionCompatible(envoyVersion.Version); err != nil {
Expand All @@ -222,13 +223,13 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {
DynamicMetadata: rootCtx.BootstrapDynamicMetadata,
})
if err != nil {
return errors.Errorf("Failed to generate Envoy bootstrap config. %v", err)
return fmt.Errorf("Failed to generate Envoy bootstrap config. %v", err)
}
runLog.Info("received bootstrap configuration", "adminPort", bootstrap.GetAdmin().GetAddress().GetSocketAddress().GetPortValue())

opts.BootstrapConfig, err = proto.ToYAML(bootstrap)
if err != nil {
return errors.Errorf("could not convert to yaml. %v", err)
return fmt.Errorf("could not convert to yaml. %v", err)
}
opts.AdminPort = bootstrap.GetAdmin().GetAddress().GetSocketAddress().GetPortValue()

Expand Down
11 changes: 6 additions & 5 deletions app/kuma-dp/pkg/config/validate.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package config

import (
"errors"
"fmt"
"os"
"unicode"

"github.com/golang-jwt/jwt/v4"
"github.com/pkg/errors"

util_files "github.com/kumahq/kuma/pkg/util/files"
)
Expand All @@ -16,20 +17,20 @@ func ValidateTokenPath(path string) error {
}
empty, err := util_files.FileEmpty(path)
if err != nil {
return errors.Wrapf(err, "could not read file %s", path)
return fmt.Errorf("could not read file %s: %w", path, err)
}
if empty {
return errors.Errorf("token under file %s is empty", path)
return fmt.Errorf("token under file %s is empty", path)
}

rawToken, err := os.ReadFile(path)
if err != nil {
return errors.Wrapf(err, "could not read the token in the file %s", path)
return fmt.Errorf("could not read the token in the file %s: %w", path, err)
}

token, parts, err := new(jwt.Parser).ParseUnverified(string(rawToken), &jwt.MapClaims{})
if err != nil {
return errors.Wrap(err, "not valid JWT token. Can't parse it.")
return fmt.Errorf("not valid JWT token. Can't parse it.: %w", err)
}

if token.Method.Alg() == "" {
Expand Down
5 changes: 2 additions & 3 deletions app/kuma-dp/pkg/dataplane/accesslogs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net"
"os"

"github.com/pkg/errors"
"google.golang.org/grpc"

v3 "github.com/kumahq/kuma/app/kuma-dp/pkg/dataplane/accesslogs/v3"
Expand Down Expand Up @@ -45,11 +44,11 @@ func (s *accessLogServer) Start(stop <-chan struct{}) error {
newName := s.address + ".bak"
err := os.Rename(s.address, newName)
if err != nil {
return errors.Errorf("file %s exists and probably opened by another kuma-dp instance", s.address)
return fmt.Errorf("file %s exists and probably opened by another kuma-dp instance", s.address)
}
err = os.Remove(newName)
if err != nil {
return errors.Errorf("not able the delete the backup file %s", newName)
return fmt.Errorf("not able the delete the backup file %s", newName)
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/kuma-dp/pkg/dataplane/accesslogs/v3/factories.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package v3

import (
"fmt"
"strings"

envoy_accesslog "github.com/envoyproxy/go-control-plane/envoy/service/accesslog/v3"
"github.com/go-logr/logr"
"github.com/pkg/errors"

accesslog "github.com/kumahq/kuma/pkg/envoy/accesslog/v3"
)

func defaultHandler(log logr.Logger, msg *envoy_accesslog.StreamAccessLogsMessage) (logHandler, error) {
parts := strings.SplitN(msg.GetIdentifier().GetLogName(), ";", 2)
if len(parts) != 2 {
return nil, errors.Errorf("log name %q has invalid format: expected %d components separated by ';', got %d", msg.GetIdentifier().GetLogName(), 2, len(parts))
return nil, fmt.Errorf("log name %q has invalid format: expected %d components separated by ';', got %d", msg.GetIdentifier().GetLogName(), 2, len(parts))
}
address, formatString := parts[0], parts[1]

Expand Down
9 changes: 5 additions & 4 deletions app/kuma-dp/pkg/dataplane/accesslogs/v3/handler.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package v3

import (
"fmt"

envoy_accesslog "github.com/envoyproxy/go-control-plane/envoy/service/accesslog/v3"
"github.com/pkg/errors"

accesslog "github.com/kumahq/kuma/pkg/envoy/accesslog/v3"
)
Expand All @@ -18,7 +19,7 @@ func (h *handler) Handle(msg *envoy_accesslog.StreamAccessLogsMessage) error {
for _, httpLogEntry := range logEntries.HttpLogs.GetLogEntry() {
record, err := h.format.FormatHttpLogEntry(httpLogEntry)
if err != nil {
return errors.Wrapf(err, "failed to format an HTTP log entry %v as %q", httpLogEntry, h.format)
return fmt.Errorf("failed to format an HTTP log entry %v as %q: %w", httpLogEntry, h.format, err)
}
if err := h.sender.Send(record); err != nil {
return err
Expand All @@ -28,14 +29,14 @@ func (h *handler) Handle(msg *envoy_accesslog.StreamAccessLogsMessage) error {
for _, tcpLogEntry := range logEntries.TcpLogs.GetLogEntry() {
record, err := h.format.FormatTcpLogEntry(tcpLogEntry)
if err != nil {
return errors.Wrapf(err, "failed to format a TCP log entry %v as %q", tcpLogEntry, h.format)
return fmt.Errorf("failed to format a TCP log entry %v as %q: %w", tcpLogEntry, h.format, err)
}
if err := h.sender.Send(record); err != nil {
return err
}
}
default:
return errors.Errorf("unknown type of log entries: %T", msg.GetLogEntries())
return fmt.Errorf("unknown type of log entries: %T", msg.GetLogEntries())
}
return nil
}
Expand Down
Loading