mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-19 04:16:21 +00:00
probe: merge controls from different probes
This change creates a host topology from cluster-wide probe using kubernetes nodes with cordon/un-cordon control. This also adds the logic to merge the controls coming from different probes for host topology.
This commit is contained in:
@@ -67,6 +67,8 @@ type Client interface {
|
||||
ScaleDown(namespaceID, id string) error
|
||||
// Cordon or Uncordon a node based on whether `desired` is true or false respectively.
|
||||
CordonNode(name string, desired bool) error
|
||||
// Returns a list of kubernetes nodes.
|
||||
GetNodes() ([]apiv1.Node, error)
|
||||
}
|
||||
|
||||
// ResourceMap is the mapping of resource and their GroupKind
|
||||
@@ -647,3 +649,12 @@ func (c *client) CordonNode(name string, desired bool) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) GetNodes() ([]apiv1.Node, error) {
|
||||
l, err := c.client.CoreV1().Nodes().List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return l.Items, nil
|
||||
}
|
||||
|
||||
@@ -302,10 +302,6 @@ func (r *Tagger) Tag(rpt report.Report) (report.Report, error) {
|
||||
|
||||
rpt.Container.Nodes[id] = n.WithParent(report.Pod, report.MakePodNodeID(uid))
|
||||
}
|
||||
for id, n := range rpt.Host.Nodes {
|
||||
controls := append(n.ActiveControls(), CordonNode, UncordonNode)
|
||||
rpt.Host.Nodes[id] = n.WithLatestActiveControls(controls...)
|
||||
}
|
||||
return rpt, nil
|
||||
}
|
||||
|
||||
@@ -364,6 +360,10 @@ func (r *Reporter) Report() (report.Report, error) {
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
hostTopology, err := r.hostTopology()
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
result.Pod = result.Pod.Merge(podTopology)
|
||||
result.Service = result.Service.Merge(serviceTopology)
|
||||
@@ -378,12 +378,7 @@ func (r *Reporter) Report() (report.Report, error) {
|
||||
result.VolumeSnapshot = result.VolumeSnapshot.Merge(volumeSnapshotTopology)
|
||||
result.VolumeSnapshotData = result.VolumeSnapshotData.Merge(volumeSnapshotDataTopology)
|
||||
result.Job = result.Job.Merge(jobTopology)
|
||||
|
||||
// Add buttons for Host view, with the ID of the Kubernetes probe
|
||||
for _, control := range CordonControl {
|
||||
control.ProbeID = r.probeID
|
||||
result.Host.Controls.AddControl(control)
|
||||
}
|
||||
result.Host = result.Host.Merge(hostTopology)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -704,3 +699,32 @@ func (r *Reporter) namespaceTopology() (report.Topology, error) {
|
||||
})
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *Reporter) hostTopology() (report.Topology, error) {
|
||||
result := report.MakeTopology()
|
||||
// Add buttons for Host view, with the ID of the Kubernetes probe
|
||||
for _, control := range CordonControl {
|
||||
control.ProbeID = r.probeID
|
||||
result.Controls.AddControl(control)
|
||||
}
|
||||
|
||||
nodes, err := r.client.GetNodes()
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
for _, n := range nodes {
|
||||
var activeControl string
|
||||
if n.Spec.Unschedulable {
|
||||
activeControl = UncordonNode
|
||||
} else {
|
||||
activeControl = CordonNode
|
||||
}
|
||||
result.AddNode(
|
||||
report.MakeNode(report.MakeHostNodeID(n.Name)).
|
||||
WithTopology("host").
|
||||
WithLatestActiveControls(activeControl),
|
||||
)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -209,6 +209,10 @@ func (c *mockClient) CordonNode(name string, desired bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockClient) GetNodes() ([]apiv1.Node, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type mockPipeClient map[string]xfer.Pipe
|
||||
|
||||
func (c mockPipeClient) PipeConnection(appID, id string, pipe xfer.Pipe) error {
|
||||
|
||||
Reference in New Issue
Block a user