Skip to content

Commit

Permalink
Include parent job ID as a Docker container label (#17843)
Browse files Browse the repository at this point in the history
Fixes: #17751
  • Loading branch information
devashishTaneja authored Jul 10, 2023
1 parent 34105f1 commit b31e891
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 234 deletions.
3 changes: 3 additions & 0 deletions .changelog/17843.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
docker: Added option for labeling container with parent job ID of periodic/dispatch jobs
```
1 change: 1 addition & 0 deletions client/allocrunner/taskrunner/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ func (tr *TaskRunner) buildTaskConfig() *drivers.TaskConfig {
Namespace: alloc.Namespace,
NodeName: alloc.NodeName,
NodeID: alloc.NodeID,
ParentJobID: alloc.Job.ParentID,
Resources: &drivers.Resources{
NomadResources: taskResources,
LinuxResources: &drivers.LinuxResources{
Expand Down
4 changes: 4 additions & 0 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
dockerLabelNamespace = "com.hashicorp.nomad.namespace"
dockerLabelNodeName = "com.hashicorp.nomad.node_name"
dockerLabelNodeID = "com.hashicorp.nomad.node_id"
dockerLabelParentJobID = "com.hashicorp.nomad.parent_job_id"
)

type pauseContainerStore struct {
Expand Down Expand Up @@ -1324,6 +1325,9 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
if glob.Glob(configurationExtraLabel, "job_id") {
labels[dockerLabelJobID] = task.JobID
}
if glob.Glob(configurationExtraLabel, "parent_job_id") && len(task.ParentJobID) > 0 {
labels[dockerLabelParentJobID] = task.ParentJobID
}
if glob.Glob(configurationExtraLabel, "task_group_name") {
labels[dockerLabelTaskGroupName] = task.TaskGroupName
}
Expand Down
1 change: 1 addition & 0 deletions plugins/drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ type TaskConfig struct {
JobName string
JobID string
TaskGroupName string
ParentJobID string
Name string // task.Name
Namespace string
NodeName string
Expand Down
Loading

0 comments on commit b31e891

Please sign in to comment.