Skip to content

Commit 83af9c1

Browse files
Merge pull request #32 from Roblox/logging
Add support for $(nomad alloc logs) command.
2 parents 3c0fc2a + 616abe3 commit 83af9c1

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,11 @@ Ubuntu (>= 16.04)
138138
`nomad-driver-containerd` [`v0.1`](https://github.com/Roblox/nomad-driver-containerd/releases/tag/v0.1) is **not** production ready.
139139
There are some open items which are currently being worked on.
140140

141-
1) **Logging**: Logging is currently not supported i.e `nomad alloc logs` command won't work out-of-the-box for containers launched using `nomad-driver-containerd`. As a workaround, one can use `containerd` command line tool `ctr` to attach to container `stdout/stderr`. Both the issue and workaround is documented [`here`](https://github.com/Roblox/nomad-driver-containerd/issues/30)
141+
1) **Networking**: Networking is **not in scope** of containerd as described [`here`](https://kubernetes.io/blog/2017/11/containerd-container-runtime-options-kubernetes/). However an external CNI plugin can be used to add networking to the container. We are researching on how to enable networking for our internal use-cases, and would publish (open-source) that work at some point.
142142

143-
2) **Networking**: Networking is **not in scope** of containerd as described [`here`](https://kubernetes.io/blog/2017/11/containerd-container-runtime-options-kubernetes/). However an external CNI plugin can be used to add networking to the container. We are researching on how to enable networking for our internal use-cases, and would publish (open-source) that work at some point.
143+
2) **Port forwarding**: The ability to map a host port to a container port. This is currently not supported, but could be supported in future.
144144

145-
3) **Port forwarding**: The ability to map a host port to a container port. This is currently not supported, but could be supported in future.
146-
147-
4) **Consul connect**: When a user launches a job in `nomad`, s/he can add a [`service stanza`](https://www.nomadproject.io/docs/job-specification/service) which will instruct `nomad` to register the service with `consul` for service discovery. This is currently not supported.
145+
3) **Consul connect**: When a user launches a job in `nomad`, s/he can add a [`service stanza`](https://www.nomadproject.io/docs/job-specification/service) which will instruct `nomad` to register the service with `consul` for service discovery. This is currently not supported.
148146

149147
## License
150148

containerd/containerd.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package containerd
1919

2020
import (
2121
"fmt"
22+
"os"
23+
"syscall"
2224

2325
"github.com/containerd/containerd"
2426
"github.com/containerd/containerd/cio"
@@ -120,8 +122,24 @@ func (d *Driver) loadContainer(id string) (containerd.Container, error) {
120122
return d.client.LoadContainer(d.ctxContainerd, id)
121123
}
122124

123-
func (d *Driver) createTask(container containerd.Container) (containerd.Task, error) {
124-
return container.NewTask(d.ctxContainerd, cio.NewCreator(cio.WithStdio))
125+
func (d *Driver) createTask(container containerd.Container, stdoutPath, stderrPath string) (containerd.Task, error) {
126+
stdout, err := openFIFO(stdoutPath)
127+
if err != nil {
128+
return nil, err
129+
}
130+
131+
stderr, err := openFIFO(stderrPath)
132+
if err != nil {
133+
return nil, err
134+
}
135+
136+
return container.NewTask(d.ctxContainerd, cio.NewCreator(cio.WithStreams(nil, stdout, stderr)))
137+
}
138+
139+
// FIFO's are named pipes in linux.
140+
// openFIFO() opens the nomad task stdout/stderr pipes and returns the fd.
141+
func openFIFO(path string) (*os.File, error) {
142+
return os.OpenFile(path, os.O_RDWR|syscall.O_NONBLOCK, 0600)
125143
}
126144

127145
func (d *Driver) getTask(container containerd.Container) (containerd.Task, error) {

containerd/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
359359

360360
d.logger.Info(fmt.Sprintf("Successfully created container with name: %s", containerName))
361361

362-
task, err := d.createTask(container)
362+
task, err := d.createTask(container, cfg.StdoutPath, cfg.StderrPath)
363363
if err != nil {
364364
return nil, nil, fmt.Errorf("Error in creating task: %v", err)
365365
}

0 commit comments

Comments
 (0)