Skip to content

Commit c75329e

Browse files
committed
Init Containers Added to Pod Template
Update for pod template directive to allow displaying init containers
1 parent 49f82e8 commit c75329e

File tree

7 files changed

+402
-217
lines changed

7 files changed

+402
-217
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: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,75 @@
11
'use strict';
22

33
angular.module('openshiftConsole')
4+
.directive('containerStatuses', function($filter) {
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.haveContainersFailed = function(containerStatuses) {
24+
25+
var failed = false;
26+
27+
_.forEach(containerStatuses, function(containerStatus) {
28+
if (scope.hasContainerFailed(containerStatus)) {
29+
failed = true;
30+
return false;
31+
}
32+
});
33+
34+
return true;
35+
};
36+
37+
scope.expandInitContainers = scope.initContainersFailed = scope.haveContainersFailed(scope.podContainerInitStatuses);
38+
39+
scope.toggleInitContainer = function() {
40+
scope.expandInitContainers = !scope.expandInitContainers;
41+
};
42+
43+
scope.showDebugAction = function (containerStatus) {
44+
45+
if (_.get(scope.containerStatuses, 'status.phase') === 'Completed') {
46+
return false;
47+
}
48+
49+
if ($filter('annotation')(scope.containerStatuses, 'openshift.io/build.name')) {
50+
return false;
51+
}
52+
53+
if ($filter('isDebugPod')(scope.containerStatuses)) {
54+
return false;
55+
}
56+
57+
var waitingReason = _.get(containerStatus, 'state.waiting.reason');
58+
if (waitingReason === 'ImagePullBackOff' || waitingReason === 'ErrImagePull') {
59+
return false;
60+
}
61+
62+
return !_.get(containerStatus, 'state.running') || !containerStatus.ready;
63+
};
64+
65+
scope.debugTerminal = function(containerStatusName) {
66+
if (scope.hasDebugTerminal) {
67+
return scope.startDebugTerminal.call(this, containerStatusName);
68+
}
69+
};
70+
}
71+
};
72+
})
473
.directive('podTemplate', function() {
574
return {
675
restrict: 'E',
@@ -12,7 +81,27 @@ angular.module('openshiftConsole')
1281
// Optional URL for setting health checks on the resource when missing.
1382
addHealthCheckUrl: '@?'
1483
},
15-
templateUrl: 'views/_pod-template.html'
84+
templateUrl: 'views/_pod-template.html',
85+
link: function(scope) {
86+
scope.containers = _.get(scope.podTemplate, 'spec.containers', []);
87+
scope.initContainers = _.get(scope.podTemplate, 'spec.initContainers', []);
88+
}
89+
};
90+
})
91+
.directive('podTemplateContainer', function() {
92+
return {
93+
restrict: 'E',
94+
scope: {
95+
podTemplateContainer: '=',
96+
imagesByDockerReference: '=',
97+
builds: '=',
98+
detailed: '=?',
99+
labelPrefix: '@?'
100+
},
101+
templateUrl: 'views/_pod-template-container.html',
102+
link: function(scope) {
103+
scope.container = scope.podTemplateContainer;
104+
}
16105
};
17106
})
18107
.directive('annotations', function() {

app/styles/_core.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,9 @@ abbr[data-original-title], abbr[title] {
766766
&.indent {
767767
margin-left: (@grid-gutter-width / 2); // 20px
768768
}
769+
&.margin-bottom-none {
770+
margin-bottom: 0;
771+
}
769772
dd {
770773
&:extend(.clearfix all); // Including this here because it's not being set even though it's in /bootstrap/less/type.less dunno why?
771774
}

app/views/_container-statuses.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--
2+
Expects the following variables:
3+
containerStatuses
4+
startDebugTerminal (optional)
5+
detailed (optional)
6+
-->
7+
8+
<div ng-if="detailed">
9+
<h4 row>
10+
<span><i class="pficon" ng-class="{'pficon-ok': !initContainersFailed}"></i></span>
11+
<span flex>
12+
<span ng-if="!initContainersFailed"> &nbsp;{{podContainerInitStatuses.length}}</span>
13+
<ng-pluralize count="podContainerInitStatuses.length"
14+
when="{'1': 'Init Container','other': 'Init Containers'}">
15+
</ng-pluralize>
16+
<span ng-if="!initContainersFailed">completed successfully</span>
17+
</span>
18+
<a class="page-header-link" href="" ng-click="toggleInitContainer()" ng-if="!expandInitContainers">Show Details</a>
19+
<a class="page-header-link" href="" ng-click="toggleInitContainer()" ng-if="expandInitContainers">Hide Details</a>
20+
</h4>
21+
22+
<div class="pod-template-block"
23+
ng-if="expandInitContainers"
24+
ng-repeat="containerStatus in podContainerInitStatuses | orderBy:'name'" >
25+
26+
<div class="pod-template">
27+
<div class="component-label">Init Container: {{containerStatus.name}}</div>
28+
29+
<div row class="icon-row">
30+
<div flex class="word-break">
31+
<dl class="dl-horizontal left margin-bottom-none">
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+
</div>
48+
</div>
49+
</div>
50+
51+
<div ng-repeat="containerStatus in podContainerStatuses | orderBy:'name'" >
52+
<h4>Container {{containerStatus.name}}</h4>
53+
54+
<dl class="dl-horizontal left">
55+
<dt>State:</dt>
56+
<dd>
57+
<kubernetes-object-describe-container-state container-state="containerStatus.state"></kubernetes-object-describe-container-state>
58+
</dd>
59+
<dt ng-if="!(containerStatus.lastState | isEmptyObj)">Last State</dt>
60+
<dd ng-if="!(containerStatus.lastState | isEmptyObj)">
61+
<kubernetes-object-describe-container-state container-state="containerStatus.lastState"></kubernetes-object-describe-container-state>
62+
</dd>
63+
<dt>Ready:</dt>
64+
<dd>{{containerStatus.ready}}</dd>
65+
<dt>Restart Count:</dt>
66+
<dd>{{containerStatus.restartCount}}</dd>
67+
68+
<div ng-if="hasDebugTerminal && showDebugAction(containerStatus) && ('pods' | canI : 'create')" class="debug-pod-action">
69+
<a href="" ng-click="debugTerminal(containerStatus.name)" role="button">Debug in Terminal</a>
70+
</div>
71+
</dl>
72+
</div>

0 commit comments

Comments
 (0)