rename the 'stateok' return value to 'checkok'

The naming was confusing because the boolean return value expresses
whether the resource needed changing (the check failed) as opposed to
the state not being not OK.

purpleidea note: The "stateok" (now properly renamed to "checkok") is
actually the historical bool return value of the Check() -> bool
function which is now part of the CheckApply() amalgamation. This is an
easy way to think about it if you're trying to understand why at the end
of a successful apply we return false, nil.
This commit is contained in:
Felix Frank
2016-05-14 18:09:29 +02:00
parent 995ca32eee
commit 3aaa80974e
6 changed files with 10 additions and 10 deletions

View File

@@ -201,7 +201,7 @@ func (obj *ExecRes) Watch(processChan chan Event) {
} }
// TODO: expand the IfCmd to be a list of commands // TODO: expand the IfCmd to be a list of commands
func (obj *ExecRes) CheckApply(apply bool) (stateok bool, err error) { func (obj *ExecRes) CheckApply(apply bool) (checkok bool, err error) {
log.Printf("%v[%v]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply) log.Printf("%v[%v]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply)
// if there is a watch command, but no if command, run based on state // if there is a watch command, but no if command, run based on state

View File

@@ -328,7 +328,7 @@ func (obj *FileRes) FileApply() error {
return nil // success return nil // success
} }
func (obj *FileRes) CheckApply(apply bool) (stateok bool, err error) { func (obj *FileRes) CheckApply(apply bool) (checkok bool, err error) {
log.Printf("%v[%v]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply) log.Printf("%v[%v]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply)
if obj.isStateOK { // cache the state if obj.isStateOK { // cache the state

View File

@@ -92,7 +92,7 @@ func (obj *NoopRes) Watch(processChan chan Event) {
} }
// CheckApply method for Noop resource. Does nothing, returns happy! // CheckApply method for Noop resource. Does nothing, returns happy!
func (obj *NoopRes) CheckApply(apply bool) (stateok bool, err error) { func (obj *NoopRes) CheckApply(apply bool) (checkok bool, err error) {
log.Printf("%v[%v]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply) log.Printf("%v[%v]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply)
return true, nil // state is always okay return true, nil // state is always okay
} }

View File

@@ -729,15 +729,15 @@ func (g *Graph) Process(v *Vertex) {
obj.SetState(resStateCheckApply) obj.SetState(resStateCheckApply)
// if this fails, don't UpdateTimestamp() // if this fails, don't UpdateTimestamp()
stateok, err := obj.CheckApply(true) checkok, err := obj.CheckApply(true)
if stateok && err != nil { // should never return this way if checkok && err != nil { // should never return this way
log.Fatalf("%v[%v]: CheckApply(): %t, %+v", obj.Kind(), obj.GetName(), stateok, err) log.Fatalf("%v[%v]: CheckApply(): %t, %+v", obj.Kind(), obj.GetName(), checkok, err)
} }
if DEBUG { if DEBUG {
log.Printf("%v[%v]: CheckApply(): %t, %v", obj.Kind(), obj.GetName(), stateok, err) log.Printf("%v[%v]: CheckApply(): %t, %v", obj.Kind(), obj.GetName(), checkok, err)
} }
if !stateok { // if state *was* not ok, we had to have apply'ed if !checkok { // if state *was* not ok, we had to have apply'ed
if err != nil { // error during check or apply if err != nil { // error during check or apply
ok = false ok = false
} else { } else {

2
pkg.go
View File

@@ -241,7 +241,7 @@ func (obj *PkgRes) pkgMappingHelper(bus *Conn) (map[string]*PkPackageIDActionDat
return result, nil return result, nil
} }
func (obj *PkgRes) CheckApply(apply bool) (stateok bool, err error) { func (obj *PkgRes) CheckApply(apply bool) (checkok bool, err error) {
log.Printf("%v: CheckApply(%t)", obj.fmtNames(obj.getNames()), apply) log.Printf("%v: CheckApply(%t)", obj.fmtNames(obj.getNames()), apply)
if obj.State == "" { // TODO: Validate() should replace this check! if obj.State == "" { // TODO: Validate() should replace this check!

2
svc.go
View File

@@ -227,7 +227,7 @@ func (obj *SvcRes) Watch(processChan chan Event) {
} }
} }
func (obj *SvcRes) CheckApply(apply bool) (stateok bool, err error) { func (obj *SvcRes) CheckApply(apply bool) (checkok bool, err error) {
log.Printf("%v[%v]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply) log.Printf("%v[%v]: CheckApply(%t)", obj.Kind(), obj.GetName(), apply)
if obj.isStateOK { // cache the state if obj.isStateOK { // cache the state