Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Transfer service to add OCI descriptors to Progress structure #9630

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/next.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7231,6 +7231,7 @@ file {
file {
name: "github.com/containerd/containerd/api/types/transfer/progress.proto"
package: "containerd.types.transfer"
dependency: "github.com/containerd/containerd/api/types/descriptor.proto"
message_type {
name: "Progress"
field {
Expand Down Expand Up @@ -7268,6 +7269,14 @@ file {
type: TYPE_INT64
json_name: "total"
}
field {
name: "desc"
number: 6
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
type_name: ".containerd.types.Descriptor"
json_name: "desc"
}
}
options {
go_package: "github.com/containerd/containerd/v2/api/types/transfer"
Expand Down
68 changes: 43 additions & 25 deletions api/types/transfer/progress.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/types/transfer/progress.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ syntax = "proto3";

package containerd.types.transfer;

import "github.com/containerd/containerd/api/types/descriptor.proto";

option go_package = "github.com/containerd/containerd/v2/api/types/transfer";

message Progress {
Expand All @@ -26,4 +28,5 @@ message Progress {
repeated string parents = 3;
int64 progress = 4;
int64 total = 5;
containerd.types.Descriptor desc = 6;
}
17 changes: 17 additions & 0 deletions cmd/ctr/commands/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ type progressNode struct {
root bool
}

func (n *progressNode) mainDesc() *ocispec.Descriptor {
if n.Desc != nil {
return n.Desc
}
for _, c := range n.children {
if desc := c.mainDesc(); desc != nil {
return desc
}
}
return nil
}

// ProgressHandler continuously updates the output with job progress
// by checking status in the content store.
func ProgressHandler(ctx context.Context, out io.Writer) (transfer.ProgressFunc, func()) {
Expand Down Expand Up @@ -329,6 +341,11 @@ func ProgressHandler(ctx context.Context, out io.Writer) (transfer.ProgressFunc,

func DisplayHierarchy(w io.Writer, status string, roots []*progressNode, start time.Time) {
total := displayNode(w, "", roots)
for _, r := range roots {
if desc := r.mainDesc(); desc != nil {
fmt.Fprintf(w, "%s %s\n", desc.MediaType, desc.Digest)
}
}
// Print the Status line
fmt.Fprintf(w, "%s\telapsed: %-4.1fs\ttotal: %7.6v\t(%v)\t\n",
status,
Expand Down
2 changes: 2 additions & 0 deletions pkg/transfer/local/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (ts *localTransferService) importStream(ctx context.Context, i transfer.Ima
}

for _, desc := range descriptors {
desc := desc
imgs, err := is.Store(ctx, desc, ts.images)
if err != nil {
if errdefs.IsNotFound(err) {
Expand All @@ -142,6 +143,7 @@ func (ts *localTransferService) importStream(ctx context.Context, i transfer.Ima
tops.Progress(transfer.Progress{
Event: "saved",
Name: img.Name,
Desc: &desc,
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/transfer/local/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (j *ProgressTracker) HandleProgress(ctx context.Context, pf transfer.Progre
Parents: job.parents,
Progress: status.Offset,
Total: status.Total,
Desc: &job.desc,
})
job.progress = status.Offset
job.state = jobInProgress
Expand All @@ -122,6 +123,7 @@ func (j *ProgressTracker) HandleProgress(ctx context.Context, pf transfer.Progre
Parents: job.parents,
Progress: job.desc.Size,
Total: job.desc.Size,
Desc: &job.desc,
})

}
Expand Down Expand Up @@ -165,6 +167,7 @@ func (j *ProgressTracker) HandleProgress(ctx context.Context, pf transfer.Progre
//Digest: desc.Digest.String(),
Progress: 0,
Total: update.desc.Size,
Desc: &job.desc,
})
}
if update.exists {
Expand All @@ -173,6 +176,7 @@ func (j *ProgressTracker) HandleProgress(ctx context.Context, pf transfer.Progre
Name: remotes.MakeRefKey(ctx, update.desc),
Progress: update.desc.Size,
Total: update.desc.Size,
Desc: &job.desc,
})
job.state = jobComplete
job.progress = job.desc.Size
Expand Down
3 changes: 3 additions & 0 deletions pkg/transfer/local/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (ts *localTransferService) push(ctx context.Context, ig transfer.ImageGette
Event: "pushing content",
Name: img.Name,
//Digest: img.Target.Digest.String(),
Desc: &img.Target,
})
}

Expand Down Expand Up @@ -109,9 +110,11 @@ func (ts *localTransferService) push(ctx context.Context, ig transfer.ImageGette
Event: "pushed content",
Name: img.Name,
//Digest: img.Target.Digest.String(),
Desc: &img.Target,
})
tops.Progress(transfer.Progress{
Event: fmt.Sprintf("Completed push to %s", p),
Desc: &img.Target,
})
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/transfer/proxy/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import (

transferapi "github.com/containerd/containerd/v2/api/services/transfer/v1"
transfertypes "github.com/containerd/containerd/v2/api/types/transfer"
"github.com/containerd/containerd/v2/oci"
"github.com/containerd/containerd/v2/pkg/streaming"
"github.com/containerd/containerd/v2/pkg/transfer"
tstreaming "github.com/containerd/containerd/v2/pkg/transfer/streaming"
"github.com/containerd/log"
"github.com/containerd/typeurl/v2"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

type proxyTransferrer struct {
Expand Down Expand Up @@ -74,12 +76,18 @@ func (p *proxyTransferrer) Transfer(ctx context.Context, src interface{}, dst in
}
switch v := i.(type) {
case *transfertypes.Progress:
var descp *ocispec.Descriptor
if v.Desc != nil {
desc := oci.DescriptorFromProto(v.Desc)
descp = &desc
}
o.Progress(transfer.Progress{
Event: v.Event,
Name: v.Name,
Parents: v.Parents,
Progress: v.Progress,
Total: v.Total,
Desc: descp,
})
default:
log.G(ctx).Warnf("unhandled progress object %T: %v", i, a.GetTypeUrl())
Expand Down
2 changes: 1 addition & 1 deletion pkg/transfer/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ type Progress struct {
Parents []string
Progress int64
Total int64
// Descriptor?
Desc *ocispec.Descriptor // since containerd v2.0
}
7 changes: 7 additions & 0 deletions services/transfer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"context"

transferapi "github.com/containerd/containerd/v2/api/services/transfer/v1"
"github.com/containerd/containerd/v2/api/types"
transferTypes "github.com/containerd/containerd/v2/api/types/transfer"
"github.com/containerd/containerd/v2/errdefs"
"github.com/containerd/containerd/v2/oci"
"github.com/containerd/containerd/v2/pkg/streaming"
"github.com/containerd/containerd/v2/pkg/transfer"
tplugins "github.com/containerd/containerd/v2/pkg/transfer/plugins"
Expand Down Expand Up @@ -92,12 +94,17 @@ func (s *service) Transfer(ctx context.Context, req *transferapi.TransferRequest
defer stream.Close()

pf := func(p transfer.Progress) {
var descp *types.Descriptor
if p.Desc != nil {
descp = oci.DescriptorToProto(*p.Desc)
}
progress, err := typeurl.MarshalAny(&transferTypes.Progress{
Event: p.Event,
Name: p.Name,
Parents: p.Parents,
Progress: p.Progress,
Total: p.Total,
Desc: descp,
})
if err != nil {
log.G(ctx).WithError(err).Warnf("event could not be marshaled: %v/%v", p.Event, p.Name)
Expand Down
Loading