mirror of
https://github.com/containerd/containerd.git
synced 2026-08-09 09:33:06 +00:00
Merge pull request #11827 from k8s-infra-cherrypick-robot/cherry-pick-11811-to-release/2.1
[release/2.1] ctr:make sure containerd socket exist before create client
This commit is contained in:
@@ -18,6 +18,7 @@ package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
@@ -59,7 +60,11 @@ func AppContext(cliContext *cli.Context) (context.Context, context.CancelFunc) {
|
||||
func NewClient(cliContext *cli.Context, opts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) {
|
||||
timeoutOpt := containerd.WithTimeout(cliContext.Duration("connect-timeout"))
|
||||
opts = append(opts, timeoutOpt)
|
||||
client, err := containerd.New(cliContext.String("address"), opts...)
|
||||
socketPath := cliContext.String("address")
|
||||
if _, err := os.Stat(socketPath); err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("cannot access socket %s: %w", socketPath, err)
|
||||
}
|
||||
client, err := containerd.New(socketPath, opts...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user