Skip to content

Commit

Permalink
Task-level actions for job submissions and retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Oct 2, 2023
1 parent 7267be7 commit 9952078
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ type Task struct {

// Workload Identities
Identities []*WorkloadIdentity `hcl:"identity,block"`

Actions []*Action `hcl:"action,block"`
}

func (t *Task) Canonicalize(tg *TaskGroup, job *Job) {
Expand Down Expand Up @@ -1167,3 +1169,10 @@ type WorkloadIdentity struct {
ServiceName string `hcl:"service_name,optional"`
TTL time.Duration `mapstructure:"ttl" hcl:"ttl,optional"`
}

type Action struct {
Name string `hcl:"name,label"`
Command *string `mapstructure:"command" hcl:"command"`
Args []string `mapstructure:"args" hcl:"args,optional"`
// Type *string `mapstructure:"type" hcl:"type,optional"`
}
16 changes: 16 additions & 0 deletions command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,15 @@ func ApiTaskToStructsTask(job *structs.Job, group *structs.TaskGroup,
Sidecar: apiTask.Lifecycle.Sidecar,
}
}

if apiTask.Actions != nil {
structsTask.Actions = []*structs.Action{}
for _, action := range apiTask.Actions {
act := &structs.Action{}
ApiActionToStructsAction(job, action, act)
structsTask.Actions = append(structsTask.Actions, act)
}
}
}

// apiWaitConfigToStructsWaitConfig is a copy and type conversion between the API
Expand Down Expand Up @@ -1385,6 +1394,13 @@ func ApiCSIPluginConfigToStructsCSIPluginConfig(apiConfig *api.TaskCSIPluginConf
return sc
}

func ApiActionToStructsAction(job *structs.Job, action *api.Action, act *structs.Action) {
act.Name = action.Name
act.Args = action.Args
act.Command = action.Command
// act.Type = action.Type
}

func ApiResourcesToStructs(in *api.Resources) *structs.Resources {
if in == nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions jobspec/parse_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
"kind",
"volume_mount",
"csi_plugin",
"actions",
)

sidecarTaskKeys = append(commonTaskKeys,
Expand Down
10 changes: 10 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7620,6 +7620,9 @@ type Task struct {
// Identities are the alternate workload identities for use with 3rd party
// endpoints.
Identities []*WorkloadIdentity

// Alloc-exec-like runnable commands
Actions []*Action
}

func (t *Task) UsesCores() bool {
Expand Down Expand Up @@ -13282,3 +13285,10 @@ func NewRpcError(err error, code *int64) *RpcError {
func (r *RpcError) Error() string {
return r.Message
}

type Action struct {
Name string
Command *string
Args []string
// Type *string
}

0 comments on commit 9952078

Please sign in to comment.