Class: Kube::Station::GraphController

Inherits:
ApplicationController show all
Defined in:
app/controllers/kube/station/graph_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#default_url_options

Instance Method Details

#showObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/kube/station/graph_controller.rb', line 4

def show
  @cluster = Cluster.find(params[:cluster_id])

  nodes = {}
  edges = []

  @cluster.resources.each do |resource|
    items = @cluster.list_resources(resource.kind)
    items.each do |item|
      meta = item[:metadata]
      uid = meta[:uid]
      nodes[uid] = {
        id: uid,
        label: meta[:name],
        kind: resource.kind,
        namespace: meta[:namespace],
        size: 20
      }

      (meta[:ownerReferences] || []).each do |ref|
        edges << { source: ref[:uid], target: uid }
      end
    end
  end

  edges.select! { |e| nodes.key?(e[:source]) && nodes.key?(e[:target]) }
  @graph_data = { nodes: nodes.values, edges: edges }.to_json
end