helper/resource: allow configuration of not found checks in state change

This commit is contained in:
Jack Pearkes 2015-02-26 09:59:42 -08:00
parent b7459cbc64
commit c180487af6
1 changed files with 13 additions and 7 deletions

View File

@ -28,6 +28,7 @@ type StateChangeConf struct {
Target string // Target state
Timeout time.Duration // The amount of time to wait before timeout
MinTimeout time.Duration // Smallest time to wait before refreshes
NotFoundChecks int // Number of times to allow not found
}
// WaitForState watches an object and waits for it to achieve the state
@ -38,6 +39,11 @@ func (conf *StateChangeConf) WaitForState() (interface{}, error) {
notfoundTick := 0
// Set a default for times to check for not found
if conf.NotFoundChecks == 0 {
conf.NotFoundChecks = 20
}
var result interface{}
var resulterr error
@ -78,7 +84,7 @@ func (conf *StateChangeConf) WaitForState() (interface{}, error) {
// If we didn't find the resource, check if we have been
// not finding it for awhile, and if so, report an error.
notfoundTick += 1
if notfoundTick > 20 {
if notfoundTick > conf.NotFoundChecks {
resulterr = errors.New("couldn't find resource")
return
}