mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
Merge pull request #2973 from weaveworks/report-upgrade-deployments
report.Upgrade() add deployments to pods as parent
This commit is contained in:
@@ -62,9 +62,7 @@ var PodRenderer = Memoise(ConditionalRenderer(renderKubernetesTopologies,
|
||||
),
|
||||
),
|
||||
),
|
||||
// ConnectionJoin invokes the renderer twice, hence it
|
||||
// helps to memoise it.
|
||||
ConnectionJoin(MapPod2IP, Memoise(selectPodsWithDeployments{})),
|
||||
ConnectionJoin(MapPod2IP, SelectPod),
|
||||
),
|
||||
),
|
||||
))
|
||||
@@ -113,31 +111,6 @@ func renderParents(childTopology string, parentTopologies []string, noParentsPse
|
||||
)...)
|
||||
}
|
||||
|
||||
// Renderer to return modified Pod nodes to elide replica sets and point directly
|
||||
// to deployments where applicable.
|
||||
type selectPodsWithDeployments struct{}
|
||||
|
||||
func (s selectPodsWithDeployments) Render(rpt report.Report) Nodes {
|
||||
result := report.Nodes{}
|
||||
// For each pod, we check for any replica sets, and merge any deployments they point to
|
||||
// into a replacement Parents value.
|
||||
for podID, pod := range rpt.Pod.Nodes {
|
||||
if replicaSetIDs, ok := pod.Parents.Lookup(report.ReplicaSet); ok {
|
||||
newParents := pod.Parents.Delete(report.ReplicaSet)
|
||||
for _, replicaSetID := range replicaSetIDs {
|
||||
if replicaSet, ok := rpt.ReplicaSet.Nodes[replicaSetID]; ok {
|
||||
if deploymentIDs, ok := replicaSet.Parents.Lookup(report.Deployment); ok {
|
||||
newParents = newParents.Add(report.Deployment, deploymentIDs)
|
||||
}
|
||||
}
|
||||
}
|
||||
pod = pod.WithParents(newParents)
|
||||
}
|
||||
result[podID] = pod
|
||||
}
|
||||
return Nodes{Nodes: result}
|
||||
}
|
||||
|
||||
// MapPod2IP maps pod nodes to their IP address. This allows pods to
|
||||
// be joined directly with the endpoint topology.
|
||||
func MapPod2IP(m report.Node) []string {
|
||||
|
||||
@@ -341,6 +341,10 @@ func (r Report) Validate() error {
|
||||
//
|
||||
// This for now creates node's LatestControls from Controls.
|
||||
func (r Report) Upgrade() Report {
|
||||
return r.upgradeLatestControls().upgradePodNodes()
|
||||
}
|
||||
|
||||
func (r Report) upgradeLatestControls() Report {
|
||||
needUpgrade := false
|
||||
r.WalkTopologies(func(topology *Topology) {
|
||||
for _, node := range topology.Nodes {
|
||||
@@ -349,6 +353,7 @@ func (r Report) Upgrade() Report {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if !needUpgrade {
|
||||
return r
|
||||
}
|
||||
@@ -369,9 +374,41 @@ func (r Report) Upgrade() Report {
|
||||
}
|
||||
topology.Nodes = n
|
||||
})
|
||||
|
||||
return cp
|
||||
}
|
||||
|
||||
func (r Report) upgradePodNodes() Report {
|
||||
// At the same time the probe stopped reporting replicasets,
|
||||
// it also started reporting deployments as pods' parents
|
||||
if len(r.ReplicaSet.Nodes) == 0 {
|
||||
return r
|
||||
}
|
||||
|
||||
// For each pod, we check for any replica sets, and merge any deployments they point to
|
||||
// into a replacement Parents value.
|
||||
nodes := Nodes{}
|
||||
for podID, pod := range r.Pod.Nodes {
|
||||
if replicaSetIDs, ok := pod.Parents.Lookup(ReplicaSet); ok {
|
||||
newParents := pod.Parents.Delete(ReplicaSet)
|
||||
for _, replicaSetID := range replicaSetIDs {
|
||||
if replicaSet, ok := r.ReplicaSet.Nodes[replicaSetID]; ok {
|
||||
if deploymentIDs, ok := replicaSet.Parents.Lookup(Deployment); ok {
|
||||
newParents = newParents.Add(Deployment, deploymentIDs)
|
||||
}
|
||||
}
|
||||
}
|
||||
// newParents contains a copy of the current parents without replicasets,
|
||||
// PruneParents().WithParents() ensures replicasets are actually deleted
|
||||
pod = pod.PruneParents().WithParents(newParents)
|
||||
}
|
||||
nodes[podID] = pod
|
||||
}
|
||||
r.Pod.Nodes = nodes
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// BackwardCompatible returns a new backward-compatible report.
|
||||
//
|
||||
// This for now creates node's Controls from LatestControls.
|
||||
|
||||
@@ -105,17 +105,21 @@ func TestReportBackwardCompatibility(t *testing.T) {
|
||||
func TestReportUpgrade(t *testing.T) {
|
||||
mtime.NowForce(time.Now())
|
||||
defer mtime.NowReset()
|
||||
node := report.MakeNode("foo").WithControls("alive")
|
||||
parentsWithDeployment := report.MakeSets().Add(report.Deployment, report.MakeStringSet("id"))
|
||||
rsNode := report.MakeNode("bar").WithParents(parentsWithDeployment)
|
||||
podNode := report.MakeNode("foo").WithControls("alive").WithParents(report.MakeSets().Add(report.ReplicaSet, report.MakeStringSet("bar")))
|
||||
controls := map[string]report.NodeControlData{
|
||||
"alive": {
|
||||
Dead: false,
|
||||
},
|
||||
}
|
||||
expectedNode := node.WithLatestControls(controls)
|
||||
expectedPodNode := podNode.PruneParents().WithParents(parentsWithDeployment).WithLatestControls(controls)
|
||||
rpt := report.MakeReport()
|
||||
rpt.Pod.AddNode(node)
|
||||
rpt.ReplicaSet.AddNode(rsNode)
|
||||
rpt.Pod.AddNode(podNode)
|
||||
expected := report.MakeReport()
|
||||
expected.Pod.AddNode(expectedNode)
|
||||
expected.ReplicaSet.AddNode(rsNode)
|
||||
expected.Pod.AddNode(expectedPodNode)
|
||||
got := rpt.Upgrade()
|
||||
if !s_reflect.DeepEqual(expected, got) {
|
||||
t.Error(test.Diff(expected, got))
|
||||
|
||||
Reference in New Issue
Block a user