Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement nomad exec for rkt #5690

Merged
merged 2 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion command/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *NodeConfigCommand) Run(args []string) int {
if updateServers {
// Get the server addresses
if len(args) == 0 {
c.Ui.Error("If the '-update-servers' flag is set, atleast one server argument must be provided")
c.Ui.Error("If the '-update-servers' flag is set, at least one server argument must be provided")
c.Ui.Error(commandErrorText(c))
return 1
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/exec/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (d *Driver) SignalTask(taskID string, signal string) error {

func (d *Driver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*drivers.ExecTaskResult, error) {
if len(cmd) == 0 {
return nil, fmt.Errorf("error cmd must have atleast one value")
return nil, fmt.Errorf("error cmd must have at least one value")
}
handle, ok := d.tasks.Get(taskID)
if !ok {
Expand Down Expand Up @@ -540,7 +540,7 @@ func (d *Driver) ExecTaskStreamingRaw(ctx context.Context,
stream drivers.ExecTaskStream) error {

if len(command) == 0 {
return fmt.Errorf("error cmd must have atleast one value")
return fmt.Errorf("error cmd must have at least one value")
}
handle, ok := d.tasks.Get(taskID)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion drivers/java/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func (d *Driver) ExecTaskStreamingRaw(ctx context.Context,
stream drivers.ExecTaskStream) error {

if len(command) == 0 {
return fmt.Errorf("error cmd must have atleast one value")
return fmt.Errorf("error cmd must have at least one value")
}
handle, ok := d.tasks.Get(taskID)
if !ok {
Expand Down
24 changes: 23 additions & 1 deletion drivers/rkt/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ func (d *Driver) SignalTask(taskID string, signal string) error {

func (d *Driver) ExecTask(taskID string, cmdArgs []string, timeout time.Duration) (*drivers.ExecTaskResult, error) {
if len(cmdArgs) == 0 {
return nil, fmt.Errorf("error cmd must have atleast one value")
return nil, fmt.Errorf("error cmd must have at least one value")
}
handle, ok := d.tasks.Get(taskID)
if !ok {
Expand Down Expand Up @@ -891,6 +891,28 @@ func (d *Driver) ExecTask(taskID string, cmdArgs []string, timeout time.Duration

}

var _ drivers.ExecTaskStreamingRawDriver = (*Driver)(nil)

func (d *Driver) ExecTaskStreamingRaw(ctx context.Context,
taskID string,
command []string,
tty bool,
stream drivers.ExecTaskStream) error {

if len(command) == 0 {
return fmt.Errorf("error cmd must have at least one value")
}
handle, ok := d.tasks.Get(taskID)
if !ok {
return drivers.ErrTaskNotFound
}

enterCmd := []string{rktCmd, "enter", handle.uuid, handle.env.ReplaceEnv(command[0])}
enterCmd = append(enterCmd, handle.env.ParseAndReplace(command[1:])...)

return handle.exec.ExecStreaming(ctx, enterCmd, tty, stream)
}

// GetAbsolutePath returns the absolute path of the passed binary by resolving
// it in the path and following symlinks.
func GetAbsolutePath(bin string) (string, error) {
Expand Down
64 changes: 64 additions & 0 deletions drivers/rkt/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,67 @@ config {

require.EqualValues(t, expected, tc)
}

func TestRkt_ExecTaskStreaming(t *testing.T) {
ctestutil.RktCompatible(t)
if !testutil.IsCI() {
t.Parallel()
}

require := require.New(t)
d := NewRktDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)

task := &drivers.TaskConfig{
ID: uuid.Generate(),
AllocID: uuid.Generate(),
Name: "etcd",
Resources: &drivers.Resources{
NomadResources: &structs.AllocatedTaskResources{
Memory: structs.AllocatedMemoryResources{
MemoryMB: 128,
},
Cpu: structs.AllocatedCpuResources{
CpuShares: 100,
},
},
LinuxResources: &drivers.LinuxResources{
MemoryLimitBytes: 134217728,
CPUShares: 100,
},
},
}

tc := &TaskConfig{
ImageName: "docker://busybox:1.29.3",
Command: "/bin/sleep",
Args: []string{"1000"},
Net: []string{"none"},
}
require.NoError(task.EncodeConcreteDriverConfig(&tc))
testtask.SetTaskConfigEnv(task)

cleanup := harness.MkAllocDir(task, true)
defer cleanup()

_, _, err := harness.StartTask(task)
require.NoError(err)
defer d.DestroyTask(task.ID, true)

// wait for container to be up and executable
testutil.WaitForResult(func() (bool, error) {
res, err := d.ExecTask(task.ID, []string{"/bin/sh", "-c", "echo hi"}, time.Second)
if err != nil {
return false, fmt.Errorf("failed to exec: %#v", err)
}
if !res.ExitResult.Successful() {
return false, fmt.Errorf("ps failed: %#v %#v", res.ExitResult, res)
}
return true, nil
}, func(err error) {
require.NoError(err)
})

dtestutil.ExecTaskStreamingConformanceTests(t, harness, task.ID)

}