(ctx context.Context, ioCreate cio.Creator, opts ...NewTaskOpts)
| 224 | } |
| 225 | |
| 226 | func (c *container) NewTask(ctx context.Context, ioCreate cio.Creator, opts ...NewTaskOpts) (_ Task, retErr error) { |
| 227 | ctx, span := tracing.StartSpan(ctx, "container.NewTask") |
| 228 | defer span.End() |
| 229 | i, err := ioCreate(c.id) |
| 230 | if err != nil { |
| 231 | return nil, err |
| 232 | } |
| 233 | defer func() { |
| 234 | if retErr != nil && i != nil { |
| 235 | i.Cancel() |
| 236 | i.Close() |
| 237 | } |
| 238 | }() |
| 239 | cfg := i.Config() |
| 240 | request := &tasks.CreateTaskRequest{ |
| 241 | ContainerID: c.id, |
| 242 | Terminal: cfg.Terminal, |
| 243 | Stdin: cfg.Stdin, |
| 244 | Stdout: cfg.Stdout, |
| 245 | Stderr: cfg.Stderr, |
| 246 | } |
| 247 | if err := c.handleMounts(ctx, request); err != nil { |
| 248 | return nil, err |
| 249 | } |
| 250 | |
| 251 | r, err := c.get(ctx) |
| 252 | if err != nil { |
| 253 | return nil, err |
| 254 | } |
| 255 | info := TaskInfo{ |
| 256 | runtime: r.Runtime.Name, |
| 257 | runtimeOptions: r.Runtime.Options, |
| 258 | } |
| 259 | for _, o := range opts { |
| 260 | if err := o(ctx, c.client, &info); err != nil { |
| 261 | return nil, err |
| 262 | } |
| 263 | } |
| 264 | for _, m := range info.RootFS { |
| 265 | request.Rootfs = append(request.Rootfs, &types.Mount{ |
| 266 | Type: m.Type, |
| 267 | Source: m.Source, |
| 268 | Target: m.Target, |
| 269 | Options: m.Options, |
| 270 | }) |
| 271 | } |
| 272 | request.RuntimePath = info.RuntimePath |
| 273 | request.TaskApiAddress = info.taskAPIAddress |
| 274 | request.TaskApiVersion = info.taskAPIVersion |
| 275 | if info.Options != nil { |
| 276 | o, err := typeurl.MarshalAny(info.Options) |
| 277 | if err != nil { |
| 278 | return nil, err |
| 279 | } |
| 280 | request.Options = typeurl.MarshalProto(o) |
| 281 | } |
| 282 | t := &task{ |
| 283 | client: c.client, |
nothing calls this directly
no test coverage detected