Skip to content

Commit

Permalink
Made the code more DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu authored and dadgar committed Nov 16, 2015
1 parent 041f48d commit c01f2a3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
9 changes: 4 additions & 5 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, dri
return c, fmt.Errorf("Unable to parse docker.privileged.enabled: %s", err)
}

if taskPrivileged := driverConfig.Privileged; taskPrivileged {
if taskPrivileged && !hostPrivileged {
if driverConfig.Privileged {
if !hostPrivileged {
return c, fmt.Errorf(`Unable to set privileged flag since "docker.privileged.enabled" is false`)
}

hostConfig.Privileged = taskPrivileged
hostConfig.Privileged = driverConfig.Privileged
}

// set DNS servers
Expand Down Expand Up @@ -303,8 +303,7 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, dri
config.ExposedPorts = exposedPorts
}

rawArgs := driverConfig.Args
parsedArgs, err := args.ParseAndReplace(rawArgs, env.Map())
parsedArgs, err := args.ParseAndReplace(driverConfig.Args, env.Map())
if err != nil {
return c, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/driver/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,

// Look for arguments
var args []string
if argRaw := driverConfig.Args; argRaw != "" {
args = append(args, argRaw)
if driverConfig.Args != "" {
args = append(args, driverConfig.Args)
}

// Setup the command
Expand Down
2 changes: 1 addition & 1 deletion client/driver/executor/test_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
MBits: 50,
DynamicPorts: []structs.Port{structs.Port{Label: "http"}},
DynamicPorts: []structs.Port{{Label: "http"}},
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions client/driver/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,

// Build the argument list.
args = append(args, "-jar", filepath.Join(allocdir.TaskLocal, jarName))
if argRaw := driverConfig.Args; argRaw != "" {
args = append(args, argRaw)
if driverConfig.Args != "" {
args = append(args, driverConfig.Args)
}

// Setup the command
Expand Down
4 changes: 2 additions & 2 deletions client/driver/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
// Parse configuration arguments
// Create the base arguments
accelerator := "tcg"
if acc := driverConfig.Accelerator; acc != "" {
accelerator = acc
if driverConfig.Accelerator != "" {
accelerator = driverConfig.Accelerator
}
// TODO: Check a lower bounds, e.g. the default 128 of Qemu
mem := fmt.Sprintf("%dM", task.Resources.MemoryMB)
Expand Down
4 changes: 2 additions & 2 deletions client/driver/raw_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (d *RawExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandl

// Look for arguments
var args []string
if argRaw := driverConfig.Args; argRaw != "" {
args = append(args, argRaw)
if driverConfig.Args != "" {
args = append(args, driverConfig.Args)
}

// Setup the command
Expand Down
4 changes: 2 additions & 2 deletions client/driver/rkt.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, e
}

// Add user passed arguments.
if userArgs := driverConfig.Args; userArgs != "" {
parsed, err := args.ParseAndReplace(userArgs, envVars.Map())
if driverConfig.Args != "" {
parsed, err := args.ParseAndReplace(driverConfig.Args, envVars.Map())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c01f2a3

Please sign in to comment.