Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
vc: export vc error types
Browse files Browse the repository at this point in the history
So that shimv2 can convert it into grpc errors.

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
  • Loading branch information
bergwolf committed Apr 12, 2019
1 parent da08b3a commit cf90751
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 62 deletions.
62 changes: 31 additions & 31 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -165,7 +165,7 @@ func FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -202,7 +202,7 @@ func StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -234,7 +234,7 @@ func StopSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandbox
return nil, vcTypes.ErrNeedSandbox
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -328,7 +328,7 @@ func StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error)
defer span.Finish()

if sandboxID == "" {
return SandboxStatus{}, errNeedSandboxID
return SandboxStatus{}, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -374,7 +374,7 @@ func CreateContainer(ctx context.Context, sandboxID string, containerConfig Cont
defer span.Finish()

if sandboxID == "" {
return nil, nil, errNeedSandboxID
return nil, nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -405,11 +405,11 @@ func DeleteContainer(ctx context.Context, sandboxID, containerID string) (VCCont
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return nil, errNeedContainerID
return nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand All @@ -434,11 +434,11 @@ func StartContainer(ctx context.Context, sandboxID, containerID string) (VCConta
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return nil, errNeedContainerID
return nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand All @@ -463,11 +463,11 @@ func StopContainer(ctx context.Context, sandboxID, containerID string) (VCContai
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return nil, errNeedContainerID
return nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand All @@ -492,11 +492,11 @@ func EnterContainer(ctx context.Context, sandboxID, containerID string, cmd type
defer span.Finish()

if sandboxID == "" {
return nil, nil, nil, errNeedSandboxID
return nil, nil, nil, vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return nil, nil, nil, errNeedContainerID
return nil, nil, nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -526,11 +526,11 @@ func StatusContainer(ctx context.Context, sandboxID, containerID string) (Contai
defer span.Finish()

if sandboxID == "" {
return ContainerStatus{}, errNeedSandboxID
return ContainerStatus{}, vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return ContainerStatus{}, errNeedContainerID
return ContainerStatus{}, vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -607,11 +607,11 @@ func KillContainer(ctx context.Context, sandboxID, containerID string, signal sy
defer span.Finish()

if sandboxID == "" {
return errNeedSandboxID
return vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return errNeedContainerID
return vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -654,11 +654,11 @@ func ProcessListContainer(ctx context.Context, sandboxID, containerID string, op
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return nil, errNeedContainerID
return nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
Expand All @@ -683,11 +683,11 @@ func UpdateContainer(ctx context.Context, sandboxID, containerID string, resourc
defer span.Finish()

if sandboxID == "" {
return errNeedSandboxID
return vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return errNeedContainerID
return vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand All @@ -712,11 +712,11 @@ func StatsContainer(ctx context.Context, sandboxID, containerID string) (Contain
defer span.Finish()

if sandboxID == "" {
return ContainerStats{}, errNeedSandboxID
return ContainerStats{}, vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return ContainerStats{}, errNeedContainerID
return ContainerStats{}, vcTypes.ErrNeedContainerID
}
lockFile, err := rLockSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -736,11 +736,11 @@ func StatsContainer(ctx context.Context, sandboxID, containerID string) (Contain

func togglePauseContainer(ctx context.Context, sandboxID, containerID string, pause bool) error {
if sandboxID == "" {
return errNeedSandboxID
return vcTypes.ErrNeedSandboxID
}

if containerID == "" {
return errNeedContainerID
return vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -784,7 +784,7 @@ func AddDevice(ctx context.Context, sandboxID string, info deviceConfig.DeviceIn
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand All @@ -804,7 +804,7 @@ func AddDevice(ctx context.Context, sandboxID string, info deviceConfig.DeviceIn

func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface, add bool) (*vcTypes.Interface, error) {
if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -848,7 +848,7 @@ func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
Expand All @@ -872,7 +872,7 @@ func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand All @@ -896,7 +896,7 @@ func ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error)
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
Expand Down
3 changes: 2 additions & 1 deletion virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/containerd/cgroups"
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
specs "github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -421,7 +422,7 @@ func (c *Container) loadDevices() ([]ContainerDevice, error) {
// container.
func (c *Container) setContainerState(state types.StateString) error {
if state == "" {
return errNeedState
return vcTypes.ErrNeedState
}

c.Logger().Debugf("Setting container state from %v to %v", c.state.State, state)
Expand Down
19 changes: 0 additions & 19 deletions virtcontainers/errors.go

This file was deleted.

19 changes: 19 additions & 0 deletions virtcontainers/pkg/types/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2017 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//

package types

import (
"errors"
)

// common error objects used for argument checking
var (
ErrNeedSandbox = errors.New("Sandbox must be specified")
ErrNeedSandboxID = errors.New("Sandbox ID cannot be empty")
ErrNeedContainerID = errors.New("Container ID cannot be empty")
ErrNeedState = errors.New("State cannot be empty")
ErrNoSuchContainer = errors.New("Container does not exist")
)
22 changes: 11 additions & 11 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func unlockSandbox(ctx context.Context, sandboxID, token string) error {
func fetchSandbox(ctx context.Context, sandboxID string) (sandbox *Sandbox, err error) {
virtLog.Info("fetch sandbox")
if sandboxID == "" {
return nil, errNeedSandboxID
return nil, vcTypes.ErrNeedSandboxID
}

sandbox, err = globalSandboxList.lookupSandbox(sandboxID)
Expand Down Expand Up @@ -665,11 +665,11 @@ func fetchSandbox(ctx context.Context, sandboxID string) (sandbox *Sandbox, err
// sandbox structure, based on a container ID.
func (s *Sandbox) findContainer(containerID string) (*Container, error) {
if s == nil {
return nil, errNeedSandbox
return nil, vcTypes.ErrNeedSandbox
}

if containerID == "" {
return nil, errNeedContainerID
return nil, vcTypes.ErrNeedContainerID
}

for id, c := range s.containers {
Expand All @@ -686,11 +686,11 @@ func (s *Sandbox) findContainer(containerID string) (*Container, error) {
// sandbox structure, based on a container ID.
func (s *Sandbox) removeContainer(containerID string) error {
if s == nil {
return errNeedSandbox
return vcTypes.ErrNeedSandbox
}

if containerID == "" {
return errNeedContainerID
return vcTypes.ErrNeedContainerID
}

if _, ok := s.containers[containerID]; !ok {
Expand Down Expand Up @@ -1130,7 +1130,7 @@ func (s *Sandbox) KillContainer(containerID string, signal syscall.Signal, all b
// DeleteContainer deletes a container from the sandbox
func (s *Sandbox) DeleteContainer(containerID string) (VCContainer, error) {
if containerID == "" {
return nil, errNeedContainerID
return nil, vcTypes.ErrNeedContainerID
}

// Fetch the container.
Expand Down Expand Up @@ -1178,7 +1178,7 @@ func (s *Sandbox) ProcessListContainer(containerID string, options ProcessListOp
// TODO: update container status properly, see kata-containers/runtime#253
func (s *Sandbox) StatusContainer(containerID string) (ContainerStatus, error) {
if containerID == "" {
return ContainerStatus{}, errNeedContainerID
return ContainerStatus{}, vcTypes.ErrNeedContainerID
}

for id, c := range s.containers {
Expand All @@ -1198,7 +1198,7 @@ func (s *Sandbox) StatusContainer(containerID string) (ContainerStatus, error) {
}
}

return ContainerStatus{}, errNoSuchContainer
return ContainerStatus{}, vcTypes.ErrNoSuchContainer
}

// EnterContainer is the virtcontainers container command execution entry point.
Expand Down Expand Up @@ -1405,7 +1405,7 @@ func (s *Sandbox) enter(args []string) error {
// sandbox.
func (s *Sandbox) setSandboxState(state types.StateString) error {
if state == "" {
return errNeedState
return vcTypes.ErrNeedState
}

// update in-memory state
Expand Down Expand Up @@ -1467,7 +1467,7 @@ func (s *Sandbox) decrementSandboxBlockIndex() error {

func (s *Sandbox) setContainersState(state types.StateString) error {
if state == "" {
return errNeedState
return vcTypes.ErrNeedState
}

for _, c := range s.containers {
Expand All @@ -1485,7 +1485,7 @@ func togglePauseSandbox(ctx context.Context, sandboxID string, pause bool) (*San
defer span.Finish()

if sandboxID == "" {
return nil, errNeedSandbox
return nil, vcTypes.ErrNeedSandbox
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
Expand Down

0 comments on commit cf90751

Please sign in to comment.