Fix the provisioner graphing
Without this change, all provisioners are added to the graph by default and they are never pruned from the graph if their not needed.
This commit is contained in:
parent
2dca1ea9a0
commit
5c3da47d8e
|
@ -136,9 +136,6 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
|
||||||
|
|
||||||
// Make sure all the connections that are proxies are connected through
|
// Make sure all the connections that are proxies are connected through
|
||||||
&ProxyTransformer{},
|
&ProxyTransformer{},
|
||||||
|
|
||||||
// Make sure we have a single root
|
|
||||||
&RootTransformer{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're on the root path, then we do a bunch of other stuff.
|
// If we're on the root path, then we do a bunch of other stuff.
|
||||||
|
@ -170,17 +167,15 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
|
||||||
&CloseProviderTransformer{},
|
&CloseProviderTransformer{},
|
||||||
&CloseProvisionerTransformer{},
|
&CloseProvisionerTransformer{},
|
||||||
|
|
||||||
// Make sure we have a single root after the above changes.
|
|
||||||
// This is the 2nd root transformer. In practice this shouldn't
|
|
||||||
// actually matter as the RootTransformer is idempotent.
|
|
||||||
&RootTransformer{},
|
|
||||||
|
|
||||||
// Perform the transitive reduction to make our graph a bit
|
// Perform the transitive reduction to make our graph a bit
|
||||||
// more sane if possible (it usually is possible).
|
// more sane if possible (it usually is possible).
|
||||||
&TransitiveReductionTransformer{},
|
&TransitiveReductionTransformer{},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure we have a single root
|
||||||
|
steps = append(steps, &RootTransformer{})
|
||||||
|
|
||||||
// Remove nils
|
// Remove nils
|
||||||
for i, s := range steps {
|
for i, s := range steps {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|
|
@ -97,15 +97,38 @@ type MissingProvisionerTransformer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MissingProvisionerTransformer) Transform(g *Graph) error {
|
func (t *MissingProvisionerTransformer) Transform(g *Graph) error {
|
||||||
|
// Create a set of our supported provisioners
|
||||||
|
supported := make(map[string]struct{}, len(t.Provisioners))
|
||||||
|
for _, v := range t.Provisioners {
|
||||||
|
supported[v] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the map of provisioners we already have in our graph
|
||||||
m := provisionerVertexMap(g)
|
m := provisionerVertexMap(g)
|
||||||
for _, p := range t.Provisioners {
|
|
||||||
|
// Go through all the provisioner consumers and make sure we add
|
||||||
|
// that provisioner if it is missing.
|
||||||
|
for _, v := range g.Vertices() {
|
||||||
|
pv, ok := v.(GraphNodeProvisionerConsumer)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range pv.ProvisionedBy() {
|
||||||
if _, ok := m[p]; ok {
|
if _, ok := m[p]; ok {
|
||||||
// This provisioner already exists as a configured node
|
// This provisioner already exists as a configure node
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := supported[p]; !ok {
|
||||||
|
// If we don't support the provisioner type, skip it.
|
||||||
|
// Validation later will catch this as an error.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add our own missing provisioner node to the graph
|
// Add our own missing provisioner node to the graph
|
||||||
g.Add(&graphNodeMissingProvisioner{ProvisionerNameValue: p})
|
m[p] = g.Add(&graphNodeMissingProvisioner{ProvisionerNameValue: p})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -101,7 +101,6 @@ func TestGraphNodeMissingProvisioner_ProvisionerName(t *testing.T) {
|
||||||
|
|
||||||
const testTransformMissingProvisionerBasicStr = `
|
const testTransformMissingProvisionerBasicStr = `
|
||||||
aws_instance.web
|
aws_instance.web
|
||||||
provisioner.foo
|
|
||||||
provisioner.shell (close)
|
provisioner.shell (close)
|
||||||
aws_instance.web
|
aws_instance.web
|
||||||
`
|
`
|
||||||
|
|
Loading…
Reference in New Issue