Skip to content

Init Containers #1560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions app/scripts/controllers/pod.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,27 +415,6 @@ angular.module('openshiftConsole')
return running;
};

$scope.showDebugAction = function(containerStatus) {
if (_.get($scope, 'pod.status.phase') === 'Completed') {
return false;
}

if (annotation($scope.pod, 'openshift.io/build.name')) {
return false;
}

if ($filter('isDebugPod')($scope.pod)) {
return false;
}

var waitingReason = _.get(containerStatus, 'state.waiting.reason');
if (waitingReason === 'ImagePullBackOff' || waitingReason === 'ErrImagePull') {
return false;
}

return !_.get(containerStatus, 'state.running') || !containerStatus.ready;
};

$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
cleanUpDebugPod();
Expand Down
72 changes: 72 additions & 0 deletions app/scripts/directives/resources.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,65 @@
'use strict';

angular.module('openshiftConsole')
.directive('containerStatuses', function($filter) {
return {
restrict: 'E',
scope: {
pod: '=',
onDebugTerminal: '=?',
detailed: '=?'
},
templateUrl: 'views/_container-statuses.html',
link: function(scope) {
scope.hasDebugTerminal = angular.isFunction(scope.onDebugTerminal);

var isContainerTerminatedSuccessfully = $filter('isContainerTerminatedSuccessfully');
var haveAllContainersTerminatedSuccessfully = function(containerStatuses) {
return _.every(containerStatuses, isContainerTerminatedSuccessfully);
};

scope.$watch('pod', function(updatedPod) {
scope.initContainersTerminated = haveAllContainersTerminatedSuccessfully(updatedPod.status.initContainerStatuses);

if (scope.expandInitContainers !== false) {
scope.expandInitContainers = !scope.initContainersTerminated;
}
});

scope.toggleInitContainer = function() {
scope.expandInitContainers = !scope.expandInitContainers;
};

scope.showDebugAction = function (containerStatus) {

if (_.get(scope.pod, 'status.phase') === 'Completed') {
return false;
}

if ($filter('annotation')(scope.pod, 'openshift.io/build.name')) {
return false;
}

if ($filter('isDebugPod')(scope.pod)) {
return false;
}

var waitingReason = _.get(containerStatus, 'state.waiting.reason');
if (waitingReason === 'ImagePullBackOff' || waitingReason === 'ErrImagePull') {
return false;
}

return !_.get(containerStatus, 'state.running') || !containerStatus.ready;
};

scope.debugTerminal = function(containerStatusName) {
if (scope.hasDebugTerminal) {
return scope.onDebugTerminal.call(this, containerStatusName);
}
};
}
};
})
.directive('podTemplate', function() {
return {
restrict: 'E',
Expand All @@ -15,6 +74,19 @@ angular.module('openshiftConsole')
templateUrl: 'views/_pod-template.html'
};
})
.directive('podTemplateContainer', function() {
return {
restrict: 'E',
scope: {
container: '=podTemplateContainer',
imagesByDockerReference: '=',
builds: '=',
detailed: '=?',
labelPrefix: '@?'
},
templateUrl: 'views/_pod-template-container.html'
};
})
.directive('annotations', function() {
return {
restrict: 'E',
Expand Down
5 changes: 5 additions & 0 deletions app/scripts/filters/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ angular.module('openshiftConsole')
return containerStatus.state.terminated && containerStatus.state.terminated.exitCode !== 0;
};
})
.filter('isContainerTerminatedSuccessfully', function() {
return function(containerStatus) {
return containerStatus.state.terminated && containerStatus.state.terminated.exitCode === 0;
};
})
.filter('isContainerUnprepared', function() {
return function(containerStatus) {
if (!containerStatus.state.running ||
Expand Down
69 changes: 69 additions & 0 deletions app/views/_container-statuses.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about these comments here, these variables are not in the directive scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caught podStatus earlier, should be updated now... if we're going for only listing values/properties/variables used in the templates can adjust accordingly

Expects the following variables:
containerStatuses
onDebugTerminal (optional)
detailed (optional)
-->

<div ng-if="detailed && pod.status.initContainerStatuses.length">
<h4 class="mar-bottom-xl" row ng-if="initContainersTerminated">
<span><i class="fa fa-check text-success"></i></span>
<span flex>
<ng-pluralize count="pod.status.initContainerStatuses.length"
when="{'1': '&nbsp;Init container {{pod.status.initContainerStatuses[0].name}}','other': '&nbsp;{} init containers'}">
</ng-pluralize>
completed successfully
</span>
<span ng-if="initContainersTerminated">
<a class="page-header-link" href="" ng-click="toggleInitContainer()">
<span ng-if="!expandInitContainers">Show</span>
<span ng-if="expandInitContainers">Hide</span>
Details
</a>
</span>
</h4>

<div class="animate-if"
ng-if="expandInitContainers"
ng-repeat="containerStatus in pod.status.initContainerStatuses track by containerStatus.name" >
<h4 class="component-label">Init container {{containerStatus.name}}</h4>

<dl class="dl-horizontal left">
<dt>State:</dt>
<dd>
<kubernetes-object-describe-container-state container-state="containerStatus.state"></kubernetes-object-describe-container-state>
</dd>
<dt ng-if="!(containerStatus.lastState | isEmptyObj)">Last State</dt>
<dd ng-if="!(containerStatus.lastState | isEmptyObj)">
<kubernetes-object-describe-container-state container-state="containerStatus.lastState"></kubernetes-object-describe-container-state>
</dd>
<dt>Ready:</dt>
<dd>{{containerStatus.ready}}</dd>
<dt>Restart Count:</dt>
<dd>{{containerStatus.restartCount}}</dd>
</dl>
</div>
</div>

<div ng-repeat="containerStatus in pod.status.containerStatuses track by containerStatus.name" >
<h4>Container {{containerStatus.name}}</h4>

<dl class="dl-horizontal left">
<dt>State:</dt>
<dd>
<kubernetes-object-describe-container-state container-state="containerStatus.state"></kubernetes-object-describe-container-state>
</dd>
<dt ng-if="!(containerStatus.lastState | isEmptyObj)">Last State</dt>
<dd ng-if="!(containerStatus.lastState | isEmptyObj)">
<kubernetes-object-describe-container-state container-state="containerStatus.lastState"></kubernetes-object-describe-container-state>
</dd>
<dt>Ready:</dt>
<dd>{{containerStatus.ready}}</dd>
<dt>Restart Count:</dt>
<dd>{{containerStatus.restartCount}}</dd>

<div ng-if="hasDebugTerminal && showDebugAction(containerStatus) && ('pods' | canI : 'create')" class="debug-pod-action">
<a href="" ng-click="debugTerminal(containerStatus.name)" role="button">Debug in Terminal</a>
</div>
</dl>
</div>
184 changes: 184 additions & 0 deletions app/views/_pod-template-container.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above re:scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caught initPrefix earlier, should be updated now...

Expects the following variables:
podTemplateContainer
imagesByDockerReference (optional)
builds (optional)
detailed (optional)
labelPrefix (optional)
-->

<div class="pod-template">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirming the view content was moved, but otherwise is unchanged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, close, the template is almost a one to one, added in labelPrefix

<div class="component-label"><span ng-bind-template="{{labelPrefix||'Container'}}:"></span> {{container.name}}</div>

<div row ng-if="container.image" class="pod-template-image icon-row">
<div class="icon-wrap">
<span class="pficon pficon-image" aria-hidden="true"></span>
</div>
<div flex class="word-break">
<span class="pod-template-key">Image:</span>
<span ng-if="!imagesByDockerReference[container.image]">{{container.image | imageStreamName}}</span>
<span ng-if="imagesByDockerReference[container.image]">
<a ng-href="{{imagesByDockerReference[container.image].imageStreamName | navigateResourceURL : 'ImageStream' : imagesByDockerReference[container.image].imageStreamNamespace}}">{{container.image | imageStreamName}}</a>
<span class="hash" title="{{imagesByDockerReference[container.image].metadata.name}}">{{imagesByDockerReference[container.image].metadata.name | stripSHAPrefix | limitTo: 7}}</span>
<span ng-if="imagesByDockerReference[container.image].dockerImageMetadata.Size" class="small text-muted nowrap">
{{imagesByDockerReference[container.image].dockerImageMetadata.Size | humanizeSize}}
</span>
</span>
</div>
</div>

<div ng-if="imagesByDockerReference && container.image && (image = imagesByDockerReference[container.image])" class="pod-template-build">
<div row class="icon-row" ng-if="build = (image | buildForImage : builds)">
<div class="icon-wrap">
<span class="fa fa-refresh" aria-hidden="true"></span>
</div>
<div flex class="word-break">
<span class="pod-template-key">Build:</span>
<span ng-if="build | configURLForResource">
<a ng-href="{{build | configURLForResource}}">{{build | buildConfigForBuild}}</a>,
</span>
<a ng-href="{{build | navigateResourceURL}}">
<span ng-if="(build | annotation : 'buildNumber')">#{{build | annotation : 'buildNumber'}}</span>
<span ng-if="!(build | annotation : 'buildNumber')">{{build.metadata.name}}</span>
</a>
</div>
</div>
<div row class="icon-row" ng-if="build.spec.source">
<div class="icon-wrap">
<span class="fa fa-code" aria-hidden="true"></span>
</div>
<div flex class="word-break">
<span class="pod-template-key">Source:</span>
<span ng-switch="build.spec.source.type">
<span ng-switch-when="Git">
<span ng-if="build.spec.revision.git.commit">
{{build.spec.revision.git.message}}
<osc-git-link
class="hash"
uri="build.spec.source.git.uri"
ref="build.spec.revision.git.commit">{{build.spec.revision.git.commit | limitTo:7}}</osc-git-link>
<span ng-if="detailed && build.spec.revision.git.author">
authored by {{build.spec.revision.git.author.name}}
</span>
</span>
<span ng-if="!build.spec.revision.git.commit">
<osc-git-link uri="build.spec.source.git.uri">{{build.spec.source.git.uri}}</osc-git-link>
</span>
</span>
<span ng-switch-default>
{{build.spec.source.type || 'Unknown'}}
</span>
</span>
</div>
</div>
</div>

<div row ng-if="detailed && (container.command.length || container.args.length)" class="icon-row">
<div class="icon-wrap">
<span aria-hidden="true" class="fa fa-terminal"></span>
</div>
<div flex class="word-break">
<span class="pod-template-key">
Command:
</span>
<span>
<code class="command">
<truncate-long-text
content="container | entrypoint : imagesByDockerReference[container.image]"
limit="80"
newline-limit="1"
expandable="true"
use-word-boundary="false">
</truncate-long-text>
</code>
</span>
</div>
</div>

<div row ng-if="container.ports.length > 0" class="pod-template-ports icon-row">
<div class="icon-wrap">
<span data-icon="" aria-hidden="true" style="font-size:16px;line-height:normal"></span>
</div>
<div flex class="word-break">
<span class="pod-template-key">Ports:</span>
<span ng-repeat="port in container.ports | orderBy: 'containerPort' | limitToOrAll : detailed ? undefined : 1">
<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>
</span>
<span ng-if="!detailed && container.ports.length >= 2">
and {{container.ports.length - 1}}
<span ng-if="container.ports.length > 2">others</span>
<span ng-if="container.ports.length === 2">other</span>
</span>
</div>
</div>

<div row ng-if="detailed" ng-repeat="mount in container.volumeMounts" class="icon-row">
<div class="icon-wrap">
<span aria-hidden="true" class="fa fa-database"></span>
</div>
<div flex class="word-break">
<span class="pod-template-key">Mount:</span>
<span>
{{mount.name}}<span ng-if="mount.subPath">, subpath {{mount.subPath}}</span>&#8201;&#8594;&#8201;<span>{{mount.mountPath}}</span>
<small class="text-muted">{{mount | volumeMountMode : podTemplate.spec.volumes}}</small>
</span>
</div>
</div>

<div row ng-if="detailed && (container.resources.requests.cpu || container.resources.limits.cpu)" class="icon-row">
<div class="icon-wrap">
<i class="fa fa-area-chart" aria-hidden="true"></i>
</div>
<div flex>
<span class="pod-template-key">CPU:</span>
<span ng-if="container.resources.requests.cpu && container.resources.limits.cpu">
{{container.resources.requests.cpu | usageWithUnits: 'cpu'}} to {{container.resources.limits.cpu | usageWithUnits: 'cpu'}}
</span>
<span ng-if="!container.resources.requests.cpu">
{{container.resources.limits.cpu | usageWithUnits: 'cpu'}} limit
</span>
<span ng-if="!container.resources.limits.cpu">
{{container.resources.requests.cpu | usageWithUnits: 'cpu'}} requested
</span>
</div>
</div>

<div row ng-if="detailed && (container.resources.requests.memory || container.resources.limits.memory)" class="icon-row">
<div class="icon-wrap">
<i class="fa fa-area-chart" aria-hidden="true"></i>
</div>
<div flex>
<span class="pod-template-key">Memory:</span>
<span ng-if="container.resources.requests.memory && container.resources.limits.memory">
{{container.resources.requests.memory | usageWithUnits: 'memory'}} to {{container.resources.limits.memory | usageWithUnits: 'memory'}}
</span>
<span ng-if="!container.resources.requests.memory">
{{container.resources.limits.memory | usageWithUnits: 'memory'}} limit
</span>
<span ng-if="!container.resources.limits.memory">
{{container.resources.requests.memory | usageWithUnits: 'memory'}} requested
</span>
</div>
</div>

<div row ng-if="detailed && container.readinessProbe" class="icon-row">
<div class="icon-wrap">
<i class="fa fa-medkit" aria-hidden="true"></i>
</div>
<div flex>
<span class="pod-template-key">Readiness Probe:</span>
<probe probe="container.readinessProbe"></probe>
</div>
</div>

<div row ng-if="detailed && container.livenessProbe" class="icon-row">
<div class="icon-wrap">
<i class="fa fa-medkit" aria-hidden="true"></i>
</div>
<div flex>
<span class="pod-template-key">Liveness Probe:</span>
<probe probe="container.livenessProbe"></probe>
</div>
</div>

</div>
Loading