Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var truncate = function(str, width, left) {
var pods = [];
var services = [];
var controllers = [];
var replicasets = [];
var deployments = [];
var uses = {};

Expand All @@ -56,6 +57,10 @@ var groupByName = function() {
$.each(controllers.items, insertByName);
}

if (replicasets.items) {
$.each(replicasets.items, insertByName);
}

if (deployments.items) {
$.each(deployments.items, insertByName);
}
Expand Down Expand Up @@ -97,6 +102,27 @@ var connectControllers = function() {
}
}

var connectReplicasets = function() {
if (!replicasets.items) return;

for (var i = 0; i < replicasets.items.length; i++) {
var replicaset = replicasets.items[i];
for (var j = 0; j < pods.items.length; j++) {
var pod = pods.items[j];
if (matchesLabelQuery(pod.metadata.labels, replicaset.spec.selector.matchLabels)) {
jsPlumb.connect({
source: 'controller-' + replicaset.metadata.name,
target: 'pod-' + pod.metadata.name,
anchors:["Bottom", "Bottom"],
paintStyle:{lineWidth:5,strokeStyle:'rgb(51,105,232)'},
joinStyle:"round",
endpointStyle:{ fillStyle: 'rgb(51,105,232)', radius: 7 },
connector: ["Flowchart", { cornerRadius:5 }]});
}
}
}
}

var connectDeployments = function() {
if (!deployments.items) return;

Expand Down Expand Up @@ -125,6 +151,8 @@ var connectServices = function() {
var service = services.items[i];
for (var j = 0; j < pods.items.length; j++) {
var pod = pods.items[j];
if (!service.spec.selector) continue;

if (matchesLabelQuery(pod.metadata.labels, service.spec.selector)) {
jsPlumb.connect(
{
Expand All @@ -142,6 +170,7 @@ var connectServices = function() {
var connectEverything = function() {
connectUses();
connectControllers();
connectReplicasets();
connectDeployments();
connectServices();
};
Expand Down Expand Up @@ -386,7 +415,16 @@ var loadData = function() {
});
});

$.when(req1, req2, req3, req4, req5).then(function() {
var req6 = $.getJSON("/apis/extensions/v1beta1/namespaces/default/replicasets?labelSelector=visualize%3Dtrue", function( data ) {
replicasets = data;
if (!data.items) return;

$.each(data.items, function(key, val) {
val.type = 'replicaset';
});
});

$.when(req1, req2, req3, req4, req5, req6).then(function() {
deferred.resolve();
});

Expand All @@ -398,8 +436,9 @@ function refresh(instance) {
pods = [];
services = [];
controllers = [];
deployments = [];
nodes = [];
replicasets = [];
deployments = [];
nodes = [];
uses = {};
groups = {};

Expand Down