Exec will find the right running container to run a new command.
(ctx context.Context, client *containerd.Client, args []string, options types.ContainerExecOptions)
| 41 | |
| 42 | // Exec will find the right running container to run a new command. |
| 43 | func Exec(ctx context.Context, client *containerd.Client, args []string, options types.ContainerExecOptions) error { |
| 44 | walker := &containerwalker.ContainerWalker{ |
| 45 | Client: client, |
| 46 | OnFound: func(ctx context.Context, found containerwalker.Found) error { |
| 47 | if found.MatchCount > 1 { |
| 48 | return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req) |
| 49 | } |
| 50 | return execActionWithContainer(ctx, client, found.Container, args, options) |
| 51 | }, |
| 52 | } |
| 53 | req := args[0] |
| 54 | n, err := walker.Walk(ctx, req) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } else if n == 0 { |
| 58 | return fmt.Errorf("no such container %s", req) |
| 59 | } |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | func execActionWithContainer(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions) error { |
| 64 | pspec, err := generateExecProcessSpec(ctx, client, container, args, options) |
no test coverage detected
searching dependent graphs…