(ctx context.Context, id string)
| 285 | } |
| 286 | |
| 287 | func (s *containerStore) Delete(ctx context.Context, id string) error { |
| 288 | ctx, span := tracing.StartSpan(ctx, |
| 289 | tracing.Name(spanContainerPrefix, "Delete"), |
| 290 | tracing.WithAttribute("container.id", id), |
| 291 | tracing.WithNamespace(ctx), |
| 292 | ) |
| 293 | defer span.End() |
| 294 | |
| 295 | if meta, err := s.Get(ctx, id); err == nil && meta.SandboxID != "" { |
| 296 | span.SetAttributes(tracing.Attribute("sandbox.id", meta.SandboxID)) |
| 297 | } |
| 298 | |
| 299 | namespace, err := namespaces.NamespaceRequired(ctx) |
| 300 | if err != nil { |
| 301 | return err |
| 302 | } |
| 303 | |
| 304 | return update(ctx, s.db, func(tx *bolt.Tx) error { |
| 305 | bkt := getContainersBucket(tx, namespace) |
| 306 | if bkt == nil { |
| 307 | return fmt.Errorf("cannot delete container %q in namespace %q: %w", id, namespace, errdefs.ErrNotFound) |
| 308 | } |
| 309 | |
| 310 | if err := bkt.DeleteBucket([]byte(id)); err != nil { |
| 311 | if err == errbolt.ErrBucketNotFound { |
| 312 | err = fmt.Errorf("container %v: %w", id, errdefs.ErrNotFound) |
| 313 | } |
| 314 | return err |
| 315 | } |
| 316 | |
| 317 | s.db.dirty.Add(1) |
| 318 | |
| 319 | return nil |
| 320 | }) |
| 321 | } |
| 322 | |
| 323 | func validateContainer(container *containers.Container) error { |
| 324 | if err := identifiers.Validate(container.ID); err != nil { |
nothing calls this directly
no test coverage detected