Skip to content

Commit 1181054

Browse files
committed
Init Containers Added to Pod Template
Update for pod template directive to allow displaying init containers
1 parent 39a73ad commit 1181054

File tree

6 files changed

+401
-221
lines changed

6 files changed

+401
-221
lines changed

app/scripts/controllers/pod.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -419,27 +419,6 @@ angular.module('openshiftConsole')
419419
return running;
420420
};
421421

422-
$scope.showDebugAction = function(containerStatus) {
423-
if (_.get($scope, 'pod.status.phase') === 'Completed') {
424-
return false;
425-
}
426-
427-
if (annotation($scope.pod, 'openshift.io/build.name')) {
428-
return false;
429-
}
430-
431-
if ($filter('isDebugPod')($scope.pod)) {
432-
return false;
433-
}
434-
435-
var waitingReason = _.get(containerStatus, 'state.waiting.reason');
436-
if (waitingReason === 'ImagePullBackOff' || waitingReason === 'ErrImagePull') {
437-
return false;
438-
}
439-
440-
return !_.get(containerStatus, 'state.running') || !containerStatus.ready;
441-
};
442-
443422
$scope.$on('$destroy', function(){
444423
DataService.unwatchAll(watches);
445424
cleanUpDebugPod();

app/scripts/directives/resources.js

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,80 @@
11
'use strict';
22

33
angular.module('openshiftConsole')
4+
.directive('containerStatuses', function($filter, isContainerFailedFilter) {
5+
return {
6+
restrict: 'E',
7+
scope: {
8+
containerStatuses: '=',
9+
startDebugTerminal: '=?',
10+
detailed: '=?'
11+
},
12+
templateUrl: 'views/_container-statuses.html',
13+
link: function(scope) {
14+
scope.hasDebugTerminal = angular.isFunction(scope.startDebugTerminal);
15+
16+
scope.podContainerStatuses = _.get(scope.containerStatuses, 'status.containerStatuses', []);
17+
scope.podContainerInitStatuses = _.get(scope.containerStatuses, 'status.initContainerStatuses', []);
18+
19+
scope.hasContainerFailed = function (containerStatus) {
20+
return $filter('isContainerFailed')(containerStatus) !== false;
21+
};
22+
23+
scope.showDebugAction = function (containerStatus) {
24+
25+
if (_.get(scope.containerStatuses, 'status.phase') === 'Completed') {
26+
return false;
27+
}
28+
29+
if ($filter('annotation')(scope.containerStatuses, 'openshift.io/build.name')) {
30+
return false;
31+
}
32+
33+
if ($filter('isDebugPod')(scope.containerStatuses)) {
34+
return false;
35+
}
36+
37+
var waitingReason = _.get(containerStatus, 'state.waiting.reason');
38+
if (waitingReason === 'ImagePullBackOff' || waitingReason === 'ErrImagePull') {
39+
return false;
40+
}
41+
42+
return !_.get(containerStatus, 'state.running') || !containerStatus.ready;
43+
};
44+
45+
scope.debugTerminal = function(containerStatusName) {
46+
if (scope.hasDebugTerminal) {
47+
return scope.startDebugTerminal.call(this, containerStatusName);
48+
}
49+
};
50+
51+
scope.expandInitContainer = [];
52+
scope.toggleInitContainer = function(containerIndex) {
53+
scope.expandInitContainer[containerIndex] = !scope.expandInitContainer[containerIndex];
54+
};
55+
}
56+
};
57+
})
58+
/*.directive('containerStatus', function($filter) {
59+
return {
60+
restrict: 'E',
61+
scope: {
62+
containerStatus: '=',
63+
startDebugTerminal: '=?',
64+
labelPrefix: '@?'
65+
},
66+
templateUrl: 'views/_container-statuses.html',
67+
link: function(scope) {
68+
scope.hasDebugTerminal = angular.isFunction(scope.startDebugTerminal);
69+
70+
scope.debugTerminal = function(containerStatusName) {
71+
if (scope.hasDebugTerminal) {
72+
return scope.startDebugTerminal.call(this, containerStatusName);
73+
}
74+
};
75+
}
76+
};
77+
})*/
478
.directive('podTemplate', function() {
579
return {
680
restrict: 'E',
@@ -12,7 +86,27 @@ angular.module('openshiftConsole')
1286
// Optional URL for setting health checks on the resource when missing.
1387
addHealthCheckUrl: '@?'
1488
},
15-
templateUrl: 'views/_pod-template.html'
89+
templateUrl: 'views/_pod-template.html',
90+
link: function(scope) {
91+
scope.containers = _.get(scope.podTemplate, 'spec.containers', []);
92+
scope.initContainers = _.get(scope.podTemplate, 'spec.initContainers', []);
93+
}
94+
};
95+
})
96+
.directive('podTemplateContainer', function() {
97+
return {
98+
restrict: 'E',
99+
scope: {
100+
podTemplateContainer: '=',
101+
imagesByDockerReference: '=',
102+
builds: '=',
103+
detailed: '=?',
104+
labelPrefix: '@?'
105+
},
106+
templateUrl: 'views/_pod-template-container.html',
107+
link: function(scope) {
108+
scope.container = scope.podTemplateContainer;
109+
}
16110
};
17111
})
18112
.directive('annotations', function() {

app/views/_container-statuses.html

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!--
2+
Expects the following variables:
3+
containerStatuses
4+
startDebugTerminal (optional)
5+
detailed (optional)
6+
-->
7+
8+
<div>
9+
10+
<div ng-if="detailed" ng-repeat="containerStatus in podContainerInitStatuses | orderBy:'name'" >
11+
<!--<h4><span ng-bind-template="{{labelPrefix}}"></span> {{containerStatus.name}}</h4>-->
12+
<!--<container-status container-status="containerStatus" label-prefix="Init Container"></container-status>-->
13+
14+
<h4 row ng-init="expandInitContainer[$index] = hasContainerFailed(containerStatus)">
15+
<span flex>Init Container {{containerStatus.name}}</span>
16+
<a flex class="page-header-link" href="" ng-click="toggleInitContainer($index)" ng-if="!expandInitContainer[$index]">Show Details</a>
17+
<a flex class="page-header-link" href="" ng-click="toggleInitContainer($index)" ng-if="expandInitContainer[$index]">Hide Details</a>
18+
</h4>
19+
20+
<dl ng-if="expandInitContainer[$index]" class="dl-horizontal left">
21+
<dt>State:</dt>
22+
<dd>
23+
<kubernetes-object-describe-container-state container-state="containerStatus.state"></kubernetes-object-describe-container-state>
24+
</dd>
25+
<dt ng-if="!(containerStatus.lastState | isEmptyObj)">Last State</dt>
26+
<dd ng-if="!(containerStatus.lastState | isEmptyObj)">
27+
<kubernetes-object-describe-container-state container-state="containerStatus.lastState"></kubernetes-object-describe-container-state>
28+
</dd>
29+
<dt>Ready:</dt>
30+
<dd>{{containerStatus.ready}}</dd>
31+
<dt>Restart Count:</dt>
32+
<dd>{{containerStatus.restartCount}}</dd>
33+
34+
<!-- ToDo: init container status debug disabled, remove "false" to reactivate -->
35+
<div ng-if="false && hasDebugTerminal && showDebugAction(containerStatus) && ('pods' | canI : 'create')" class="debug-pod-action">
36+
<a href="" ng-click="debugTerminal(containerStatus.name)" role="button">Debug in Terminal</a>
37+
</div>
38+
</dl>
39+
</div>
40+
41+
</div>
42+
43+
<div ng-repeat="containerStatus in podContainerStatuses | orderBy:'name'" >
44+
<!--<h4><span ng-bind-template="{{labelPrefix}}:"></span> {{containerStatus.name}}</h4>-->
45+
<!--<container-status container-status="containerStatus" label-prefix="Container" start-debug-terminal="startDebugTerminal"></container-status>-->
46+
47+
<h4>Container {{containerStatus.name}}</h4>
48+
49+
<dl class="dl-horizontal left">
50+
<dt>State:</dt>
51+
<dd>
52+
<kubernetes-object-describe-container-state container-state="containerStatus.state"></kubernetes-object-describe-container-state>
53+
</dd>
54+
<dt ng-if="!(containerStatus.lastState | isEmptyObj)">Last State</dt>
55+
<dd ng-if="!(containerStatus.lastState | isEmptyObj)">
56+
<kubernetes-object-describe-container-state container-state="containerStatus.lastState"></kubernetes-object-describe-container-state>
57+
</dd>
58+
<dt>Ready:</dt>
59+
<dd>{{containerStatus.ready}}</dd>
60+
<dt>Restart Count:</dt>
61+
<dd>{{containerStatus.restartCount}}</dd>
62+
63+
<div ng-if="hasDebugTerminal && showDebugAction(containerStatus) && ('pods' | canI : 'create')" class="debug-pod-action">
64+
<a href="" ng-click="debugTerminal(containerStatus.name)" role="button">Debug in Terminal</a>
65+
</div>
66+
</dl>
67+
</div>
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<!--
2+
Expects the following variables:
3+
podTemplateContainer
4+
imagesByDockerReference (optional)
5+
builds (optional)
6+
detailed (optional)
7+
labelPrefix (optional)
8+
-->
9+
10+
<div class="pod-template">
11+
<div class="component-label"><span ng-bind-template="{{labelPrefix}}:"></span> {{container.name}}</div>
12+
13+
<div row ng-if="container.image" class="pod-template-image icon-row">
14+
<div class="icon-wrap">
15+
<span class="pficon pficon-image" aria-hidden="true"></span>
16+
</div>
17+
<div flex class="word-break">
18+
<span class="pod-template-key">Image:</span>
19+
<span ng-if="!imagesByDockerReference[container.image]">{{container.image | imageStreamName}}</span>
20+
<span ng-if="imagesByDockerReference[container.image]">
21+
<a ng-href="{{imagesByDockerReference[container.image].imageStreamName | navigateResourceURL : 'ImageStream' : imagesByDockerReference[container.image].imageStreamNamespace}}">{{container.image | imageStreamName}}</a>
22+
<span class="hash" title="{{imagesByDockerReference[container.image].metadata.name}}">{{imagesByDockerReference[container.image].metadata.name | stripSHAPrefix | limitTo: 7}}</span>
23+
<span ng-if="imagesByDockerReference[container.image].dockerImageMetadata.Size" class="small text-muted nowrap">
24+
{{imagesByDockerReference[container.image].dockerImageMetadata.Size | humanizeSize}}
25+
</span>
26+
</span>
27+
</div>
28+
</div>
29+
30+
<div ng-if="imagesByDockerReference && container.image && (image = imagesByDockerReference[container.image])" class="pod-template-build">
31+
<div row class="icon-row" ng-if="build = (image | buildForImage : builds)">
32+
<div class="icon-wrap">
33+
<span class="fa fa-refresh" aria-hidden="true"></span>
34+
</div>
35+
<div flex class="word-break">
36+
<span class="pod-template-key">Build:</span>
37+
<span ng-if="build | configURLForResource">
38+
<a ng-href="{{build | configURLForResource}}">{{build | buildConfigForBuild}}</a>,
39+
</span>
40+
<a ng-href="{{build | navigateResourceURL}}">
41+
<span ng-if="(build | annotation : 'buildNumber')">#{{build | annotation : 'buildNumber'}}</span>
42+
<span ng-if="!(build | annotation : 'buildNumber')">{{build.metadata.name}}</span>
43+
</a>
44+
</div>
45+
</div>
46+
<div row class="icon-row" ng-if="build.spec.source">
47+
<div class="icon-wrap">
48+
<span class="fa fa-code" aria-hidden="true"></span>
49+
</div>
50+
<div flex class="word-break">
51+
<span class="pod-template-key">Source:</span>
52+
<span ng-switch="build.spec.source.type">
53+
<span ng-switch-when="Git">
54+
<span ng-if="build.spec.revision.git.commit">
55+
{{build.spec.revision.git.message}}
56+
<osc-git-link
57+
class="hash"
58+
uri="build.spec.source.git.uri"
59+
ref="build.spec.revision.git.commit">{{build.spec.revision.git.commit | limitTo:7}}</osc-git-link>
60+
<span ng-if="detailed && build.spec.revision.git.author">
61+
authored by {{build.spec.revision.git.author.name}}
62+
</span>
63+
</span>
64+
<span ng-if="!build.spec.revision.git.commit">
65+
<osc-git-link uri="build.spec.source.git.uri">{{build.spec.source.git.uri}}</osc-git-link>
66+
</span>
67+
</span>
68+
<span ng-switch-default>
69+
{{build.spec.source.type || 'Unknown'}}
70+
</span>
71+
</span>
72+
</div>
73+
</div>
74+
</div>
75+
76+
<div row ng-if="detailed && (container.command.length || container.args.length)" class="icon-row">
77+
<div class="icon-wrap">
78+
<span aria-hidden="true" class="fa fa-terminal"></span>
79+
</div>
80+
<div flex class="word-break">
81+
<span class="pod-template-key">
82+
Command:
83+
</span>
84+
<span>
85+
<code class="command">
86+
<truncate-long-text
87+
content="container | entrypoint : imagesByDockerReference[container.image]"
88+
limit="80"
89+
newline-limit="1"
90+
expandable="true"
91+
use-word-boundary="false">
92+
</truncate-long-text>
93+
</code>
94+
</span>
95+
</div>
96+
</div>
97+
98+
<div row ng-if="container.ports.length > 0" class="pod-template-ports icon-row">
99+
<div class="icon-wrap">
100+
<span data-icon="" aria-hidden="true" style="font-size:16px;line-height:normal"></span>
101+
</div>
102+
<div flex class="word-break">
103+
<span class="pod-template-key">Ports:</span>
104+
<span ng-repeat="port in container.ports | orderBy: 'containerPort' | limitToOrAll : detailed ? undefined : 1">
105+
<span><span class="nowrap">{{port.containerPort}}/{{port.protocol}}</span>
106+
<span ng-if="port.name"> <span class="nowrap">({{port.name}})</span></span>
107+
<span ng-if="port.hostPort"> <span class="nowrap"><span class="port-icon">&#8594;</span> {{port.hostPort}}</span></span>
108+
</span>
109+
<span ng-if="!$last">, </span>
110+
</span>
111+
<span ng-if="!detailed && container.ports.length >= 2">
112+
and {{container.ports.length - 1}}
113+
<span ng-if="container.ports.length > 2">others</span>
114+
<span ng-if="container.ports.length === 2">other</span>
115+
</span>
116+
</div>
117+
</div>
118+
119+
<div row ng-if="detailed" ng-repeat="mount in container.volumeMounts" class="icon-row">
120+
<div class="icon-wrap">
121+
<span aria-hidden="true" class="fa fa-database"></span>
122+
</div>
123+
<div flex class="word-break">
124+
<span class="pod-template-key">Mount:</span>
125+
<span>
126+
{{mount.name}}<span ng-if="mount.subPath">, subpath {{mount.subPath}}</span>&#8201;&#8594;&#8201;<span>{{mount.mountPath}}</span>
127+
<small class="text-muted">{{mount | volumeMountMode : podTemplate.spec.volumes}}</small>
128+
</span>
129+
</div>
130+
</div>
131+
132+
<div row ng-if="detailed && (container.resources.requests.cpu || container.resources.limits.cpu)" class="icon-row">
133+
<div class="icon-wrap">
134+
<i class="fa fa-area-chart" aria-hidden="true"></i>
135+
</div>
136+
<div flex>
137+
<span class="pod-template-key">CPU:</span>
138+
<span ng-if="container.resources.requests.cpu && container.resources.limits.cpu">
139+
{{container.resources.requests.cpu | usageWithUnits: 'cpu'}} to {{container.resources.limits.cpu | usageWithUnits: 'cpu'}}
140+
</span>
141+
<span ng-if="!container.resources.requests.cpu">
142+
{{container.resources.limits.cpu | usageWithUnits: 'cpu'}} limit
143+
</span>
144+
<span ng-if="!container.resources.limits.cpu">
145+
{{container.resources.requests.cpu | usageWithUnits: 'cpu'}} requested
146+
</span>
147+
</div>
148+
</div>
149+
150+
<div row ng-if="detailed && (container.resources.requests.memory || container.resources.limits.memory)" class="icon-row">
151+
<div class="icon-wrap">
152+
<i class="fa fa-area-chart" aria-hidden="true"></i>
153+
</div>
154+
<div flex>
155+
<span class="pod-template-key">Memory:</span>
156+
<span ng-if="container.resources.requests.memory && container.resources.limits.memory">
157+
{{container.resources.requests.memory | usageWithUnits: 'memory'}} to {{container.resources.limits.memory | usageWithUnits: 'memory'}}
158+
</span>
159+
<span ng-if="!container.resources.requests.memory">
160+
{{container.resources.limits.memory | usageWithUnits: 'memory'}} limit
161+
</span>
162+
<span ng-if="!container.resources.limits.memory">
163+
{{container.resources.requests.memory | usageWithUnits: 'memory'}} requested
164+
</span>
165+
</div>
166+
</div>
167+
168+
<div row ng-if="detailed && container.readinessProbe" class="icon-row">
169+
<div class="icon-wrap">
170+
<i class="fa fa-medkit" aria-hidden="true"></i>
171+
</div>
172+
<div flex>
173+
<span class="pod-template-key">Readiness Probe:</span>
174+
<probe probe="container.readinessProbe"></probe>
175+
</div>
176+
</div>
177+
178+
<div row ng-if="detailed && container.livenessProbe" class="icon-row">
179+
<div class="icon-wrap">
180+
<i class="fa fa-medkit" aria-hidden="true"></i>
181+
</div>
182+
<div flex>
183+
<span class="pod-template-key">Liveness Probe:</span>
184+
<probe probe="container.livenessProbe"></probe>
185+
</div>
186+
</div>
187+
188+
</div>

0 commit comments

Comments
 (0)