mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
plugin/driver: add Copy funcs
This commit is contained in:
committed by
Michael Schurter
parent
d68f2f0819
commit
b016b2b5b0
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/helper"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/plugins/base"
|
||||
"github.com/hashicorp/nomad/plugins/shared/hclspec"
|
||||
@@ -110,6 +111,17 @@ type TaskConfig struct {
|
||||
StderrPath string
|
||||
}
|
||||
|
||||
func (tc *TaskConfig) Copy() *TaskConfig {
|
||||
if tc == nil {
|
||||
return nil
|
||||
}
|
||||
c := new(TaskConfig)
|
||||
*c = *tc
|
||||
c.Env = helper.CopyMapStringString(c.Env)
|
||||
c.Resources = tc.Resources.Copy()
|
||||
return c
|
||||
}
|
||||
|
||||
func (tc *TaskConfig) EnvList() []string {
|
||||
l := make([]string, 0, len(tc.Env))
|
||||
for k, v := range tc.Env {
|
||||
@@ -161,6 +173,20 @@ type Resources struct {
|
||||
LinuxResources *LinuxResources
|
||||
}
|
||||
|
||||
func (r *Resources) Copy() *Resources {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
res := new(Resources)
|
||||
if r.NomadResources != nil {
|
||||
res.NomadResources = r.NomadResources.Copy()
|
||||
}
|
||||
if r.LinuxResources != nil {
|
||||
res.LinuxResources = r.LinuxResources.Copy()
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
type LinuxResources struct {
|
||||
CPUPeriod int64
|
||||
CPUQuota int64
|
||||
@@ -171,6 +197,12 @@ type LinuxResources struct {
|
||||
CpusetMems string
|
||||
}
|
||||
|
||||
func (r *LinuxResources) Copy() *LinuxResources {
|
||||
res := new(LinuxResources)
|
||||
*res = *r
|
||||
return res
|
||||
}
|
||||
|
||||
type DeviceConfig struct {
|
||||
TaskPath string
|
||||
HostPath string
|
||||
|
||||
@@ -27,3 +27,10 @@ func (h *TaskHandle) GetDriverState(v interface{}) error {
|
||||
return base.MsgPackDecode(h.driverState, v)
|
||||
|
||||
}
|
||||
|
||||
func (h *TaskHandle) Copy() *TaskHandle {
|
||||
handle := new(TaskHandle)
|
||||
*handle = *h
|
||||
handle.Config = h.Config.Copy()
|
||||
return handle
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
"github.com/hashicorp/nomad/client/driver/env"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/plugins/drivers/proto"
|
||||
@@ -47,19 +45,6 @@ func healthStateFromProto(pb proto.FingerprintResponse_HealthState) HealthState
|
||||
return HealthStateUndetected
|
||||
}
|
||||
|
||||
// NewTaskConfig builds a TaskConfig from a Task struct
|
||||
func NewTaskConfig(task *structs.Task, taskDir *allocdir.TaskDir, env *env.TaskEnv) *TaskConfig {
|
||||
return &TaskConfig{
|
||||
Name: task.Name,
|
||||
Resources: &Resources{
|
||||
NomadResources: task.Resources,
|
||||
},
|
||||
Env: env.Map(),
|
||||
User: task.User,
|
||||
AllocDir: taskDir.AllocDir,
|
||||
}
|
||||
}
|
||||
|
||||
func taskConfigFromProto(pb *proto.TaskConfig) *TaskConfig {
|
||||
if pb == nil {
|
||||
return &TaskConfig{}
|
||||
|
||||
Reference in New Issue
Block a user