Skip to content

Commit

Permalink
Merge pull request containerd#10856 from dmcgowan/update-errdefs-0.3.0
Browse files Browse the repository at this point in the history
Update errdefs to 0.3.0
  • Loading branch information
AkihiroSuda authored Oct 21, 2024
2 parents b291eb8 + 2f24aa0 commit bc3ce87
Show file tree
Hide file tree
Showing 61 changed files with 2,039 additions and 514 deletions.
20 changes: 11 additions & 9 deletions client/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ import (
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/api/types/runc/options"
tasktypes "github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/v2/core/containers"
"github.com/containerd/containerd/v2/core/images"
"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/containerd/v2/pkg/oci"
"github.com/containerd/containerd/v2/pkg/tracing"
"github.com/containerd/errdefs"
"github.com/containerd/errdefs/pkg/errgrpc"
"github.com/containerd/fifo"
"github.com/containerd/typeurl/v2"
ver "github.com/opencontainers/image-spec/specs-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/selinux/go-selinux/label"

"github.com/containerd/containerd/v2/core/containers"
"github.com/containerd/containerd/v2/core/images"
"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/containerd/v2/pkg/oci"
"github.com/containerd/containerd/v2/pkg/tracing"
)

const (
Expand Down Expand Up @@ -317,7 +319,7 @@ func (c *container) NewTask(ctx context.Context, ioCreate cio.Creator, opts ...N
)
response, err := c.client.TaskService().Create(ctx, request)
if err != nil {
return nil, errdefs.FromGRPC(err)
return nil, errgrpc.ToNative(err)
}

span.AddEvent("task created",
Expand All @@ -341,7 +343,7 @@ func (c *container) Update(ctx context.Context, opts ...UpdateContainerOpts) err
}
}
if _, err := c.client.ContainerService().Update(ctx, r); err != nil {
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}
return nil
}
Expand Down Expand Up @@ -387,7 +389,7 @@ func (c *container) Checkpoint(ctx context.Context, ref string, opts ...Checkpoi
// process remaining opts
for _, o := range opts {
if err := o(ctx, c.client, &info, index, copts); err != nil {
err = errdefs.FromGRPC(err)
err = errgrpc.ToNative(err)
if !errdefs.IsAlreadyExists(err) {
return nil, err
}
Expand Down Expand Up @@ -415,7 +417,7 @@ func (c *container) loadTask(ctx context.Context, ioAttach cio.Attach) (Task, er
ContainerID: c.id,
})
if err != nil {
err = errdefs.FromGRPC(err)
err = errgrpc.ToNative(err)
if errdefs.IsNotFound(err) {
return nil, fmt.Errorf("no running task found: %w", err)
}
Expand Down
23 changes: 12 additions & 11 deletions client/containerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
"io"

containersapi "github.com/containerd/containerd/api/services/containers/v1"
"github.com/containerd/containerd/v2/core/containers"
"github.com/containerd/containerd/v2/pkg/protobuf"
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
"github.com/containerd/errdefs"
"github.com/containerd/errdefs/pkg/errgrpc"
"github.com/containerd/typeurl/v2"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/containerd/containerd/v2/core/containers"
"github.com/containerd/containerd/v2/pkg/protobuf"
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
)

type remoteContainers struct {
Expand All @@ -49,7 +50,7 @@ func (r *remoteContainers) Get(ctx context.Context, id string) (containers.Conta
ID: id,
})
if err != nil {
return containers.Container{}, errdefs.FromGRPC(err)
return containers.Container{}, errgrpc.ToNative(err)
}

return containerFromProto(resp.Container), nil
Expand All @@ -71,7 +72,7 @@ func (r *remoteContainers) list(ctx context.Context, filters ...string) ([]conta
Filters: filters,
})
if err != nil {
return nil, errdefs.FromGRPC(err)
return nil, errgrpc.ToNative(err)
}
return containersFromProto(resp.Containers), nil
}
Expand All @@ -83,7 +84,7 @@ func (r *remoteContainers) stream(ctx context.Context, filters ...string) ([]con
Filters: filters,
})
if err != nil {
return nil, errdefs.FromGRPC(err)
return nil, errgrpc.ToNative(err)
}
var containers []containers.Container
for {
Expand All @@ -97,7 +98,7 @@ func (r *remoteContainers) stream(ctx context.Context, filters ...string) ([]con
return nil, errStreamNotAvailable
}
}
return nil, errdefs.FromGRPC(err)
return nil, errgrpc.ToNative(err)
}
select {
case <-ctx.Done():
Expand All @@ -113,7 +114,7 @@ func (r *remoteContainers) Create(ctx context.Context, container containers.Cont
Container: containerToProto(&container),
})
if err != nil {
return containers.Container{}, errdefs.FromGRPC(err)
return containers.Container{}, errgrpc.ToNative(err)
}

return containerFromProto(created.Container), nil
Expand All @@ -133,7 +134,7 @@ func (r *remoteContainers) Update(ctx context.Context, container containers.Cont
UpdateMask: updateMask,
})
if err != nil {
return containers.Container{}, errdefs.FromGRPC(err)
return containers.Container{}, errgrpc.ToNative(err)
}

return containerFromProto(updated.Container), nil
Expand All @@ -145,7 +146,7 @@ func (r *remoteContainers) Delete(ctx context.Context, id string) error {
ID: id,
})

return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)

}

Expand Down
9 changes: 5 additions & 4 deletions client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (

eventsapi "github.com/containerd/containerd/api/services/events/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/errdefs/pkg/errgrpc"
"github.com/containerd/typeurl/v2"

"github.com/containerd/containerd/v2/core/events"
"github.com/containerd/containerd/v2/pkg/protobuf"
"github.com/containerd/errdefs"
"github.com/containerd/typeurl/v2"
)

// EventService handles the publish, forward and subscribe of events.
Expand Down Expand Up @@ -56,7 +57,7 @@ func (e *eventRemote) Publish(ctx context.Context, topic string, event events.Ev
Event: typeurl.MarshalProto(evt),
}
if _, err := e.client.Publish(ctx, req); err != nil {
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}
return nil
}
Expand All @@ -71,7 +72,7 @@ func (e *eventRemote) Forward(ctx context.Context, envelope *events.Envelope) er
},
}
if _, err := e.client.Forward(ctx, req); err != nil {
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}
return nil
}
Expand Down
15 changes: 8 additions & 7 deletions client/image_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
"context"

imagesapi "github.com/containerd/containerd/api/services/images/v1"
"github.com/containerd/errdefs/pkg/errgrpc"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/containerd/containerd/v2/core/images"
"github.com/containerd/containerd/v2/pkg/epoch"
"github.com/containerd/containerd/v2/pkg/oci"
"github.com/containerd/containerd/v2/pkg/protobuf"
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
"github.com/containerd/errdefs"
"google.golang.org/protobuf/types/known/timestamppb"
)

type remoteImages struct {
Expand All @@ -45,7 +46,7 @@ func (s *remoteImages) Get(ctx context.Context, name string) (images.Image, erro
Name: name,
})
if err != nil {
return images.Image{}, errdefs.FromGRPC(err)
return images.Image{}, errgrpc.ToNative(err)
}

return imageFromProto(resp.Image), nil
Expand All @@ -56,7 +57,7 @@ func (s *remoteImages) List(ctx context.Context, filters ...string) ([]images.Im
Filters: filters,
})
if err != nil {
return nil, errdefs.FromGRPC(err)
return nil, errgrpc.ToNative(err)
}

return imagesFromProto(resp.Images), nil
Expand All @@ -71,7 +72,7 @@ func (s *remoteImages) Create(ctx context.Context, image images.Image) (images.I
}
created, err := s.client.Create(ctx, req)
if err != nil {
return images.Image{}, errdefs.FromGRPC(err)
return images.Image{}, errgrpc.ToNative(err)
}

return imageFromProto(created.Image), nil
Expand All @@ -93,7 +94,7 @@ func (s *remoteImages) Update(ctx context.Context, image images.Image, fieldpath
}
updated, err := s.client.Update(ctx, req)
if err != nil {
return images.Image{}, errdefs.FromGRPC(err)
return images.Image{}, errgrpc.ToNative(err)
}

return imageFromProto(updated.Image), nil
Expand All @@ -114,7 +115,7 @@ func (s *remoteImages) Delete(ctx context.Context, name string, opts ...images.D
req.Target = oci.DescriptorToProto(*do.Target)
}
_, err := s.client.Delete(ctx, req)
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}

func imageToProto(image *images.Image) *imagesapi.Image {
Expand Down
13 changes: 7 additions & 6 deletions client/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"strings"

api "github.com/containerd/containerd/api/services/namespaces/v1"
"github.com/containerd/errdefs/pkg/errgrpc"

"github.com/containerd/containerd/v2/pkg/namespaces"
"github.com/containerd/containerd/v2/pkg/protobuf/types"
"github.com/containerd/errdefs"
)

// NewNamespaceStoreFromClient returns a new namespace store
Expand All @@ -45,7 +46,7 @@ func (r *remoteNamespaces) Create(ctx context.Context, namespace string, labels

_, err := r.client.Create(ctx, &req)
if err != nil {
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}

return nil
Expand All @@ -57,7 +58,7 @@ func (r *remoteNamespaces) Labels(ctx context.Context, namespace string) (map[st

resp, err := r.client.Get(ctx, &req)
if err != nil {
return nil, errdefs.FromGRPC(err)
return nil, errgrpc.ToNative(err)
}

return resp.Namespace.Labels, nil
Expand All @@ -77,7 +78,7 @@ func (r *remoteNamespaces) SetLabel(ctx context.Context, namespace, key, value s

_, err := r.client.Update(ctx, &req)
if err != nil {
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}

return nil
Expand All @@ -88,7 +89,7 @@ func (r *remoteNamespaces) List(ctx context.Context) ([]string, error) {

resp, err := r.client.List(ctx, &req)
if err != nil {
return nil, errdefs.FromGRPC(err)
return nil, errgrpc.ToNative(err)
}

var namespaces []string
Expand All @@ -114,7 +115,7 @@ func (r *remoteNamespaces) Delete(ctx context.Context, namespace string, opts ..
}
_, err := r.client.Delete(ctx, &req)
if err != nil {
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}

return nil
Expand Down
16 changes: 9 additions & 7 deletions client/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import (
"time"

"github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/errdefs"
"github.com/containerd/errdefs/pkg/errgrpc"

"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/containerd/v2/pkg/protobuf"
"github.com/containerd/containerd/v2/pkg/tracing"
"github.com/containerd/errdefs"
)

// Process represents a system process
Expand Down Expand Up @@ -134,7 +136,7 @@ func (p *process) Start(ctx context.Context) error {
p.io.Wait()
p.io.Close()
}
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}
span.SetAttributes(tracing.Attribute("process.pid", int(r.Pid)))
p.pid = r.Pid
Expand All @@ -160,7 +162,7 @@ func (p *process) Kill(ctx context.Context, s syscall.Signal, opts ...KillOpts)
ExecID: p.id,
All: i.All,
})
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}

func (p *process) Wait(ctx context.Context) (<-chan ExitStatus, error) {
Expand Down Expand Up @@ -206,7 +208,7 @@ func (p *process) CloseIO(ctx context.Context, opts ...IOCloserOpts) error {
}
r.Stdin = i.Stdin
_, err := p.task.client.TaskService().CloseIO(ctx, r)
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}

func (p *process) IO() cio.IO {
Expand All @@ -224,7 +226,7 @@ func (p *process) Resize(ctx context.Context, w, h uint32) error {
Height: h,
ExecID: p.id,
})
return errdefs.FromGRPC(err)
return errgrpc.ToNative(err)
}

func (p *process) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitStatus, error) {
Expand All @@ -250,7 +252,7 @@ func (p *process) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitS
ExecID: p.id,
})
if err != nil {
return nil, errdefs.FromGRPC(err)
return nil, errgrpc.ToNative(err)
}
if p.io != nil {
p.io.Cancel()
Expand All @@ -266,7 +268,7 @@ func (p *process) Status(ctx context.Context) (Status, error) {
ExecID: p.id,
})
if err != nil {
return Status{}, errdefs.FromGRPC(err)
return Status{}, errgrpc.ToNative(err)
}
status := ProcessStatus(strings.ToLower(r.Process.Status.String()))
exitStatus := r.Process.ExitStatus
Expand Down
Loading

0 comments on commit bc3ce87

Please sign in to comment.