MCPcopy
hub / github.com/containerd/containerd / NewClient

Function NewClient

cmd/ctr/commands/client.go:60–90  ·  view source on GitHub ↗

NewClient returns a new containerd client

(cliContext *cli.Context, opts ...containerd.Opt)

Source from the content-addressed store, hash-verified

58
59// NewClient returns a new containerd client
60func NewClient(cliContext *cli.Context, opts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) {
61 timeoutOpt := containerd.WithTimeout(cliContext.Duration("connect-timeout"))
62 opts = append(opts, timeoutOpt)
63 socketPath := cliContext.String("address")
64 if _, err := os.Stat(socketPath); err != nil {
65 return nil, nil, nil, fmt.Errorf("cannot access socket %s: %w", socketPath, err)
66 }
67 client, err := containerd.New(socketPath, opts...)
68 if err != nil {
69 return nil, nil, nil, err
70 }
71 ctx, cancel := AppContext(cliContext)
72 var suppressDeprecationWarnings bool
73 if s := os.Getenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS"); s != "" {
74 suppressDeprecationWarnings, err = strconv.ParseBool(s)
75 if err != nil {
76 log.L.WithError(err).Warn("Failed to parse CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS=" + s)
77 }
78 }
79 if !suppressDeprecationWarnings {
80 resp, err := client.IntrospectionService().Server(ctx)
81 if err != nil {
82 log.L.WithError(err).Warn("Failed to check deprecations")
83 } else {
84 for _, d := range resp.Deprecations {
85 log.L.Warn("DEPRECATION: " + d.Message)
86 }
87 }
88 }
89 return client, ctx, cancel, nil
90}

Callers 15

snapshots.goFile · 0.92
leases.goFile · 0.92
namespaces.goFile · 0.92
sandboxes.goFile · 0.92
version.goFile · 0.92
restore.goFile · 0.92
containers.goFile · 0.92
checkpoint.goFile · 0.92
events.goFile · 0.92
start.goFile · 0.92
attach.goFile · 0.92
resume.goFile · 0.92

Calls 5

AppContextFunction · 0.85
IntrospectionServiceMethod · 0.80
StatMethod · 0.65
ServerMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…