Skip to content

Commit

Permalink
Merge pull request #33 from dropje86/force_count
Browse files Browse the repository at this point in the history
introduce -force-count into Deploy
  • Loading branch information
jrasell committed Nov 14, 2017
2 parents f013954 + 106acfa commit e8a46ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ General Options:
-var-file=<file>
Used in conjunction with the -job-file will deploy a templated job to your
Nomad cluster.
-force-count
Use the taskgroup count from the Nomad jobfile instead of the count that
is currently set in a running job.
`
return strings.TrimSpace(helpText)
}
Expand All @@ -57,6 +61,7 @@ func (c *DeployCommand) Run(args []string) int {
var err error
var job *nomad.Job
var canary int
var forceCount bool

flags := c.Meta.FlagSet("deploy", FlagSetVars)
flags.Usage = func() { c.UI.Output(c.Help()) }
Expand All @@ -65,6 +70,7 @@ func (c *DeployCommand) Run(args []string) int {
flags.IntVar(&canary, "canary-auto-promote", 0, "")
flags.StringVar(&log, "log-level", "INFO", "")
flags.StringVar(&variables, "var-file", "", "")
flags.BoolVar(&forceCount, "force-count", false, "")

if err = flags.Parse(args); err != nil {
return 1
Expand Down Expand Up @@ -98,7 +104,7 @@ func (c *DeployCommand) Run(args []string) int {
return 1
}

success := client.Deploy(job, canary)
success := client.Deploy(job, canary, forceCount)
if !success {
c.UI.Error(fmt.Sprintf("[ERROR] levant/command: deployment of job %s failed", *job.Name))
return 1
Expand Down
12 changes: 7 additions & 5 deletions levant/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type nomadClient struct {
type NomadClient interface {
// Deploy triggers a register of the job resulting in a Nomad deployment which
// is monitored to determine the eventual state.
Deploy(*nomad.Job, int) bool
Deploy(*nomad.Job, int, bool) bool
}

// NewNomadClient is used to create a new client to interact with Nomad.
Expand All @@ -39,17 +39,19 @@ func NewNomadClient(addr string) (NomadClient, error) {

// Deploy triggers a register of the job resulting in a Nomad deployment which
// is monitored to determine the eventual state.
func (c *nomadClient) Deploy(job *nomad.Job, autoPromote int) (success bool) {
func (c *nomadClient) Deploy(job *nomad.Job, autoPromote int, forceCount bool) (success bool) {

// Validate the job to check it is syntactically correct.
if _, _, err := c.nomad.Jobs().Validate(job, nil); err != nil {
logging.Error("levant/deploy: job validation failed: %v", err)
return
}

logging.Debug("levant/deploy: running dynamic job count updater for job %s", *job.Name)
if err := c.dynamicGroupCountUpdater(job); err != nil {
return
if !forceCount {
logging.Debug("levant/deploy: running dynamic job count updater for job %s", *job.Name)
if err := c.dynamicGroupCountUpdater(job); err != nil {
return
}
}

logging.Info("levant/deploy: triggering a deployment of job %s", *job.Name)
Expand Down

0 comments on commit e8a46ee

Please sign in to comment.