(ctx context.Context, namespace, address string, opts ...containerd.Opt)
| 36 | ) |
| 37 | |
| 38 | func NewClient(ctx context.Context, namespace, address string, opts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) { |
| 39 | ctx = namespaces.WithNamespace(ctx, namespace) |
| 40 | |
| 41 | address = strings.TrimPrefix(address, "unix://") |
| 42 | const dockerContainerdaddress = "/var/run/docker/containerd/containerd.sock" |
| 43 | if err := systemutil.IsSocketAccessible(address); err != nil { |
| 44 | if systemutil.IsSocketAccessible(dockerContainerdaddress) == nil { |
| 45 | err = fmt.Errorf("cannot access containerd socket %q (hint: try running with `--address %s` to connect to Docker-managed containerd): %w", address, dockerContainerdaddress, err) |
| 46 | } else { |
| 47 | err = fmt.Errorf("cannot access containerd socket %q: %w", address, err) |
| 48 | } |
| 49 | return nil, nil, nil, err |
| 50 | } |
| 51 | client, err := containerd.New(address, opts...) |
| 52 | if err != nil { |
| 53 | return nil, nil, nil, err |
| 54 | } |
| 55 | var cancel context.CancelFunc |
| 56 | ctx, cancel = context.WithCancel(ctx) |
| 57 | return client, ctx, cancel, nil |
| 58 | } |
| 59 | |
| 60 | func NewClientWithPlatform(ctx context.Context, namespace, address, platform string, clientOpts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) { |
| 61 | if platform != "" { |
no test coverage detected
searching dependent graphs…