Support HTTP debug in ctr

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko
2021-03-22 09:32:34 -07:00
parent 4e919ffaba
commit 22ef69d77d
7 changed files with 104 additions and 37 deletions

View File

@@ -20,6 +20,7 @@ import (
"context"
"fmt"
"io"
"net/http/httptrace"
"os"
"sync"
"text/tabwriter"
@@ -110,6 +111,8 @@ type FetchConfig struct {
AllMetadata bool
// RemoteOpts is not used by ctr, but can be used by other CLI tools
RemoteOpts []containerd.RemoteOpt
// TraceHTTP writes DNS and connection information to the log when dealing with a container registry
TraceHTTP bool
}
// NewFetchConfig returns the default FetchConfig from cli flags
@@ -119,8 +122,9 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig,
return nil, err
}
config := &FetchConfig{
Resolver: resolver,
Labels: clicontext.StringSlice("label"),
Resolver: resolver,
Labels: clicontext.StringSlice("label"),
TraceHTTP: clicontext.Bool("http-trace"),
}
if !clicontext.GlobalBool("debug") {
config.ProgressOutput = os.Stdout
@@ -148,6 +152,10 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig,
func Fetch(ctx context.Context, client *containerd.Client, ref string, config *FetchConfig) (images.Image, error) {
ongoing := NewJobs(ref)
if config.TraceHTTP {
ctx = httptrace.WithClientTrace(ctx, commands.NewDebugClientTrace(ctx))
}
pctx, stopProgress := context.WithCancel(ctx)
progress := make(chan struct{})