NewContainer will create a new container with the provided id. The id must be unique within the namespace.
(ctx context.Context, id string, opts ...NewContainerOpts)
| 338 | // NewContainer will create a new container with the provided id. |
| 339 | // The id must be unique within the namespace. |
| 340 | func (c *Client) NewContainer(ctx context.Context, id string, opts ...NewContainerOpts) (Container, error) { |
| 341 | ctx, span := tracing.StartSpan(ctx, "client.NewContainer") |
| 342 | defer span.End() |
| 343 | ctx, done, err := c.WithLease(ctx) |
| 344 | if err != nil { |
| 345 | return nil, err |
| 346 | } |
| 347 | defer done(ctx) |
| 348 | |
| 349 | runtime, err := c.defaultRuntime(ctx) |
| 350 | if err != nil { |
| 351 | return nil, err |
| 352 | } |
| 353 | |
| 354 | container := containers.Container{ |
| 355 | ID: id, |
| 356 | Runtime: containers.RuntimeInfo{ |
| 357 | Name: runtime, |
| 358 | }, |
| 359 | } |
| 360 | for _, o := range opts { |
| 361 | if err := o(ctx, c, &container); err != nil { |
| 362 | return nil, err |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | span.SetAttributes( |
| 367 | tracing.Attribute("container.id", container.ID), |
| 368 | tracing.Attribute("container.image.ref", container.Image), |
| 369 | tracing.Attribute("container.runtime.name", container.Runtime.Name), |
| 370 | tracing.Attribute("container.snapshotter.name", container.Snapshotter), |
| 371 | ) |
| 372 | r, err := c.ContainerService().Create(ctx, container) |
| 373 | if err != nil { |
| 374 | return nil, err |
| 375 | } |
| 376 | return containerFromRecord(c, r), nil |
| 377 | } |
| 378 | |
| 379 | // LoadContainer loads an existing container from metadata |
| 380 | func (c *Client) LoadContainer(ctx context.Context, id string) (Container, error) { |
no test coverage detected