Skip to content

Commit

Permalink
remove duplicated descriptor from/to proto
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
  • Loading branch information
djdongjin committed Aug 31, 2024
1 parent 93d6f0f commit 3d7955b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
26 changes: 3 additions & 23 deletions plugins/services/images/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ package images

import (
imagesapi "github.com/containerd/containerd/api/services/images/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/v2/core/images"
"github.com/containerd/containerd/v2/pkg/oci"
"github.com/containerd/containerd/v2/pkg/protobuf"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

func imagesToProto(images []images.Image) []*imagesapi.Image {
Expand All @@ -40,7 +38,7 @@ func imageToProto(image *images.Image) *imagesapi.Image {
return &imagesapi.Image{
Name: image.Name,
Labels: image.Labels,
Target: descToProto(&image.Target),
Target: oci.DescriptorToProto(image.Target),
CreatedAt: protobuf.ToTimestamp(image.CreatedAt),
UpdatedAt: protobuf.ToTimestamp(image.UpdatedAt),
}
Expand All @@ -50,26 +48,8 @@ func imageFromProto(imagepb *imagesapi.Image) images.Image {
return images.Image{
Name: imagepb.Name,
Labels: imagepb.Labels,
Target: descFromProto(imagepb.Target),
Target: oci.DescriptorFromProto(imagepb.Target),
CreatedAt: protobuf.FromTimestamp(imagepb.CreatedAt),
UpdatedAt: protobuf.FromTimestamp(imagepb.UpdatedAt),
}
}

func descFromProto(desc *types.Descriptor) ocispec.Descriptor {
return ocispec.Descriptor{
MediaType: desc.MediaType,
Size: desc.Size,
Digest: digest.Digest(desc.Digest),
Annotations: desc.Annotations,
}
}

func descToProto(desc *ocispec.Descriptor) *types.Descriptor {
return &types.Descriptor{
MediaType: desc.MediaType,
Size: desc.Size,
Digest: desc.Digest.String(),
Annotations: desc.Annotations,
}
}
3 changes: 2 additions & 1 deletion plugins/services/images/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/containerd/containerd/v2/pkg/deprecation"
"github.com/containerd/containerd/v2/pkg/epoch"
"github.com/containerd/containerd/v2/pkg/gc"
"github.com/containerd/containerd/v2/pkg/oci"
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
"github.com/containerd/containerd/v2/plugins"
"github.com/containerd/containerd/v2/plugins/services"
Expand Down Expand Up @@ -168,7 +169,7 @@ func (l *local) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest, _

var opts []images.DeleteOpt
if req.Target != nil {
desc := descFromProto(req.Target)
desc := oci.DescriptorFromProto(req.Target)
opts = append(opts, images.DeleteTarget(&desc))
}

Expand Down

0 comments on commit 3d7955b

Please sign in to comment.