engine: resources: Work around a subtle embedded res bug
This is a subtle issue that was found that caused a panic. This should solve things for now, but it would be wise to build embedded or composite resources sparingly until we we're certain this would work the way we wanted for all scenarios.
This commit is contained in:
@@ -79,6 +79,7 @@ type CronRes struct {
|
|||||||
traits.Base
|
traits.Base
|
||||||
traits.Edgeable
|
traits.Edgeable
|
||||||
traits.Recvable
|
traits.Recvable
|
||||||
|
traits.Refreshable // needed because we embed a svc res
|
||||||
|
|
||||||
init *engine.Init
|
init *engine.Init
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ func init() {
|
|||||||
type NspawnRes struct {
|
type NspawnRes struct {
|
||||||
traits.Base // add the base methods without re-implementation
|
traits.Base // add the base methods without re-implementation
|
||||||
//traits.Groupable // TODO: this would be quite useful for this resource
|
//traits.Groupable // TODO: this would be quite useful for this resource
|
||||||
|
traits.Refreshable // needed because we embed a svc res
|
||||||
|
|
||||||
init *engine.Init
|
init *engine.Init
|
||||||
|
|
||||||
|
|||||||
@@ -280,7 +280,17 @@ func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
|
|
||||||
var running = (activestate.Value == dbus.MakeVariant("active"))
|
var running = (activestate.Value == dbus.MakeVariant("active"))
|
||||||
var stateOK = ((obj.State == "") || (obj.State == "running" && running) || (obj.State == "stopped" && !running))
|
var stateOK = ((obj.State == "") || (obj.State == "running" && running) || (obj.State == "stopped" && !running))
|
||||||
var startupOK = true // XXX: DETECT AND SET
|
var startupOK = true // XXX: DETECT AND SET
|
||||||
|
|
||||||
|
// NOTE: if this svc resource is embedded as a composite resource inside
|
||||||
|
// of another resource using a technique such as `makeComposite()`, then
|
||||||
|
// the Init of the embedded resource is traditionally passed through and
|
||||||
|
// identical to the parent's Init. As a result, the data matches what is
|
||||||
|
// expected from the parent. (So this luckily turns out to be actually a
|
||||||
|
// thing that does help, although it is important to add the Refreshable
|
||||||
|
// trait to the parent resource, or we'll panic when we call this line.)
|
||||||
|
// It might not be recommended to use the Watch method without a thought
|
||||||
|
// to what actually happens when we would run Send(), and other methods.
|
||||||
var refresh = obj.init.Refresh() // do we have a pending reload to apply?
|
var refresh = obj.init.Refresh() // do we have a pending reload to apply?
|
||||||
|
|
||||||
if stateOK && startupOK && !refresh {
|
if stateOK && startupOK && !refresh {
|
||||||
|
|||||||
Reference in New Issue
Block a user