(ctx context.Context, container containers.Container)
| 121 | } |
| 122 | |
| 123 | func (s *containerStore) Create(ctx context.Context, container containers.Container) (containers.Container, error) { |
| 124 | ctx, span := tracing.StartSpan(ctx, |
| 125 | tracing.Name(spanContainerPrefix, "Create"), |
| 126 | tracing.WithAttribute("container.id", container.ID), |
| 127 | tracing.WithNamespace(ctx), |
| 128 | ) |
| 129 | defer span.End() |
| 130 | if container.SandboxID != "" { |
| 131 | span.SetAttributes(tracing.Attribute("sandbox.id", container.SandboxID)) |
| 132 | } |
| 133 | namespace, err := namespaces.NamespaceRequired(ctx) |
| 134 | if err != nil { |
| 135 | return containers.Container{}, err |
| 136 | } |
| 137 | |
| 138 | if err := validateContainer(&container); err != nil { |
| 139 | return containers.Container{}, fmt.Errorf("create container failed validation: %w", err) |
| 140 | } |
| 141 | |
| 142 | if err := update(ctx, s.db, func(tx *bolt.Tx) error { |
| 143 | bkt, err := createContainersBucket(tx, namespace) |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } |
| 147 | |
| 148 | cbkt, err := bkt.CreateBucket([]byte(container.ID)) |
| 149 | if err != nil { |
| 150 | if err == errbolt.ErrBucketExists { |
| 151 | err = fmt.Errorf("container %q: %w", container.ID, errdefs.ErrAlreadyExists) |
| 152 | } |
| 153 | return err |
| 154 | } |
| 155 | |
| 156 | container.CreatedAt = time.Now().UTC() |
| 157 | container.UpdatedAt = container.CreatedAt |
| 158 | if err := writeContainer(cbkt, &container); err != nil { |
| 159 | return fmt.Errorf("failed to write container %q: %w", container.ID, err) |
| 160 | } |
| 161 | |
| 162 | span.SetAttributes( |
| 163 | tracing.Attribute("container.createdAt", container.CreatedAt.Format(time.RFC3339)), |
| 164 | tracing.Attribute("container.updatedAt", container.UpdatedAt.Format(time.RFC3339)), |
| 165 | ) |
| 166 | return nil |
| 167 | }); err != nil { |
| 168 | return containers.Container{}, err |
| 169 | } |
| 170 | |
| 171 | return container, nil |
| 172 | } |
| 173 | |
| 174 | func (s *containerStore) Update(ctx context.Context, container containers.Container, fieldpaths ...string) (containers.Container, error) { |
| 175 | if container.ID == "" { |
nothing calls this directly
no test coverage detected