Skip to content

Commit

Permalink
#4 forward podman log to nomad logger
Browse files Browse the repository at this point in the history
  • Loading branch information
towe75 committed Nov 19, 2019
1 parent 7d49404 commit 12b8a38
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ For now you can:

* use the jobs driver config to define the image for your container
* start/stop containers with default or customer entrypoint and arguments
* use nomad alloc data in the container. It's bind mounted to /nomad
* bind mount custome volumes into the container
* [Nomad runtime environment](https://www.nomadproject.io/docs/runtime/environment.html) is populated
* use nomad alloc data in the container.
* bind mount custom volumes into the container
* monitor the memory consuption
* monitor CPU usage (might be buggy)
* container memory is limited to configured value
* task config cpu value is used to populate podman CpuShares
* podman log is forwarded to [Nomad logger](https://www.nomadproject.io/docs/commands/alloc/logs.html)

### Driver Configuration

Expand Down
6 changes: 5 additions & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
containerName := BuildContainerName(cfg)
memoryLimit := fmt.Sprintf("%dm", cfg.Resources.NomadResources.Memory.MemoryMB)
cpuShares := cfg.Resources.LinuxResources.CPUShares
logOpts := []string{
fmt.Sprintf("path=%s",cfg.StdoutPath),
}

allEnv := cfg.EnvList()

Expand Down Expand Up @@ -342,6 +345,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
Memory: &memoryLimit,
MemorySwap: &memoryLimit,
CpuShares: &cpuShares,
LogOpt: &logOpts,
}

containerID, err := iopodman.CreateContainer().Call(d.ctx, varlinkConnection, createOpts)
Expand Down Expand Up @@ -526,7 +530,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
}

func (d *Driver) TaskStats(ctx context.Context, taskID string, interval time.Duration) (<-chan *drivers.TaskResourceUsage, error) {
d.logger.Error("TaskStats called")
d.logger.Debug("TaskStats called")
handle, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound
Expand Down
52 changes: 51 additions & 1 deletion driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestDockerDriver_Start_Wait_AllocDir(t *testing.T) {
taskCfg := newTaskConfig("", []string{
"sh",
"-c",
fmt.Sprintf(`sleep 1; echo -n %s > $%s/%s`,
fmt.Sprintf(`echo -n %s > $%s/%s; sleep 1`,
string(exp), taskenv.AllocDir, file),
})
task := &drivers.TaskConfig{
Expand Down Expand Up @@ -402,6 +402,56 @@ func TestPodmanDriver_GC_Container_off(t *testing.T) {
iopodman.RemoveContainer().Call(ctx, varlinkConnection, containerName, true ,true)
}

// Check stdout/stderr logging
func TestPodmanDriver_Stdout(t *testing.T) {
if !tu.IsCI() {
t.Parallel()
}

check := uuid.Generate()

taskCfg := newTaskConfig("", []string{
"sh",
"-c",
"echo "+check,
})
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "stdout",
AllocID: uuid.Generate(),
Resources: basicResources,
}
require.NoError(t, task.EncodeConcreteDriverConfig(&taskCfg))

d := podmanDriverHarness(t, nil)
cleanup := d.MkAllocDir(task, true)
defer cleanup()

_, _, err := d.StartTask(task)
require.NoError(t, err)

defer d.DestroyTask(task.ID, true)


logfile := filepath.Join(filepath.Dir(task.StdoutPath),fmt.Sprintf("%s.stdout.0",task.Name))
t.Logf("LOG PATH %s", logfile)
// Get the stdout of the process and assert that it's not empty
stdout, err := ioutil.ReadFile(logfile)
require.NoError(t, err)
require.Contains(t,string(stdout), check)

// Attempt to wait
waitCh, err := d.WaitTask(context.Background(), task.ID)
require.NoError(t, err)

select {
case <-waitCh:
t.Fatalf("wait channel should not have received an exit result")
case <-time.After(time.Duration(tu.TestMultiplier()*1) * time.Second):
}

}

func newTaskConfig(variant string, command []string) TaskConfig {
// busyboxImageID is the ID stored in busybox.tar
busyboxImageID := "docker://busybox"
Expand Down

0 comments on commit 12b8a38

Please sign in to comment.