Propagate multiple container values at once

This is more efficient than repeatedly inserting a single value.
This commit is contained in:
Bryan Boreham
2018-07-18 08:58:07 +00:00
parent 6ff8316a1d
commit cc79b7631e
3 changed files with 16 additions and 12 deletions

View File

@@ -143,11 +143,9 @@ func (r containerWithImageNameRenderer) Render(rpt report.Report) Nodes {
imageNameWithoutTag := docker.ImageNameWithoutTag(imageName)
imageNodeID := report.MakeContainerImageNodeID(imageNameWithoutTag)
c = propagateLatest(docker.ImageName, image, c)
c = propagateLatest(docker.ImageTag, image, c)
c = propagateLatest(docker.ImageSize, image, c)
c = propagateLatest(docker.ImageVirtualSize, image, c)
c = propagateLatest(docker.ImageLabelPrefix+"works.weave.role", image, c)
c.Latest = c.Latest.Propagate(image.Latest, docker.ImageName, docker.ImageTag,
docker.ImageSize, docker.ImageVirtualSize, docker.ImageLabelPrefix+"works.weave.role")
c.Parents = c.Parents.
Delete(report.ContainerImage).
Add(report.ContainerImage, report.MakeStringSet(imageNodeID))

View File

@@ -115,13 +115,6 @@ func (m Map) Render(rpt report.Report) Nodes {
return output.result(input)
}
func propagateLatest(key string, from, to report.Node) report.Node {
if value, timestamp, ok := from.Latest.LookupEntry(key); ok {
to.Latest = to.Latest.Set(key, timestamp, value)
}
return to
}
// Condition is a predecate over the entire report that can evaluate to true or false.
type Condition func(report.Report) bool

View File

@@ -173,3 +173,16 @@ func (m StringLatestMap) addMapEntries(ts time.Time, n map[string]string) String
out.fixup()
return out
}
// Propagate a set of latest values from one set to another.
func (m StringLatestMap) Propagate(from StringLatestMap, keys ...string) StringLatestMap {
out := make(StringLatestMap, len(m), len(m)+len(keys))
copy(out, m)
for _, k := range keys {
if v, ts, ok := from.LookupEntry(k); ok {
out = append(out, stringLatestEntry{key: k, Value: v, Timestamp: ts})
}
}
out.fixup()
return out
}