lang: Handle merging of compatible resources properly
The duplicate resource problem that puppet had should now be correctly solved in mgmt.
This commit is contained in:
@@ -58,23 +58,51 @@ func interpret(ast interfaces.Stmt) (*pgraph.Graph, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if r, exists := lookup[kind][name]; exists { // found same name
|
if r, exists := lookup[kind][name]; exists { // found same name
|
||||||
|
// if the resources support the compatibility API, then
|
||||||
|
// we can attempt to merge them intelligently...
|
||||||
|
r1, ok1 := r.(engine.CompatibleRes)
|
||||||
|
r2, ok2 := res.(engine.CompatibleRes)
|
||||||
|
if ok1 && ok2 {
|
||||||
|
if err := engine.AdaptCmp(r1, r2); err != nil {
|
||||||
|
// TODO: print a diff of the two resources
|
||||||
|
return nil, errwrap.Wrapf(err, "incompatible duplicate resource `%s` found", res)
|
||||||
|
}
|
||||||
|
merged, err := engine.ResMerge(r1, r2)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errwrap.Wrapf(err, "could not merge duplicate resources")
|
||||||
|
}
|
||||||
|
|
||||||
|
lookup[kind][name] = merged
|
||||||
|
// they match here, we don't need to test below!
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if err := engine.ResCmp(r, res); err != nil {
|
if err := engine.ResCmp(r, res); err != nil {
|
||||||
// TODO: print a diff of the two resources
|
// TODO: print a diff of the two resources
|
||||||
return nil, errwrap.Wrapf(err, "incompatible duplicate resource `%s` found", res)
|
return nil, errwrap.Wrapf(err, "inequivalent duplicate resource `%s` found", res)
|
||||||
}
|
}
|
||||||
// more than one compatible resource exists... we allow
|
// more than one identical resource exists. we can allow
|
||||||
// duplicates, if they're not going to conflict...
|
// duplicates, if they're not going to conflict... since
|
||||||
|
// it was identical, we leave the earlier version in the
|
||||||
|
// graph since they're exactly equivalent anyways.
|
||||||
// TODO: does it matter which one we add to the graph?
|
// TODO: does it matter which one we add to the graph?
|
||||||
// currently we add the first one that was found...
|
// currently we add the first one that was found...
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
lookup[kind][name] = res // add to temporary lookup table
|
lookup[kind][name] = res // add to temporary lookup table
|
||||||
graph.AddVertex(res)
|
//graph.AddVertex(res) // do this below once this table is final
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure all the vertices exist...
|
||||||
|
for _, m := range lookup {
|
||||||
|
for _, res := range m {
|
||||||
|
graph.AddVertex(res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range output.Edges {
|
for _, e := range output.Edges {
|
||||||
var v1, v2 engine.Res
|
var v1, v2 engine.Res
|
||||||
var exists bool // = true
|
var exists bool
|
||||||
var m map[string]engine.Res
|
var m map[string]engine.Res
|
||||||
var notify = e.Notify
|
var notify = e.Notify
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user