remove duplicated descriptor from/to proto
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
This commit is contained in:
parent
93d6f0f921
commit
3d7955bf78
@ -18,11 +18,9 @@ package images
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
imagesapi "github.com/containerd/containerd/api/services/images/v1"
|
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/core/images"
|
||||||
|
"github.com/containerd/containerd/v2/pkg/oci"
|
||||||
"github.com/containerd/containerd/v2/pkg/protobuf"
|
"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 {
|
func imagesToProto(images []images.Image) []*imagesapi.Image {
|
||||||
@ -40,7 +38,7 @@ func imageToProto(image *images.Image) *imagesapi.Image {
|
|||||||
return &imagesapi.Image{
|
return &imagesapi.Image{
|
||||||
Name: image.Name,
|
Name: image.Name,
|
||||||
Labels: image.Labels,
|
Labels: image.Labels,
|
||||||
Target: descToProto(&image.Target),
|
Target: oci.DescriptorToProto(image.Target),
|
||||||
CreatedAt: protobuf.ToTimestamp(image.CreatedAt),
|
CreatedAt: protobuf.ToTimestamp(image.CreatedAt),
|
||||||
UpdatedAt: protobuf.ToTimestamp(image.UpdatedAt),
|
UpdatedAt: protobuf.ToTimestamp(image.UpdatedAt),
|
||||||
}
|
}
|
||||||
@ -50,26 +48,8 @@ func imageFromProto(imagepb *imagesapi.Image) images.Image {
|
|||||||
return images.Image{
|
return images.Image{
|
||||||
Name: imagepb.Name,
|
Name: imagepb.Name,
|
||||||
Labels: imagepb.Labels,
|
Labels: imagepb.Labels,
|
||||||
Target: descFromProto(imagepb.Target),
|
Target: oci.DescriptorFromProto(imagepb.Target),
|
||||||
CreatedAt: protobuf.FromTimestamp(imagepb.CreatedAt),
|
CreatedAt: protobuf.FromTimestamp(imagepb.CreatedAt),
|
||||||
UpdatedAt: protobuf.FromTimestamp(imagepb.UpdatedAt),
|
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/containerd/containerd/v2/pkg/deprecation"
|
"github.com/containerd/containerd/v2/pkg/deprecation"
|
||||||
"github.com/containerd/containerd/v2/pkg/epoch"
|
"github.com/containerd/containerd/v2/pkg/epoch"
|
||||||
"github.com/containerd/containerd/v2/pkg/gc"
|
"github.com/containerd/containerd/v2/pkg/gc"
|
||||||
|
"github.com/containerd/containerd/v2/pkg/oci"
|
||||||
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
|
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
|
||||||
"github.com/containerd/containerd/v2/plugins"
|
"github.com/containerd/containerd/v2/plugins"
|
||||||
"github.com/containerd/containerd/v2/plugins/services"
|
"github.com/containerd/containerd/v2/plugins/services"
|
||||||
@ -168,7 +169,7 @@ func (l *local) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest, _
|
|||||||
|
|
||||||
var opts []images.DeleteOpt
|
var opts []images.DeleteOpt
|
||||||
if req.Target != nil {
|
if req.Target != nil {
|
||||||
desc := descFromProto(req.Target)
|
desc := oci.DescriptorFromProto(req.Target)
|
||||||
opts = append(opts, images.DeleteTarget(&desc))
|
opts = append(opts, images.DeleteTarget(&desc))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user