MCPcopy Index your code
hub / github.com/containerd/containerd / Create

Method Create

core/metadata/sandbox.go:54–93  ·  view source on GitHub ↗

Create a sandbox record in the store

(ctx context.Context, sandbox api.Sandbox)

Source from the content-addressed store, hash-verified

52
53// Create a sandbox record in the store
54func (s *sandboxStore) Create(ctx context.Context, sandbox api.Sandbox) (api.Sandbox, error) {
55 ctx, span := tracing.StartSpan(ctx,
56 tracing.Name(spanSandboxPrefix, "Create"),
57 tracing.WithAttribute("sandbox.id", sandbox.ID),
58 tracing.WithNamespace(ctx),
59 )
60 defer span.End()
61
62 ns, err := namespaces.NamespaceRequired(ctx)
63 if err != nil {
64 return api.Sandbox{}, err
65 }
66
67 sandbox.CreatedAt = time.Now().UTC()
68 sandbox.UpdatedAt = sandbox.CreatedAt
69
70 if err := s.validate(&sandbox); err != nil {
71 return api.Sandbox{}, fmt.Errorf("failed to validate sandbox: %w", err)
72 }
73
74 if err := update(ctx, s.db, func(tx *bbolt.Tx) error {
75 parent, err := createSandboxBucket(tx, ns)
76 if err != nil {
77 return fmt.Errorf("create error: %w", err)
78 }
79
80 if err := s.write(parent, &sandbox, false); err != nil {
81 return fmt.Errorf("write error: %w", err)
82 }
83
84 span.SetAttributes(
85 tracing.Attribute("sandbox.CreatedAt", sandbox.CreatedAt.Format(time.RFC3339)),
86 )
87 return nil
88 }); err != nil {
89 return api.Sandbox{}, err
90 }
91
92 return sandbox, nil
93}
94
95// Update the sandbox with the provided sandbox object and fields
96func (s *sandboxStore) Update(ctx context.Context, sandbox api.Sandbox, fieldpaths ...string) (api.Sandbox, error) {

Callers

nothing calls this directly

Calls 13

validateMethod · 0.95
writeMethod · 0.95
StartSpanFunction · 0.92
NameFunction · 0.92
WithAttributeFunction · 0.92
WithNamespaceFunction · 0.92
NamespaceRequiredFunction · 0.92
AttributeFunction · 0.92
updateFunction · 0.85
createSandboxBucketFunction · 0.85
EndMethod · 0.80
SetAttributesMethod · 0.80

Tested by

no test coverage detected