Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce -force-count into Deploy #33

Merged
merged 1 commit into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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