MCPcopy
hub / github.com/containerd/containerd / WithContainerExtension

Function WithContainerExtension

client/container_opts.go:293–313  ·  view source on GitHub ↗

WithContainerExtension appends extension data to the container object. Use this to decorate the container object with additional data for the client integration. Make sure to register the type of `extension` in the typeurl package via `typeurl.Register` or container creation may fail.

(name string, extension any)

Source from the content-addressed store, hash-verified

291// Make sure to register the type of `extension` in the typeurl package via
292// `typeurl.Register` or container creation may fail.
293func WithContainerExtension(name string, extension any) NewContainerOpts {
294 return func(ctx context.Context, client *Client, c *containers.Container) error {
295 if name == "" {
296 return fmt.Errorf("extension key must not be zero-length: %w", errdefs.ErrInvalidArgument)
297 }
298
299 ext, err := typeurl.MarshalAny(extension)
300 if err != nil {
301 if errors.Is(err, typeurl.ErrNotFound) {
302 return fmt.Errorf("extension %q is not registered with the typeurl package, see `typeurl.Register`: %w", name, err)
303 }
304 return fmt.Errorf("error marshalling extension: %w", err)
305 }
306
307 if c.Extensions == nil {
308 c.Extensions = make(map[string]typeurl.Any)
309 }
310 c.Extensions[name] = ext
311 return nil
312 }
313}
314
315// WithNewSpec generates a new spec for a new container
316func WithNewSpec(opts ...oci.SpecOpts) NewContainerOpts {

Callers 1

TestContainerExtensionsFunction · 0.85

Calls 1

MarshalAnyMethod · 0.65

Tested by 1

TestContainerExtensionsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…