-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add support for initial check status #1599
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
job "foo" { | ||
|
||
group "group" { | ||
count = 1 | ||
|
||
task "task" { | ||
|
||
service { | ||
tags = ["foo", "bar"] | ||
|
||
check { | ||
name = "check-name" | ||
type = "http" | ||
interval = "10s" | ||
timeout = "2s" | ||
initial_status = "passing" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"time" | ||
|
||
"github.com/gorhill/cronexpr" | ||
"github.com/hashicorp/consul/api" | ||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/go-version" | ||
"github.com/hashicorp/nomad/helper/args" | ||
|
@@ -1591,15 +1592,16 @@ const ( | |
// The ServiceCheck data model represents the consul health check that | ||
// Nomad registers for a Task | ||
type ServiceCheck struct { | ||
Name string // Name of the check, defaults to id | ||
Type string // Type of the check - tcp, http, docker and script | ||
Command string // Command is the command to run for script checks | ||
Args []string // Args is a list of argumes for script checks | ||
Path string // path of the health check url for http type check | ||
Protocol string // Protocol to use if check is http, defaults to http | ||
PortLabel string `mapstructure:"port"` // The port to use for tcp/http checks | ||
Interval time.Duration // Interval of the check | ||
Timeout time.Duration // Timeout of the response from the check before consul fails the check | ||
Name string // Name of the check, defaults to id | ||
Type string // Type of the check - tcp, http, docker and script | ||
Command string // Command is the command to run for script checks | ||
Args []string // Args is a list of argumes for script checks | ||
Path string // path of the health check url for http type check | ||
Protocol string // Protocol to use if check is http, defaults to http | ||
PortLabel string `mapstructure:"port"` // The port to use for tcp/http checks | ||
Interval time.Duration // Interval of the check | ||
Timeout time.Duration // Timeout of the response from the check before consul fails the check | ||
InitialStatus string // Initial status of the check | ||
} | ||
|
||
func (sc *ServiceCheck) Copy() *ServiceCheck { | ||
|
@@ -1653,6 +1655,17 @@ func (sc *ServiceCheck) validate() error { | |
return fmt.Errorf("interval (%v) can not be lower than %v", sc.Interval, minCheckInterval) | ||
} | ||
|
||
switch sc.InitialStatus { | ||
case "": | ||
case api.HealthUnknown: | ||
case api.HealthPassing: | ||
case api.HealthWarning: | ||
case api.HealthCritical: | ||
default: | ||
return fmt.Errorf(`invalid initial check state (%s), must be one of "%s", "%s", "%s", or "%s"`, sc.InitialStatus, api.HealthUnknown, api.HealthPassing, api.HealthWarning, api.HealthCritical) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also check that parsing the file resulted in the check that we are expecting by using
reflect.DeepEquals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay! it turns out it was actually broken without the mapstructure tag :x