Skip to content

Commit

Permalink
Merge pull request #42 from tripiq/canary-restriction
Browse files Browse the repository at this point in the history
command/deploy: more robust canary promote check
  • Loading branch information
jrasell committed Nov 23, 2017
2 parents 2690f0c + b1511b3 commit 754d2a6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func (c *DeployCommand) Run(args []string) int {
c.UI.Error(fmt.Sprintf("[ERROR] levant/command: %v", err))
return 1
}

c.UI.Info(fmt.Sprintf("[INFO] levant/command: running canary-auto-update of %vs", canary))
}

client, err := levant.NewNomadClient(addr)
Expand All @@ -116,12 +118,19 @@ func (c *DeployCommand) Run(args []string) int {
}

func (c *DeployCommand) checkCanaryAutoPromote(job *nomad.Job, canaryAutoPromote int) error {
if canaryAutoPromote == 0 {
return nil
}

if canaryAutoPromote > 0 && *job.Update.Canary == 0 {
return fmt.Errorf("canary-auto-update of %v passed but job is not canary enabled", canaryAutoPromote)
if job.Update != nil && job.Update.Canary != nil && *job.Update.Canary > 0 {
return nil
}

c.UI.Info(fmt.Sprintf("[INFO] levant/command: running canary-auto-update of %vs", canaryAutoPromote))
for _, group := range job.TaskGroups {
if group.Update != nil && group.Update.Canary != nil && *group.Update.Canary > 0 {
return nil
}
}

return nil
return fmt.Errorf("canary-auto-update of %v passed but job is not canary enabled", canaryAutoPromote)
}

0 comments on commit 754d2a6

Please sign in to comment.