Skip to content

Commit 07354d6

Browse files
committed
Init Containers Added to Pod Template
Update for pod template directive to allow displaying init containers
1 parent 9c3ecd1 commit 07354d6

File tree

9 files changed

+494
-247
lines changed

9 files changed

+494
-247
lines changed

app/scripts/controllers/pod.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -415,27 +415,6 @@ angular.module('openshiftConsole')
415415
return running;
416416
};
417417

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

app/scripts/directives/resources.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,65 @@
11
'use strict';
22

33
angular.module('openshiftConsole')
4+
.directive('containerStatuses', function($filter) {
5+
return {
6+
restrict: 'E',
7+
scope: {
8+
pod: '=',
9+
onDebugTerminal: '=?',
10+
detailed: '=?'
11+
},
12+
templateUrl: 'views/_container-statuses.html',
13+
link: function(scope) {
14+
scope.hasDebugTerminal = angular.isFunction(scope.onDebugTerminal);
15+
16+
var isContainerTerminatedSuccessfully = $filter('isContainerTerminatedSuccessfully');
17+
var haveAllContainersTerminatedSuccessfully = function(containerStatuses) {
18+
return _.every(containerStatuses, isContainerTerminatedSuccessfully);
19+
};
20+
21+
scope.$watch('pod', function(updatedPod) {
22+
scope.initContainersTerminated = haveAllContainersTerminatedSuccessfully(updatedPod.status.initContainerStatuses);
23+
24+
if (scope.expandInitContainers !== false) {
25+
scope.expandInitContainers = !scope.initContainersTerminated;
26+
}
27+
});
28+
29+
scope.toggleInitContainer = function() {
30+
scope.expandInitContainers = !scope.expandInitContainers;
31+
};
32+
33+
scope.showDebugAction = function (containerStatus) {
34+
35+
if (_.get(scope.containerStatuses, 'status.phase') === 'Completed') {
36+
return false;
37+
}
38+
39+
if ($filter('annotation')(scope.containerStatuses, 'openshift.io/build.name')) {
40+
return false;
41+
}
42+
43+
if ($filter('isDebugPod')(scope.containerStatuses)) {
44+
return false;
45+
}
46+
47+
var waitingReason = _.get(containerStatus, 'state.waiting.reason');
48+
if (waitingReason === 'ImagePullBackOff' || waitingReason === 'ErrImagePull') {
49+
return false;
50+
}
51+
52+
return !_.get(containerStatus, 'state.running') || !containerStatus.ready;
53+
};
54+
55+
scope.debugTerminal = function(containerStatusName) {
56+
if (scope.hasDebugTerminal) {
57+
return scope.onDebugTerminal.call(this, containerStatusName);
58+
}
59+
};
60+
}
61+
};
62+
})
463
.directive('podTemplate', function() {
564
return {
665
restrict: 'E',
@@ -15,6 +74,19 @@ angular.module('openshiftConsole')
1574
templateUrl: 'views/_pod-template.html'
1675
};
1776
})
77+
.directive('podTemplateContainer', function() {
78+
return {
79+
restrict: 'E',
80+
scope: {
81+
container: '=podTemplateContainer',
82+
imagesByDockerReference: '=',
83+
builds: '=',
84+
detailed: '=?',
85+
labelPrefix: '@?'
86+
},
87+
templateUrl: 'views/_pod-template-container.html'
88+
};
89+
})
1890
.directive('annotations', function() {
1991
return {
2092
restrict: 'E',

app/scripts/filters/resources.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ angular.module('openshiftConsole')
314314
return containerStatus.state.terminated && containerStatus.state.terminated.exitCode !== 0;
315315
};
316316
})
317+
.filter('isContainerTerminatedSuccessfully', function() {
318+
return function(containerStatus) {
319+
return containerStatus.state.terminated && containerStatus.state.terminated.exitCode === 0;
320+
};
321+
})
317322
.filter('isContainerUnprepared', function() {
318323
return function(containerStatus) {
319324
if (!containerStatus.state.running ||

app/views/_container-statuses.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!--
2+
Expects the following variables:
3+
containerStatuses
4+
onDebugTerminal (optional)
5+
detailed (optional)
6+
-->
7+
8+
<div ng-if="detailed && pod.status.initContainerStatuses.length">
9+
<h4 class="mar-bottom-xl" row ng-if="initContainersTerminated">
10+
<span><i class="fa fa-check text-success"></i></span>
11+
<span flex>
12+
<ng-pluralize count="pod.status.initContainerStatuses.length"
13+
when="{'1': '&nbsp;Init container {{pod.status.initContainerStatuses[0].name}}','other': '&nbsp;{} init containers'}">
14+
</ng-pluralize>
15+
completed successfully
16+
</span>
17+
<span ng-if="initContainersTerminated">
18+
<a class="page-header-link" href="" ng-click="toggleInitContainer()">
19+
<span ng-if="!expandInitContainers">Show</span>
20+
<span ng-if="expandInitContainers">Hide</span>
21+
Details
22+
</a>
23+
</span>
24+
</h4>
25+
26+
<div class="animate-if"
27+
ng-if="expandInitContainers"
28+
ng-repeat="containerStatus in pod.status.initContainerStatuses track by containerStatus.name" >
29+
<h4 class="component-label">Init container {{containerStatus.name}}</h4>
30+
31+
<dl class="dl-horizontal left">
32+
<dt>State:</dt>
33+
<dd>
34+
<kubernetes-object-describe-container-state container-state="containerStatus.state"></kubernetes-object-describe-container-state>
35+
</dd>
36+
<dt ng-if="!(containerStatus.lastState | isEmptyObj)">Last State</dt>
37+
<dd ng-if="!(containerStatus.lastState | isEmptyObj)">
38+
<kubernetes-object-describe-container-state container-state="containerStatus.lastState"></kubernetes-object-describe-container-state>
39+
</dd>
40+
<dt>Ready:</dt>
41+
<dd>{{containerStatus.ready}}</dd>
42+
<dt>Restart Count:</dt>
43+
<dd>{{containerStatus.restartCount}}</dd>
44+
</dl>
45+
</div>
46+
</div>
47+
48+
<div ng-repeat="containerStatus in pod.status.containerStatuses track by containerStatus.name" >
49+
<h4>Container {{containerStatus.name}}</h4>
50+
51+
<dl class="dl-horizontal left">
52+
<dt>State:</dt>
53+
<dd>
54+
<kubernetes-object-describe-container-state container-state="containerStatus.state"></kubernetes-object-describe-container-state>
55+
</dd>
56+
<dt ng-if="!(containerStatus.lastState | isEmptyObj)">Last State</dt>
57+
<dd ng-if="!(containerStatus.lastState | isEmptyObj)">
58+
<kubernetes-object-describe-container-state container-state="containerStatus.lastState"></kubernetes-object-describe-container-state>
59+
</dd>
60+
<dt>Ready:</dt>
61+
<dd>{{containerStatus.ready}}</dd>
62+
<dt>Restart Count:</dt>
63+
<dd>{{containerStatus.restartCount}}</dd>
64+
65+
<div ng-if="hasDebugTerminal && showDebugAction(containerStatus) && ('pods' | canI : 'create')" class="debug-pod-action">
66+
<a href="" ng-click="debugTerminal(containerStatus.name)" role="button">Debug in Terminal</a>
67+
</div>
68+
</dl>
69+
</div>
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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||'Container'}}:"></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 class="nowrap">{{port.containerPort}}/{{port.protocol}}</span><span ng-if="port.name"><span class="nowrap"> ({{port.name}})</span></span><span ng-if="port.hostPort"><span class="nowrap"><span class="port-icon"> &#8594;</span> {{port.hostPort}}</span></span><span ng-if="!$last">, </span>
106+
</span>
107+
<span ng-if="!detailed && container.ports.length >= 2">
108+
and {{container.ports.length - 1}}
109+
<span ng-if="container.ports.length > 2">others</span>
110+
<span ng-if="container.ports.length === 2">other</span>
111+
</span>
112+
</div>
113+
</div>
114+
115+
<div row ng-if="detailed" ng-repeat="mount in container.volumeMounts" class="icon-row">
116+
<div class="icon-wrap">
117+
<span aria-hidden="true" class="fa fa-database"></span>
118+
</div>
119+
<div flex class="word-break">
120+
<span class="pod-template-key">Mount:</span>
121+
<span>
122+
{{mount.name}}<span ng-if="mount.subPath">, subpath {{mount.subPath}}</span>&#8201;&#8594;&#8201;<span>{{mount.mountPath}}</span>
123+
<small class="text-muted">{{mount | volumeMountMode : podTemplate.spec.volumes}}</small>
124+
</span>
125+
</div>
126+
</div>
127+
128+
<div row ng-if="detailed && (container.resources.requests.cpu || container.resources.limits.cpu)" class="icon-row">
129+
<div class="icon-wrap">
130+
<i class="fa fa-area-chart" aria-hidden="true"></i>
131+
</div>
132+
<div flex>
133+
<span class="pod-template-key">CPU:</span>
134+
<span ng-if="container.resources.requests.cpu && container.resources.limits.cpu">
135+
{{container.resources.requests.cpu | usageWithUnits: 'cpu'}} to {{container.resources.limits.cpu | usageWithUnits: 'cpu'}}
136+
</span>
137+
<span ng-if="!container.resources.requests.cpu">
138+
{{container.resources.limits.cpu | usageWithUnits: 'cpu'}} limit
139+
</span>
140+
<span ng-if="!container.resources.limits.cpu">
141+
{{container.resources.requests.cpu | usageWithUnits: 'cpu'}} requested
142+
</span>
143+
</div>
144+
</div>
145+
146+
<div row ng-if="detailed && (container.resources.requests.memory || container.resources.limits.memory)" class="icon-row">
147+
<div class="icon-wrap">
148+
<i class="fa fa-area-chart" aria-hidden="true"></i>
149+
</div>
150+
<div flex>
151+
<span class="pod-template-key">Memory:</span>
152+
<span ng-if="container.resources.requests.memory && container.resources.limits.memory">
153+
{{container.resources.requests.memory | usageWithUnits: 'memory'}} to {{container.resources.limits.memory | usageWithUnits: 'memory'}}
154+
</span>
155+
<span ng-if="!container.resources.requests.memory">
156+
{{container.resources.limits.memory | usageWithUnits: 'memory'}} limit
157+
</span>
158+
<span ng-if="!container.resources.limits.memory">
159+
{{container.resources.requests.memory | usageWithUnits: 'memory'}} requested
160+
</span>
161+
</div>
162+
</div>
163+
164+
<div row ng-if="detailed && container.readinessProbe" class="icon-row">
165+
<div class="icon-wrap">
166+
<i class="fa fa-medkit" aria-hidden="true"></i>
167+
</div>
168+
<div flex>
169+
<span class="pod-template-key">Readiness Probe:</span>
170+
<probe probe="container.readinessProbe"></probe>
171+
</div>
172+
</div>
173+
174+
<div row ng-if="detailed && container.livenessProbe" class="icon-row">
175+
<div class="icon-wrap">
176+
<i class="fa fa-medkit" aria-hidden="true"></i>
177+
</div>
178+
<div flex>
179+
<span class="pod-template-key">Liveness Probe:</span>
180+
<probe probe="container.livenessProbe"></probe>
181+
</div>
182+
</div>
183+
184+
</div>

0 commit comments

Comments
 (0)