Fix task group name
Previously when creating a job, Poseidon would still use the old task group name format instead of default-group as expected.
This commit is contained in:
@ -5,7 +5,7 @@ job "python" {
|
|||||||
type = "batch"
|
type = "batch"
|
||||||
namespace = "${NOMAD_NAMESPACE}"
|
namespace = "${NOMAD_NAMESPACE}"
|
||||||
|
|
||||||
group "python-group" {
|
group "default-group" {
|
||||||
ephemeral_disk {
|
ephemeral_disk {
|
||||||
migrate = false
|
migrate = false
|
||||||
size = 10
|
size = 10
|
||||||
|
@ -3,7 +3,6 @@ package environment
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
|
||||||
nomadApi "github.com/hashicorp/nomad/api"
|
nomadApi "github.com/hashicorp/nomad/api"
|
||||||
"github.com/hashicorp/nomad/jobspec2"
|
"github.com/hashicorp/nomad/jobspec2"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/nomad"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/nomad"
|
||||||
@ -12,8 +11,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultTaskDriver = "docker"
|
DefaultTaskDriver = "docker"
|
||||||
TaskNameFormat = "%s-task"
|
|
||||||
TaskName = "python-job-task"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// defaultJobHCL holds our default job in HCL format.
|
// defaultJobHCL holds our default job in HCL format.
|
||||||
@ -50,8 +47,8 @@ func createJob(
|
|||||||
job.ID = &id
|
job.ID = &id
|
||||||
job.Name = &id
|
job.Name = &id
|
||||||
|
|
||||||
var taskGroup = createTaskGroup(&job, fmt.Sprintf(nomad.TaskGroupNameFormat, id), prewarmingPoolSize)
|
var taskGroup = createTaskGroup(&job, nomad.TaskGroupName, prewarmingPoolSize)
|
||||||
configureTask(taskGroup, fmt.Sprintf(TaskNameFormat, id), cpuLimit, memoryLimit, image, networkAccess, exposedPorts)
|
configureTask(taskGroup, nomad.TaskName, cpuLimit, memoryLimit, image, networkAccess, exposedPorts)
|
||||||
|
|
||||||
return &job
|
return &job
|
||||||
}
|
}
|
||||||
|
@ -55,13 +55,13 @@ func createTestJob() (*nomadApi.Job, *nomadApi.Job) {
|
|||||||
base := nomadApi.NewBatchJob("python-job", "python-job", "region-name", 100)
|
base := nomadApi.NewBatchJob("python-job", "python-job", "region-name", 100)
|
||||||
job := nomadApi.NewBatchJob("python-job", "python-job", "region-name", 100)
|
job := nomadApi.NewBatchJob("python-job", "python-job", "region-name", 100)
|
||||||
task := createTestTask()
|
task := createTestTask()
|
||||||
task.Name = TaskName
|
task.Name = nomad.TaskName
|
||||||
image := "python:latest"
|
image := "python:latest"
|
||||||
task.Config = map[string]interface{}{"image": image}
|
task.Config = map[string]interface{}{"image": image}
|
||||||
task.Config["network_mode"] = "none"
|
task.Config["network_mode"] = "none"
|
||||||
task.Resources = createTestResources()
|
task.Resources = createTestResources()
|
||||||
taskGroup := createTestTaskGroup()
|
taskGroup := createTestTaskGroup()
|
||||||
taskGroupName := fmt.Sprintf(nomad.TaskGroupNameFormat, *job.ID)
|
taskGroupName := nomad.TaskGroupName
|
||||||
taskGroup.Name = &taskGroupName
|
taskGroup.Name = &taskGroupName
|
||||||
taskGroup.Tasks = []*nomadApi.Task{task}
|
taskGroup.Tasks = []*nomadApi.Task{task}
|
||||||
taskGroup.Networks = []*nomadApi.NetworkResource{}
|
taskGroup.Networks = []*nomadApi.NetworkResource{}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package nomad
|
package nomad
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
nomadApi "github.com/hashicorp/nomad/api"
|
nomadApi "github.com/hashicorp/nomad/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TaskGroupNameFormat = "%s-group"
|
TaskGroupName = "default-group"
|
||||||
TaskName = "default-task"
|
TaskName = "default-task"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoadJobList loads the list of jobs from the Nomad api.
|
// LoadJobList loads the list of jobs from the Nomad api.
|
||||||
@ -23,13 +22,13 @@ func (nc *nomadAPIClient) JobScale(jobID string) (jobScale uint, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// ToDo: Consider counting also the placed and desired allocations
|
// ToDo: Consider counting also the placed and desired allocations
|
||||||
jobScale = uint(status.TaskGroups[fmt.Sprintf(TaskGroupNameFormat, jobID)].Running)
|
jobScale = uint(status.TaskGroups[TaskGroupName].Running)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetJobScale sets the scaling count of the passed job to Nomad.
|
// SetJobScale sets the scaling count of the passed job to Nomad.
|
||||||
func (nc *nomadAPIClient) SetJobScale(jobID string, count uint, reason string) (err error) {
|
func (nc *nomadAPIClient) SetJobScale(jobID string, count uint, reason string) (err error) {
|
||||||
intCount := int(count)
|
intCount := int(count)
|
||||||
_, _, err = nc.client.Jobs().Scale(jobID, fmt.Sprintf(TaskGroupNameFormat, jobID), &intCount, reason, false, nil, nil)
|
_, _, err = nc.client.Jobs().Scale(jobID, TaskGroupName, &intCount, reason, false, nil, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user