Use github.com/pkg/errors
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
@@ -17,12 +17,12 @@ limitations under the License.
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/sys/unix"
|
||||
@@ -40,7 +40,7 @@ func (c *criContainerdService) StopContainer(ctx context.Context, r *runtime.Sto
|
||||
// Get container config from container store.
|
||||
container, err := c.containerStore.Get(r.GetContainerId())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("an error occurred when try to find container %q: %v", r.GetContainerId(), err)
|
||||
return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId())
|
||||
}
|
||||
|
||||
if err := c.stopContainer(ctx, container, time.Duration(r.GetTimeout())*time.Second); err != nil {
|
||||
@@ -71,27 +71,27 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
|
||||
// deleted and image is garbage collected before this point. However,
|
||||
// the chance is really slim, even it happens, it's still fine to return
|
||||
// an error here.
|
||||
return fmt.Errorf("failed to get image metadata %q: %v", container.ImageRef, err)
|
||||
return errors.Wrapf(err, "failed to get image metadata %q", container.ImageRef)
|
||||
}
|
||||
if image.ImageSpec.Config.StopSignal != "" {
|
||||
stopSignal, err = signal.ParseSignal(image.ImageSpec.Config.StopSignal)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse stop signal %q: %v",
|
||||
image.ImageSpec.Config.StopSignal, err)
|
||||
return errors.Wrapf(err, "failed to parse stop signal %q",
|
||||
image.ImageSpec.Config.StopSignal)
|
||||
}
|
||||
}
|
||||
logrus.Infof("Stop container %q with signal %v", id, stopSignal)
|
||||
task, err := container.Container.Task(ctx, nil)
|
||||
if err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
return fmt.Errorf("failed to stop container, task not found for container %q: %v", id, err)
|
||||
return errors.Wrapf(err, "failed to stop container, task not found for container %q", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if task != nil {
|
||||
if err = task.Kill(ctx, stopSignal); err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
return fmt.Errorf("failed to stop container %q: %v", id, err)
|
||||
return errors.Wrapf(err, "failed to stop container %q", id)
|
||||
}
|
||||
// Move on to make sure container status is updated.
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
|
||||
task, err := container.Container.Task(ctx, nil)
|
||||
if err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
return fmt.Errorf("failed to stop container, task not found for container %q: %v", id, err)
|
||||
return errors.Wrapf(err, "failed to stop container, task not found for container %q", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
|
||||
if task != nil {
|
||||
if err = task.Kill(ctx, unix.SIGKILL, containerd.WithKillAll); err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
return fmt.Errorf("failed to kill container %q: %v", id, err)
|
||||
return errors.Wrapf(err, "failed to kill container %q", id)
|
||||
}
|
||||
// Move on to make sure container status is updated.
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
|
||||
|
||||
// Wait for a fixed timeout until container stop is observed by event monitor.
|
||||
if err := c.waitContainerStop(ctx, container, killContainerTimeout); err != nil {
|
||||
return fmt.Errorf("an error occurs during waiting for container %q to stop: %v", id, err)
|
||||
return errors.Wrapf(err, "an error occurs during waiting for container %q to stop", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -135,9 +135,9 @@ func (c *criContainerdService) waitContainerStop(ctx context.Context, container
|
||||
defer timeoutTimer.Stop()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return fmt.Errorf("wait container %q is cancelled", container.ID)
|
||||
return errors.Errorf("wait container %q is cancelled", container.ID)
|
||||
case <-timeoutTimer.C:
|
||||
return fmt.Errorf("wait container %q stop timeout", container.ID)
|
||||
return errors.Errorf("wait container %q stop timeout", container.ID)
|
||||
case <-container.Stopped():
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user