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)
| 291 | // Make sure to register the type of `extension` in the typeurl package via |
| 292 | // `typeurl.Register` or container creation may fail. |
| 293 | func 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 |
| 316 | func WithNewSpec(opts ...oci.SpecOpts) NewContainerOpts { |
searching dependent graphs…