Deployment adds JobSpecModifyIndex

Deployment tracks the Job.JobModifyIndex so that PUTS against /v1/jobs
can be more easily coorelated with the created deployment.

Fixes https://github.com/hashicorp/nomad/issues/4301
This commit is contained in:
Alex Dadgar 2018-05-30 11:33:56 -07:00
parent e96a4af694
commit 195e19827b
2 changed files with 53 additions and 20 deletions

View File

@ -125,17 +125,44 @@ func (d *Deployments) SetAllocHealth(deploymentID string, healthy, unhealthy []s
// Deployment is used to serialize an deployment.
type Deployment struct {
ID string
Namespace string
JobID string
JobVersion uint64
JobModifyIndex uint64
JobCreateIndex uint64
TaskGroups map[string]*DeploymentState
Status string
// ID is a generated UUID for the deployment
ID string
// Namespace is the namespace the deployment is created in
Namespace string
// JobID is the job the deployment is created for
JobID string
// JobVersion is the version of the job at which the deployment is tracking
JobVersion uint64
// JobModifyIndex is the modify index of the job at which the deployment is
// tracking. This is the ModifyIndex field on the job.
JobModifyIndex uint64
// JobSpecModifyIndex is the modify index of the job spec at which the
// deployment is tracking. This is the JobModifyIndex field on the job.
JobSpecModifyIndex uint64
// JobCreateIndex is the create index of the job which the deployment is
// tracking. It is needed so that if the job gets stopped and reran we can
// present the correct list of deployments for the job and not old ones.
JobCreateIndex uint64
// TaskGroups is the set of task groups effected by the deployment and their
// current deployment status.
TaskGroups map[string]*DeploymentState
// The status of the deployment
Status string
// StatusDescription allows a human readable description of the deployment
// status.
StatusDescription string
CreateIndex uint64
ModifyIndex uint64
CreateIndex uint64
ModifyIndex uint64
}
// DeploymentState tracks the state of a deployment for a given task group.

View File

@ -5425,9 +5425,14 @@ type Deployment struct {
// JobVersion is the version of the job at which the deployment is tracking
JobVersion uint64
// JobModifyIndex is the modify index of the job at which the deployment is tracking
// JobModifyIndex is the modify index of the job at which the deployment is
// tracking. This is the ModifyIndex field on the job.
JobModifyIndex uint64
// JobSpecModifyIndex is the modify index of the job spec at which the
// deployment is tracking. This is the JobModifyIndex field on the job.
JobSpecModifyIndex uint64
// JobCreateIndex is the create index of the job which the deployment is
// tracking. It is needed so that if the job gets stopped and reran we can
// present the correct list of deployments for the job and not old ones.
@ -5451,15 +5456,16 @@ type Deployment struct {
// NewDeployment creates a new deployment given the job.
func NewDeployment(job *Job) *Deployment {
return &Deployment{
ID: uuid.Generate(),
Namespace: job.Namespace,
JobID: job.ID,
JobVersion: job.Version,
JobModifyIndex: job.ModifyIndex,
JobCreateIndex: job.CreateIndex,
Status: DeploymentStatusRunning,
StatusDescription: DeploymentStatusDescriptionRunning,
TaskGroups: make(map[string]*DeploymentState, len(job.TaskGroups)),
ID: uuid.Generate(),
Namespace: job.Namespace,
JobID: job.ID,
JobVersion: job.Version,
JobModifyIndex: job.ModifyIndex,
JobSpecModifyIndex: job.JobModifyIndex,
JobCreateIndex: job.CreateIndex,
Status: DeploymentStatusRunning,
StatusDescription: DeploymentStatusDescriptionRunning,
TaskGroups: make(map[string]*DeploymentState, len(job.TaskGroups)),
}
}