Skip to content

Commit 546a661

Browse files
committed
update pod watch function, table width; add headers
1 parent 7e81227 commit 546a661

File tree

6 files changed

+83
-80
lines changed

6 files changed

+83
-80
lines changed

app/scripts/controllers/service.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ angular.module('openshiftConsole')
1616
$scope.service = null;
1717
$scope.services = null;
1818
$scope.alerts = {};
19+
$scope.pods = [];
1920
$scope.renderOptions = $scope.renderOptions || {};
2021
$scope.renderOptions.hideFilterWidget = true;
2122
$scope.breadcrumbs = [
@@ -30,9 +31,22 @@ angular.module('openshiftConsole')
3031

3132
var watches = [];
3233

34+
// receive pods for the current service scope only when the service object is available
35+
var getPodsForService = function(service, pods) {
36+
$scope.podsForService = {};
37+
if (!service || !pods) {
38+
return;
39+
}
40+
41+
var ls = new LabelSelector(service.spec.selector);
42+
$scope.podsForService = ls.select(pods);
43+
};
3344
var serviceResolved = function(service, action) {
3445
$scope.loaded = true;
3546
$scope.service = service;
47+
48+
getPodsForService(service, $scope.pods);
49+
3650
if (action === "DELETED") {
3751
$scope.alerts["deleted"] = {
3852
type: "warning",
@@ -66,42 +80,28 @@ angular.module('openshiftConsole')
6680
}));
6781

6882
watches.push(DataService.watch("pods", context, function(pods) {
69-
var service = $scope.service;
70-
if (!service) {
71-
DataService
72-
.get("services", $routeParams.service, context)
73-
.then(function(service) {
74-
getPodsForService(service, pods);
75-
});
76-
return;
77-
}
78-
getPodsForService(service, pods);
79-
}));
80-
81-
// receive pods for the current service scope only when the service object is available
82-
function getPodsForService(service, pods) {
83-
$scope.podsForService = [];
84-
var ls = new LabelSelector(service.spec.selector);
83+
$scope.pods = [];
8584
angular.forEach(pods.by("metadata.name"), function(pod) {
86-
if (ls.matches(pod)) {
87-
$scope.podsForService.push(pod);
88-
}
85+
$scope.pods.push(pod);
8986
});
90-
}
87+
getPodsForService($scope.service, $scope.pods);
88+
}));
9189

9290
watches.push(DataService.watch("endpoints", context, function(endpoints) {
9391
$scope.podsWithEndpoints = {};
94-
angular.forEach(endpoints.by("metadata.name"), function(endpoint) {
95-
if (endpoint.metadata.name === $routeParams.service) {
96-
endpoint.subsets.forEach(function(subset) {
97-
subset.addresses.forEach(function(address) {
98-
if (address.targetRef !== undefined &&
99-
address.targetRef.kind === "Pod") {
100-
$scope.podsWithEndpoints[address.targetRef.name] = true;
101-
}
102-
});
103-
});
104-
}
92+
var svcEndpoint = endpoints.by("metadata.name");
93+
svcEndpoint = svcEndpoint[$routeParams.service];
94+
95+
if (!svcEndpoint) {
96+
return;
97+
}
98+
99+
_.each(svcEndpoint.subsets, function(subset) {
100+
_.each(subset.addresses, function(address) {
101+
if (_.get(address, "targetRef.kind") === "Pod") {
102+
$scope.podsWithEndpoints[address.targetRef.name] = true;
103+
}
104+
});
105105
});
106106
}));
107107

app/views/browse/service.html

+12-9
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ <h1>
6969
<span ng-repeat="ingress in service.status.loadBalancer.ingress"
7070
>{{ingress.ip}}<span ng-if="!$last">, </span></span>
7171
</dd>
72-
<dt ng-if="service.spec.externalIPs.length">External IPs:</dt>
73-
<dd ng-if="service.spec.externalIPs.length">
72+
<dt ng-if-start="service.spec.externalIPs.length">External IPs:</dt>
73+
<dd ng-if-end>
7474
<span ng-repeat="externalIP in service.spec.externalIPs"
7575
>{{externalIP}}<span ng-if="!$last">, </span></span>
7676
</dd>
@@ -81,13 +81,8 @@ <h1>
8181
</span>
8282
</dd>
8383
</dl>
84-
<div ng-if="routesForService.length" class="table-responsive small service-table">
85-
<routes-table routes="routesForService" services="services" custom-name-header="routesForService[0].kind"></routes-table>
86-
</div>
87-
<div ng-if="podsForService.length" class="table-responsive small service-table">
88-
<pods-table pods="podsForService" active-pods="podsWithEndpoints" custom-name-header="podsForService[0].kind"></pods-table>
89-
</div>
90-
<div ng-if="service.spec.ports.length" class="table-responsive">
84+
<h3 ng-if-start="service.spec.ports.length">Ports</h3>
85+
<div ng-if-end class="table-responsive">
9186
<table class="table table-bordered small service-table">
9287
<thead>
9388
<tr>
@@ -113,6 +108,14 @@ <h1>
113108
</tbody>
114109
</table>
115110
</div>
111+
<h3 ng-if-start="routesForService.length">Routes</h3>
112+
<div ng-if-end class="table-responsive small">
113+
<routes-table routes="routesForService" services="services" custom-name-header="routesForService[0].kind"></routes-table>
114+
</div>
115+
<h3 ng-if-start="(podsForService | hashSize) > 0">Pods</h3>
116+
<div ng-if-end class="table-responsive small">
117+
<pods-table pods="podsForService" active-pods="podsWithEndpoints" custom-name-header="podsForService[0].kind"></pods-table>
118+
</div>
116119
<annotations annotations="service.metadata.annotations"></annotations>
117120
</div>
118121
</uib-tab>

app/views/directives/pods-table.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</tbody>
1414
<tbody ng-repeat="pod in pods | orderObjectsByDate : true">
1515
<tr>
16-
<td data-title="Name">
16+
<td data-title="{{customNameHeader || 'Name'}}">
1717
<a href="{{pod | navigateResourceURL}}">{{pod.metadata.name}}</a>
1818
<span ng-if="!activePods[pod.metadata.name]" data-toggle="popover" data-trigger="hover" data-content="This pod has no endpoints and is not accepting traffic." style="cursor: help; padding-left: 5px;">
1919
<span class="pficon pficon-warning-triangle-o" aria-hidden="true" data-toggle="tooltip" style="cursor: help;"></span>

app/views/directives/routes-table.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</tbody>
1414
<tbody ng-repeat="route in routes | orderObjectsByDate : true">
1515
<tr>
16-
<td data-title="Name">
16+
<td data-title="{{ customNameHeader || 'Name' }}">
1717
<a href="{{route | navigateResourceURL}}">{{route.metadata.name}}</a>
1818
<route-warnings ng-if="route.spec.to.kind !== 'Service' || services"
1919
route="route"

dist/scripts/scripts.js

+24-27
Original file line numberDiff line numberDiff line change
@@ -5979,50 +5979,47 @@ d.unwatchAll(i);
59795979
});
59805980
}));
59815981
} ]), angular.module("openshiftConsole").controller("ServiceController", [ "$scope", "$routeParams", "DataService", "ProjectsService", "$filter", function(a, b, c, d, e) {
5982-
a.projectName = b.project, a.service = null, a.services = null, a.alerts = {}, a.renderOptions = a.renderOptions || {}, a.renderOptions.hideFilterWidget = !0, a.breadcrumbs = [ {
5982+
a.projectName = b.project, a.service = null, a.services = null, a.alerts = {}, a.pods = [], a.renderOptions = a.renderOptions || {}, a.renderOptions.hideFilterWidget = !0, a.breadcrumbs = [ {
59835983
title:"Services",
59845984
link:"project/" + b.project + "/browse/services"
59855985
}, {
59865986
title:b.service
59875987
} ];
59885988
var f = [], g = function(b, c) {
5989-
a.loaded = !0, a.service = b, "DELETED" === c && (a.alerts.deleted = {
5989+
if (a.podsForService = {}, b && c) {
5990+
var d = new LabelSelector(b.spec.selector);
5991+
a.podsForService = d.select(c);
5992+
}
5993+
}, h = function(b, c) {
5994+
a.loaded = !0, a.service = b, g(b, a.pods), "DELETED" === c && (a.alerts.deleted = {
59905995
type:"warning",
59915996
message:"This service has been deleted."
59925997
});
59935998
};
5994-
d.get(b.project).then(_.spread(function(d, h) {
5995-
function i(b, c) {
5996-
a.podsForService = [];
5997-
var d = new LabelSelector(b.spec.selector);
5998-
angular.forEach(c.by("metadata.name"), function(b) {
5999-
d.matches(b) && a.podsForService.push(b);
6000-
});
6001-
}
6002-
a.project = d, a.projectContext = h, c.get("services", b.service, h).then(function(a) {
6003-
g(a), f.push(c.watchObject("services", b.service, h, g));
5999+
d.get(b.project).then(_.spread(function(d, i) {
6000+
a.project = d, a.projectContext = i, c.get("services", b.service, i).then(function(a) {
6001+
h(a), f.push(c.watchObject("services", b.service, i, h));
60046002
}, function(b) {
60056003
a.loaded = !0, a.alerts.load = {
60066004
type:"error",
60076005
message:"The service details could not be loaded.",
60086006
details:"Reason: " + e("getErrorDetails")(b)
60096007
};
6010-
}), f.push(c.watch("services", h, function(b) {
6008+
}), f.push(c.watch("services", i, function(b) {
60116009
a.services = b.by("metadata.name");
6012-
})), f.push(c.watch("pods", h, function(d) {
6013-
var e = a.service;
6014-
return e ? void i(e, d) :void c.get("services", b.service, h).then(function(a) {
6015-
i(a, d);
6016-
});
6017-
})), f.push(c.watch("endpoints", h, function(c) {
6018-
a.podsWithEndpoints = {}, angular.forEach(c.by("metadata.name"), function(c) {
6019-
c.metadata.name === b.service && c.subsets.forEach(function(b) {
6020-
b.addresses.forEach(function(b) {
6021-
void 0 !== b.targetRef && "Pod" === b.targetRef.kind && (a.podsWithEndpoints[b.targetRef.name] = !0);
6022-
});
6023-
});
6024-
});
6025-
})), f.push(c.watch("routes", h, function(c) {
6010+
})), f.push(c.watch("pods", i, function(b) {
6011+
a.pods = [], angular.forEach(b.by("metadata.name"), function(b) {
6012+
a.pods.push(b);
6013+
}), g(a.service, a.pods);
6014+
})), f.push(c.watch("endpoints", i, function(c) {
6015+
a.podsWithEndpoints = {};
6016+
var d = c.by("metadata.name");
6017+
d = d[b.service], d && _.each(d.subsets, function(b) {
6018+
_.each(b.addresses, function(b) {
6019+
"Pod" === _.get(b, "targetRef.kind") && (a.podsWithEndpoints[b.targetRef.name] = !0);
6020+
});
6021+
});
6022+
})), f.push(c.watch("routes", i, function(c) {
60266023
a.routesForService = [], angular.forEach(c.by("metadata.name"), function(c) {
60276024
"Service" === c.spec.to.kind && c.spec.to.name === b.service && a.routesForService.push(c);
60286025
}), Logger.log("routes (subscribe)", a.routesByService);

dist/scripts/templates.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -3422,8 +3422,8 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
34223422
"<dd ng-if=\"service.status.loadBalancer.ingress.length\">\n" +
34233423
"<span ng-repeat=\"ingress in service.status.loadBalancer.ingress\">{{ingress.ip}}<span ng-if=\"!$last\">, </span></span>\n" +
34243424
"</dd>\n" +
3425-
"<dt ng-if=\"service.spec.externalIPs.length\">External IPs:</dt>\n" +
3426-
"<dd ng-if=\"service.spec.externalIPs.length\">\n" +
3425+
"<dt ng-if-start=\"service.spec.externalIPs.length\">External IPs:</dt>\n" +
3426+
"<dd ng-if-end>\n" +
34273427
"<span ng-repeat=\"externalIP in service.spec.externalIPs\">{{externalIP}}<span ng-if=\"!$last\">, </span></span>\n" +
34283428
"</dd>\n" +
34293429
"<dt ng-if=\"!routesForService.length\">Routes:</dt>\n" +
@@ -3433,13 +3433,8 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
34333433
"</span>\n" +
34343434
"</dd>\n" +
34353435
"</dl>\n" +
3436-
"<div ng-if=\"routesForService.length\" class=\"table-responsive small service-table\">\n" +
3437-
"<routes-table routes=\"routesForService\" services=\"services\" custom-name-header=\"routesForService[0].kind\"></routes-table>\n" +
3438-
"</div>\n" +
3439-
"<div ng-if=\"podsForService.length\" class=\"table-responsive small service-table\">\n" +
3440-
"<pods-table pods=\"podsForService\" active-pods=\"podsWithEndpoints\" custom-name-header=\"podsForService[0].kind\"></pods-table>\n" +
3441-
"</div>\n" +
3442-
"<div ng-if=\"service.spec.ports.length\" class=\"table-responsive\">\n" +
3436+
"<h3 ng-if-start=\"service.spec.ports.length\">Ports</h3>\n" +
3437+
"<div ng-if-end class=\"table-responsive\">\n" +
34433438
"<table class=\"table table-bordered small service-table\">\n" +
34443439
"<thead>\n" +
34453440
"<tr>\n" +
@@ -3465,6 +3460,14 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
34653460
"</tbody>\n" +
34663461
"</table>\n" +
34673462
"</div>\n" +
3463+
"<h3 ng-if-start=\"routesForService.length\">Routes</h3>\n" +
3464+
"<div ng-if-end class=\"table-responsive small\">\n" +
3465+
"<routes-table routes=\"routesForService\" services=\"services\" custom-name-header=\"routesForService[0].kind\"></routes-table>\n" +
3466+
"</div>\n" +
3467+
"<h3 ng-if-start=\"(podsForService | hashSize) > 0\">Pods</h3>\n" +
3468+
"<div ng-if-end class=\"table-responsive small\">\n" +
3469+
"<pods-table pods=\"podsForService\" active-pods=\"podsWithEndpoints\" custom-name-header=\"podsForService[0].kind\"></pods-table>\n" +
3470+
"</div>\n" +
34683471
"<annotations annotations=\"service.metadata.annotations\"></annotations>\n" +
34693472
"</div>\n" +
34703473
"</uib-tab>\n" +
@@ -7208,7 +7211,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
72087211
"</tbody>\n" +
72097212
"<tbody ng-repeat=\"pod in pods | orderObjectsByDate : true\">\n" +
72107213
"<tr>\n" +
7211-
"<td data-title=\"Name\">\n" +
7214+
"<td data-title=\"{{customNameHeader || 'Name'}}\">\n" +
72127215
"<a href=\"{{pod | navigateResourceURL}}\">{{pod.metadata.name}}</a>\n" +
72137216
"<span ng-if=\"!activePods[pod.metadata.name]\" data-toggle=\"popover\" data-trigger=\"hover\" data-content=\"This pod has no endpoints and is not accepting traffic.\" style=\"cursor: help; padding-left: 5px\">\n" +
72147217
"<span class=\"pficon pficon-warning-triangle-o\" aria-hidden=\"true\" data-toggle=\"tooltip\" style=\"cursor: help\"></span>\n" +
@@ -7291,7 +7294,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
72917294
"</tbody>\n" +
72927295
"<tbody ng-repeat=\"route in routes | orderObjectsByDate : true\">\n" +
72937296
"<tr>\n" +
7294-
"<td data-title=\"Name\">\n" +
7297+
"<td data-title=\"{{ customNameHeader || 'Name' }}\">\n" +
72957298
"<a href=\"{{route | navigateResourceURL}}\">{{route.metadata.name}}</a>\n" +
72967299
"<route-warnings ng-if=\"route.spec.to.kind !== 'Service' || services\" route=\"route\" service=\"services[route.spec.to.name]\">\n" +
72977300
"</route-warnings>\n" +

0 commit comments

Comments
 (0)