From a216daedceec43f36b2309d2281c50d58246097b Mon Sep 17 00:00:00 2001 From: Danielle Lancashire Date: Thu, 25 Jul 2019 16:46:18 +0200 Subject: [PATCH] api: Allow submission of jobs with volumes --- command/agent/job_endpoint.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 2ff6e48bb..fd857a181 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -189,6 +189,7 @@ func (s *HTTPServer) ValidateJobRequest(resp http.ResponseWriter, req *http.Requ } job := ApiJobToStructJob(validateRequest.Job) + args := structs.JobValidateRequest{ Job: job, WriteRequest: structs.WriteRequest{ @@ -740,6 +741,29 @@ func ApiTgToStructsTG(taskGroup *api.TaskGroup, tg *structs.TaskGroup) { } } + if l := len(taskGroup.Volumes); l != 0 { + tg.Volumes = make(map[string]*structs.VolumeRequest, l) + for k, v := range taskGroup.Volumes { + if v.Type != structs.VolumeTypeHost { + // Ignore non-host volumes in this iteration currently. + continue + } + + vol := &structs.Volume{ + Name: v.Name, + Type: v.Type, + ReadOnly: v.ReadOnly, + Hidden: v.Hidden, + Config: v.Config, + } + + tg.Volumes[k] = &structs.VolumeRequest{ + Volume: vol, + Config: v.Config, + } + } + } + if taskGroup.Update != nil { tg.Update = &structs.UpdateStrategy{ Stagger: *taskGroup.Update.Stagger, @@ -788,6 +812,17 @@ func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task) { structsTask.Constraints = ApiConstraintsToStructs(apiTask.Constraints) structsTask.Affinities = ApiAffinitiesToStructs(apiTask.Affinities) + if l := len(apiTask.VolumeMounts); l != 0 { + structsTask.VolumeMounts = make([]*structs.VolumeMount, l) + for i, mount := range apiTask.VolumeMounts { + structsTask.VolumeMounts[i] = &structs.VolumeMount{ + Volume: mount.Volume, + Destination: mount.Destination, + ReadOnly: mount.ReadOnly, + } + } + } + if l := len(apiTask.Services); l != 0 { structsTask.Services = make([]*structs.Service, l) for i, service := range apiTask.Services {