feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io> Co-authored-by: zounengren <zouyee1989@gmail.com>
This commit is contained in:
@@ -31,7 +31,6 @@ import (
|
||||
"github.com/containerd/containerd/pkg/cri/streaming"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
cni "github.com/containerd/go-cni"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
@@ -135,20 +134,20 @@ func NewCRIService(config criconfig.Config, client *containerd.Client) (CRIServi
|
||||
}
|
||||
|
||||
if client.SnapshotService(c.config.ContainerdConfig.Snapshotter) == nil {
|
||||
return nil, errors.Errorf("failed to find snapshotter %q", c.config.ContainerdConfig.Snapshotter)
|
||||
return nil, fmt.Errorf("failed to find snapshotter %q", c.config.ContainerdConfig.Snapshotter)
|
||||
}
|
||||
|
||||
c.imageFSPath = imageFSPath(config.ContainerdRootDir, config.ContainerdConfig.Snapshotter)
|
||||
logrus.Infof("Get image filesystem path %q", c.imageFSPath)
|
||||
|
||||
if err := c.initPlatform(); err != nil {
|
||||
return nil, errors.Wrap(err, "initialize platform")
|
||||
return nil, fmt.Errorf("initialize platform: %w", err)
|
||||
}
|
||||
|
||||
// prepare streaming server
|
||||
c.streamServer, err = newStreamServer(c, config.StreamServerAddress, config.StreamServerPort, config.StreamIdleTimeout)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create stream server")
|
||||
return nil, fmt.Errorf("failed to create stream server: %w", err)
|
||||
}
|
||||
|
||||
c.eventMonitor = newEventMonitor(c)
|
||||
@@ -164,7 +163,7 @@ func NewCRIService(config criconfig.Config, client *containerd.Client) (CRIServi
|
||||
if path != "" {
|
||||
m, err := newCNINetConfSyncer(path, i, c.cniLoadOptions())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to create cni conf monitor for %s", name)
|
||||
return nil, fmt.Errorf("failed to create cni conf monitor for %s: %w", name, err)
|
||||
}
|
||||
c.cniNetConfMonitor[name] = m
|
||||
}
|
||||
@@ -201,7 +200,7 @@ func (c *criService) Run() error {
|
||||
|
||||
logrus.Infof("Start recovering state")
|
||||
if err := c.recover(ctrdutil.NamespacedContext()); err != nil {
|
||||
return errors.Wrap(err, "failed to recover state")
|
||||
return fmt.Errorf("failed to recover state: %w", err)
|
||||
}
|
||||
|
||||
// Start event handler.
|
||||
@@ -255,7 +254,7 @@ func (c *criService) Run() error {
|
||||
case cniNetConfMonitorErr = <-cniNetConfMonitorErrCh:
|
||||
}
|
||||
if err := c.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to stop cri service")
|
||||
return fmt.Errorf("failed to stop cri service: %w", err)
|
||||
}
|
||||
// If the error is set above, err from channel must be nil here, because
|
||||
// the channel is supposed to be closed. Or else, we wait and set it.
|
||||
@@ -282,13 +281,13 @@ func (c *criService) Run() error {
|
||||
logrus.Errorf("Stream server is not stopped in %q", streamServerStopTimeout)
|
||||
}
|
||||
if eventMonitorErr != nil {
|
||||
return errors.Wrap(eventMonitorErr, "event monitor error")
|
||||
return fmt.Errorf("event monitor error: %w", eventMonitorErr)
|
||||
}
|
||||
if streamServerErr != nil {
|
||||
return errors.Wrap(streamServerErr, "stream server error")
|
||||
return fmt.Errorf("stream server error: %w", streamServerErr)
|
||||
}
|
||||
if cniNetConfMonitorErr != nil {
|
||||
return errors.Wrap(cniNetConfMonitorErr, "cni network conf monitor error")
|
||||
return fmt.Errorf("cni network conf monitor error: %w", cniNetConfMonitorErr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -304,7 +303,7 @@ func (c *criService) Close() error {
|
||||
}
|
||||
c.eventMonitor.stop()
|
||||
if err := c.streamServer.Stop(); err != nil {
|
||||
return errors.Wrap(err, "failed to stop stream server")
|
||||
return fmt.Errorf("failed to stop stream server: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -328,13 +327,13 @@ func imageFSPath(rootDir, snapshotter string) string {
|
||||
func loadOCISpec(filename string) (*oci.Spec, error) {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to open base OCI spec: %s", filename)
|
||||
return nil, fmt.Errorf("failed to open base OCI spec: %s: %w", filename, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
spec := oci.Spec{}
|
||||
if err := json.NewDecoder(file).Decode(&spec); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse base OCI spec file")
|
||||
return nil, fmt.Errorf("failed to parse base OCI spec file: %w", err)
|
||||
}
|
||||
|
||||
return &spec, nil
|
||||
@@ -354,7 +353,7 @@ func loadBaseOCISpecs(config *criconfig.Config) (map[string]*oci.Spec, error) {
|
||||
|
||||
spec, err := loadOCISpec(cfg.BaseRuntimeSpec)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to load base OCI spec from file: %s", cfg.BaseRuntimeSpec)
|
||||
return nil, fmt.Errorf("failed to load base OCI spec from file: %s: %w", cfg.BaseRuntimeSpec, err)
|
||||
}
|
||||
|
||||
specs[cfg.BaseRuntimeSpec] = spec
|
||||
|
||||
Reference in New Issue
Block a user