Add support for {nomad alloc logs} command.

This commit is contained in:
Shishir Mahajan 2020-08-20 17:38:33 -07:00
parent 3c0fc2a598
commit c699faf654
No known key found for this signature in database
GPG Key ID: D41782E7688DEC4A
2 changed files with 21 additions and 3 deletions

View File

@ -19,6 +19,8 @@ package containerd
import (
"fmt"
"os"
"syscall"
"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
@ -120,8 +122,24 @@ func (d *Driver) loadContainer(id string) (containerd.Container, error) {
return d.client.LoadContainer(d.ctxContainerd, id)
}
func (d *Driver) createTask(container containerd.Container) (containerd.Task, error) {
return container.NewTask(d.ctxContainerd, cio.NewCreator(cio.WithStdio))
func (d *Driver) createTask(container containerd.Container, stdoutPath, stderrPath string) (containerd.Task, error) {
stdout, err := openFIFO(stdoutPath)
if err != nil {
return nil, err
}
stderr, err := openFIFO(stderrPath)
if err != nil {
return nil, err
}
return container.NewTask(d.ctxContainerd, cio.NewCreator(cio.WithStreams(nil, stdout, stderr)))
}
// FIFO's are named pipes in linux.
// openFIFO() opens the nomad task stdout/stderr pipes and returns the fd.
func openFIFO(path string) (*os.File, error) {
return os.OpenFile(path, os.O_RDWR|syscall.O_NONBLOCK, 0600)
}
func (d *Driver) getTask(container containerd.Container) (containerd.Task, error) {

View File

@ -359,7 +359,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
d.logger.Info(fmt.Sprintf("Successfully created container with name: %s", containerName))
task, err := d.createTask(container)
task, err := d.createTask(container, cfg.StdoutPath, cfg.StderrPath)
if err != nil {
return nil, nil, fmt.Errorf("Error in creating task: %v", err)
}