Skip to content

Commit fee3da9

Browse files
committed
refactor portsForRoute implementation
This patch re-implements the `portsForRoute` map to include ports without routes. It also adds small fixes to the services view
1 parent 926968c commit fee3da9

File tree

10 files changed

+309
-372
lines changed

10 files changed

+309
-372
lines changed

app/scripts/constants.js

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ window.OPENSHIFT_CONSTANTS = {
3737
"new_pod_exec": "dev_guide/deployments/deployment_strategies.html#pod-based-lifecycle-hook",
3838
"authorization": "architecture/additional_concepts/authorization.html",
3939
"roles": "architecture/additional_concepts/authorization.html#roles",
40-
"services": "architecture/core_concepts/pods_and_services.html#services",
4140
"service_accounts": "dev_guide/service_accounts.html",
4241
"users_and_groups": "architecture/additional_concepts/authentication.html#users-and-groups",
4342
"pipeline-builds": "architecture/core_concepts/builds_and_image_streams.html#pipeline-build",

app/scripts/controllers/service.js

+35-29
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ angular.module('openshiftConsole')
1616
$scope.service = null;
1717
$scope.services = null;
1818
$scope.alerts = {};
19-
$scope.pods = [];
2019
$scope.renderOptions = $scope.renderOptions || {};
2120
$scope.renderOptions.hideFilterWidget = true;
2221
$scope.breadcrumbs = [
@@ -33,43 +32,55 @@ angular.module('openshiftConsole')
3332
"Pending": "This pod will not receive traffic until all of its containers have been created."
3433
};
3534

35+
var allPods = {};
3636
var watches = [];
3737

38-
// receives routes for the current service and maps a service port to each route name
39-
var getPortsForRoutes = function(service, routes) {
40-
if (!service || !routes) {
38+
// receives routes for the current service and maps service ports to each route name
39+
var getPortsByRoute = function() {
40+
if(!$scope.service) {
4141
return;
4242
}
4343

44-
$scope.portsForRoutes = {};
45-
var orderedPorts = $filter("orderBy")(service.spec.ports, "port");
44+
$scope.portsByRoute = {};
4645

47-
for(var i = 0; i < routes.length; i++) {
48-
$scope.portsForRoutes[routes[i].metadata.name] = orderedPorts[i];
46+
_.each($scope.service.spec.ports, function(port) {
47+
var reachedByRoute = false;
48+
_.each($scope.routesForService, function(route) {
49+
if(!route.spec.port || route.spec.port.targetPort === port.name ||
50+
route.spec.port.targetPort === port.targetPort) {
51+
if(!$scope.portsByRoute[route.metadata.name]) {
52+
$scope.portsByRoute[route.metadata.name] = [];
53+
}
54+
$scope.portsByRoute[route.metadata.name].push(port);
55+
reachedByRoute = true;
56+
}
57+
});
4958

50-
// determine if at least one nodePort present
51-
if(orderedPorts[i].nodePort) {
52-
$scope.showNodePorts = true;
59+
if(!reachedByRoute) {
60+
if(!$scope.portsByRoute['']) {
61+
$scope.portsByRoute[''] = [];
62+
}
63+
$scope.portsByRoute[''].push(port);
5364
}
54-
}
65+
});
5566
};
5667

5768
// receive pods for the current service scope only when the service object is available
58-
var getPodsForService = function(service, pods) {
69+
var getPodsForService = function() {
5970
$scope.podsForService = {};
60-
if (!service || !pods) {
71+
if (!$scope.service) {
6172
return;
6273
}
6374

64-
var ls = new LabelSelector(service.spec.selector);
65-
$scope.podsForService = ls.select(pods);
75+
var ls = new LabelSelector($scope.service.spec.selector);
76+
$scope.podsForService = ls.select(allPods);
6677
};
6778
var serviceResolved = function(service, action) {
6879
$scope.loaded = true;
6980
$scope.service = service;
7081

71-
getPodsForService(service, $scope.pods);
72-
getPortsForRoutes(service, $scope.routesForService);
82+
getPodsForService();
83+
getPortsByRoute();
7384

7485
if (action === "DELETED") {
7586
$scope.alerts["deleted"] = {
@@ -104,18 +115,13 @@ angular.module('openshiftConsole')
104115
}));
105116

106117
watches.push(DataService.watch("pods", context, function(pods) {
107-
$scope.pods = [];
108-
angular.forEach(pods.by("metadata.name"), function(pod) {
109-
$scope.pods.push(pod);
110-
});
111-
getPodsForService($scope.service, $scope.pods);
118+
allPods = pods.by("metadata.name");
119+
getPodsForService();
112120
}));
113121

114122
watches.push(DataService.watch("endpoints", context, function(endpoints) {
115123
$scope.podsWithEndpoints = {};
116-
var svcEndpoint = endpoints.by("metadata.name");
117-
svcEndpoint = svcEndpoint[$routeParams.service];
118-
124+
var svcEndpoint = endpoints.by("metadata.name")[$routeParams.service];
119125
if (!svcEndpoint) {
120126
return;
121127
}
@@ -130,15 +136,15 @@ angular.module('openshiftConsole')
130136
}));
131137

132138
watches.push(DataService.watch("routes", context, function(routes) {
133-
$scope.routesForService = [];
139+
$scope.routesForService = {};
134140
angular.forEach(routes.by("metadata.name"), function(route) {
135141
if (route.spec.to.kind === "Service" &&
136142
route.spec.to.name === $routeParams.service) {
137-
$scope.routesForService.push(route);
143+
$scope.routesForService[route.metadata.name] = route;
138144
}
139145
});
140146

141-
getPortsForRoutes($scope.service, $scope.routesForService);
147+
getPortsByRoute();
142148
Logger.log("routes (subscribe)", $scope.routesByService);
143149
}));
144150

app/scripts/directives/resources.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -177,33 +177,18 @@ angular.module('openshiftConsole')
177177
templateUrl: 'views/directives/pods-table.html'
178178
};
179179
})
180-
.directive('routesTable', function() {
181-
return {
182-
restrict: 'E',
183-
scope: {
184-
routes: '=',
185-
services: '=',
186-
// Optional empty message to display when there are no pods.
187-
emptyMessage: '=?',
188-
// Alternative header text to display in the 'Name' column.
189-
customNameHeader: '=?'
190-
},
191-
templateUrl: 'views/directives/routes-table.html'
192-
};
193-
})
194180
.directive('trafficTable', function() {
195181
return {
196182
restrict: 'E',
197183
scope: {
198184
routes: '=',
199185
services: '=',
200-
ports: '=',
186+
portsByRoute: '=',
201187
showNodePorts: '=?',
202188
// Optional empty message to display when there are no pods.
203189
emptyMessage: '=?',
204190
// Alternative header text to display in the 'Name' column.
205191
customNameHeader: '=?',
206-
hasFooter: '=?'
207192
},
208193
templateUrl: 'views/directives/traffic-table.html'
209194
};

app/views/browse/routes.html

+58-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,64 @@ <h1>
3131
<alerts alerts="alerts"></alerts>
3232
<div class="row">
3333
<div class="col-md-12 gutter-top">
34-
<routes-table routes="routes" services="services" emptyMessage="emptyMessage"></routes-table>
34+
<table class="table table-bordered table-hover table-mobile">
35+
<thead>
36+
<tr>
37+
<th>{{customNameHeader || 'Name'}}</th>
38+
<th>Hostname</th>
39+
<th>Routes To</th>
40+
<th>Target Port</th>
41+
<th>TLS Termination</th>
42+
</tr>
43+
</thead>
44+
<tbody ng-if="(routes | hashSize) == 0">
45+
<tr><td colspan="5"><em>{{emptyMessage || 'No routes to show'}}</em></td></tr>
46+
</tbody>
47+
<tbody ng-repeat="route in routes | orderObjectsByDate : true">
48+
<tr>
49+
<td data-title="{{ customNameHeader || 'Name' }}">
50+
<a href="{{route | navigateResourceURL}}">{{route.metadata.name}}</a>
51+
<route-warnings ng-if="route.spec.to.kind !== 'Service' || services"
52+
route="route"
53+
service="services[route.spec.to.name]">
54+
</route-warnings>
55+
</td>
56+
<td data-title="Hostname">
57+
<span ng-if="(route | isWebRoute)" class="word-break">
58+
<a href="{{route | routeWebURL}}" target="_blank">{{route | routeLabel}}</a>
59+
</span>
60+
<span ng-if="!(route | isWebRoute)" class="word-break">
61+
{{route | routeLabel}}
62+
</span>
63+
<span ng-if="!route.status.ingress" data-toggle="popover" data-trigger="hover" data-content="The route is not accepting traffic yet because it has not been admitted by a router." style="cursor: help; padding-left: 5px;">
64+
<status-icon status="'Pending'" disable-animation></status-icon>
65+
<span class="sr-only">Pending</span>
66+
</span>
67+
</td>
68+
<td data-title="Routes To">
69+
<span ng-if="route.spec.to.kind !== 'Service'">{{route.spec.to.kind}}: {{route.spec.to.name}}</span>
70+
<span ng-if="route.spec.to.kind === 'Service'"><a ng-href="{{route.spec.to.name | navigateResourceURL : 'Service': route.metadata.namespace}}">{{route.spec.to.name}}</a></span>
71+
</td>
72+
<!-- Add non-breaking space to empty cells. Otherwise, table-mobile layout is broken. -->
73+
<td data-title="Target Port">
74+
<span ng-if="route.spec.port.targetPort">
75+
<span ng-if="route.spec.to.kind !== 'Service'">{{route.spec.port.targetPort}}</span>
76+
<!-- Show the short display port in the table, but the long in the title attr. -->
77+
<span ng-if="route.spec.to.kind === 'Service'"
78+
ng-attr-title="{{route | routeTargetPortMapping : services[route.spec.to.name]}}">
79+
{{route.spec.port.targetPort}}
80+
</span>
81+
</span>
82+
<span ng-if="!route.spec.port.targetPort">&nbsp;</span>
83+
</td>
84+
<!-- Use shorter Termination title for table-mobile to avoid overlapping text. -->
85+
<td data-title="Termination">
86+
{{route.spec.tls.termination}}
87+
<span ng-if="!route.spec.tls.termination">&nbsp;</span>
88+
</td>
89+
</tr>
90+
</tbody>
91+
</table>
3592
</div><!-- /col-* -->
3693
</div>
3794
</div>

app/views/browse/service.html

+12-18
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ <h1>
6464
<dd>{{service.spec.clusterIP}}</dd>
6565
<dt>Hostname:</dt>
6666
<dd>
67-
{{service.metadata.name + '.' + service.metadata.namespace + '.svc'}}
67+
{{service.metadata.name}}.{{service.metadata.namespace}}.svc
6868
<span data-toggle="popover" data-trigger="hover" data-content="{{'This address is only resolvable from within the cluster.'}}" style="cursor: help; padding-left: 5px;">
6969
<span class="pficon pficon-info" aria-hidden="true" data-toggle="tooltip" style="cursor: help;"></span>
7070
</span>
@@ -73,8 +73,8 @@ <h1>
7373
<dd ng-if-end>{{service.spec.externalName}}</dd>
7474
<dt>Session affinity:</dt>
7575
<dd>{{service.spec.sessionAffinity}}</dd>
76-
<dt ng-if="service.status.loadBalancer.ingress.length">Ingress Points:</dt>
77-
<dd ng-if="service.status.loadBalancer.ingress.length">
76+
<dt ng-if-start="service.status.loadBalancer.ingress.length">Ingress Points:</dt>
77+
<dd ng-if-end>
7878
<span ng-repeat="ingress in service.status.loadBalancer.ingress"
7979
>{{ingress.ip}}<span ng-if="!$last">, </span></span>
8080
</dd>
@@ -83,32 +83,26 @@ <h1>
8383
<span ng-repeat="externalIP in service.spec.externalIPs"
8484
>{{externalIP}}<span ng-if="!$last">, </span></span>
8585
</dd>
86-
<dt ng-if="!routesForService.length">Routes:</dt>
87-
<dd ng-if="!routesForService.length">
88-
<span ng-if="!routesForService.length">
86+
<dt ng-if-start="(routesForService | hashSize) == 0">Routes:</dt>
87+
<dd ng-if-end>
88+
<span>
8989
<a ng-href="project/{{project.metadata.name}}/create-route?service={{service.metadata.name}}" ng-if="'routes' | canI : 'create'">Create route</a>
90+
<span ng-if="!('routes' | canI : 'create')"><em>None</em></span>
9091
</span>
9192
</dd>
9293
</dl>
9394
<h3>
9495
Traffic
9596
</h3>
9697
<div class="table-responsive">
97-
<traffic-table routes="routesForService" ports="portsForRoutes" services="services" show-node-ports="showNodePorts" custom-name-header="routesForService[0].kind" has-footer="true"></traffic-table>
98+
<traffic-table ports-by-route="portsByRoute" routes="routesForService" services="services" show-node-ports="showNodePorts" custom-name-header="'Route'"></traffic-table>
99+
</div>
100+
<div style="margin:-10px 0 10px 0;">
101+
Learn more about <a ng-href="{{'route-types' | helpLink}}" target="_blank">routes</a> and <a ng-href="{{'services' | helpLink}}" target="_blank">services</a>
98102
</div>
99-
Learn more about
100-
<span class="learn-more-inline" style="margin-left:0;">
101-
<a ng-href="{{'route-types' | helpLink}}" target="_blank">routes <i class="fa fa-external-link"></i>
102-
</a>
103-
</span> and
104-
<span class="learn-more-inline" style="margin-left:0;">
105-
<a ng-href="{{'services' | helpLink}}" target="_blank">
106-
services <i class="fa fa-external-link"></i>
107-
</a>
108-
</span>.
109103
<h3>Pods</h3>
110104
<div class="table-responsive">
111-
<pods-table pods="podsForService" active-pods="podsWithEndpoints" custom-name-header="podsForService[0].kind" pod-failure-reasons="podFailureReasons"></pods-table>
105+
<pods-table pods="podsForService" active-pods="podsWithEndpoints" custom-name-header="'Pod'" pod-failure-reasons="podFailureReasons"></pods-table>
112106
</div>
113107
<annotations annotations="service.metadata.annotations"></annotations>
114108
</div>

app/views/directives/pods-table.html

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
<tr>
1717
<td data-title="{{customNameHeader || 'Name'}}">
1818
<a href="{{pod | navigateResourceURL}}">{{pod.metadata.name}}</a>
19-
<span ng-if="pod | isTroubledPod">
20-
<pod-warnings pod="pod"></pod-warnings>
21-
</span>
2219
<span ng-if="pod | isDebugPod">
2320
<i class="fa fa-bug info-popover"
2421
aria-hidden="true"
@@ -39,12 +36,13 @@
3936
<td data-title="Age"><span am-time-ago="pod.metadata.creationTimestamp" am-without-suffix="true"></span></td>
4037
<td ng-if="activePods" data-title="Receiving Traffic">
4138
<span ng-if="activePods[pod.metadata.name]">
42-
<status-icon fixed-width="true" status="'Succeeded'" disable-animation></status-icon>
39+
<span class="fa fa-check text-success" aria-hidden="true"></span>
40+
<span class="sr-only">Yes</span>
4341
</span>
4442
<span ng-if="!activePods[pod.metadata.name]">
45-
<span data-toggle="popover" data-trigger="hover" data-content="{{podFailureReasons[pod.status.phase] || 'This pod has no endpoints and is not accepting traffic.'}}" style="cursor: help; padding-left: 5px;">
43+
<span data-toggle="popover" data-trigger="hover" data-content="{{podFailureReasons[pod.status.phase] || 'This pod has no endpoints and is not accepting traffic.'}}" style="cursor: help;">
4644
<span class="fa fa-fw fa-times text-danger" aria-hidden="true" data-toggle="tooltip" style="cursor: help;"></span>
47-
<span class="sr-only">{{pod.status.phase}}</span>
45+
<span class="sr-only">No</span>
4846
</span>
4947
</span>
5048
</td>

app/views/directives/routes-table.html

-58
This file was deleted.

0 commit comments

Comments
 (0)