MCPcopy
hub / github.com/containerd/containerd / AppContext

Function AppContext

cmd/ctr/commands/client.go:37–57  ·  view source on GitHub ↗

AppContext returns the context for a command. Should only be called once per command, near the start. This will ensure the namespace is picked up and set the timeout, if one is defined.

(cliContext *cli.Context)

Source from the content-addressed store, hash-verified

35// This will ensure the namespace is picked up and set the timeout, if one is
36// defined.
37func AppContext(cliContext *cli.Context) (context.Context, context.CancelFunc) {
38 var (
39 ctx = cliContext.Context
40 timeout = cliContext.Duration("timeout")
41 namespace = cliContext.String("namespace")
42 cancel context.CancelFunc
43 )
44 ctx = namespaces.WithNamespace(ctx, namespace)
45 if timeout > 0 {
46 ctx, cancel = context.WithTimeout(ctx, timeout)
47 } else {
48 ctx, cancel = context.WithCancel(ctx)
49 }
50 if tm, err := epoch.SourceDateEpoch(); err != nil {
51 log.L.WithError(err).Warn("Failed to read SOURCE_DATE_EPOCH")
52 } else if tm != nil {
53 log.L.Debugf("Using SOURCE_DATE_EPOCH: %v", tm)
54 ctx = epoch.WithSourceDateEpoch(ctx, tm)
55 }
56 return ctx, cancel
57}
58
59// NewClient returns a new containerd client
60func NewClient(cliContext *cli.Context, opts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) {

Callers 3

oci.goFile · 0.92
content.goFile · 0.92
NewClientFunction · 0.85

Calls 4

WithNamespaceFunction · 0.92
SourceDateEpochFunction · 0.92
WithSourceDateEpochFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…