Skip to content
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

Show environment variables coming from the builder image in the Environment tab #889

Merged
merged 1 commit into from
Nov 21, 2016
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
22 changes: 22 additions & 0 deletions app/scripts/controllers/buildConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ angular.module('openshiftConsole')
$filter,
$routeParams,
AlertMessageService,
APIService,
BuildsService,
ImagesService,
DataService,
LabelFilter,
ProjectsService,
Expand All @@ -23,6 +25,7 @@ angular.module('openshiftConsole')
$scope.alerts = {};
$scope.breadcrumbs = [];
$scope.forms = {};
$scope.expand = {imageEnv: false};

if ($routeParams.isPipeline) {
$scope.breadcrumbs.push({
Expand Down Expand Up @@ -99,6 +102,8 @@ angular.module('openshiftConsole')
$scope.forms.bcEnvVars.$setPristine();
};

var lastLoadedBuildFromImageKey;

var buildConfigResolved = function(buildConfig, action) {
$scope.loaded = true;
$scope.buildConfig = buildConfig;
Expand All @@ -110,6 +115,23 @@ angular.module('openshiftConsole')
$scope.imageSourcesPaths.push($filter('destinationSourcePair')(imageSource.paths));
});
}
var buildFrom = _.get(buildStrategy(buildConfig), 'from', {});
// We don't want to reload the image every time the BC updates, only load again if the from changes
var buildFromImageKey = buildFrom.kind + "/" + buildFrom.name + "/" + (buildFrom.namespace || $scope.projectName);
if (lastLoadedBuildFromImageKey !== buildFromImageKey) {
if (_.includes(["ImageStreamTag", "ImageStreamImage"], buildFrom.kind)) {
lastLoadedBuildFromImageKey = buildFromImageKey;
DataService.get(APIService.kindToResource(buildFrom.kind), buildFrom.name, {namespace: buildFrom.namespace || $scope.projectName}, {errorNotification: false}).then(function(imageStreamImage){
$scope.BCEnvVarsFromImage = ImagesService.getEnvironment(imageStreamImage);
}, function() {
// We may not be able to fetch the image info as the end user, don't reveal any errors
$scope.BCEnvVarsFromImage = [];
});
}
else {
$scope.BCEnvVarsFromImage = [];
}
}
copyBuildConfigAndEnsureEnv(buildConfig);
if (action === "DELETED") {
$scope.alerts["deleted"] = {
Expand Down
11 changes: 2 additions & 9 deletions app/scripts/controllers/create/createFromImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ angular.module("openshiftConsole")
HPAService,
QuotaService,
SecretsService,
ImagesService,
TaskList,
failureObjectNameFilter,
$filter,
Expand Down Expand Up @@ -150,15 +151,7 @@ angular.module("openshiftConsole")
var imageName = scope.imageTag;
DataService.get("imagestreamtags", imageStream.metadata.name + ":" + imageName, {namespace: scope.namespace}).then(function(imageStreamTag){
scope.image = imageStreamTag.image;
scope.DCEnvVarsFromImage = _.map(
_.get(imageStreamTag, 'image.dockerImageMetadata.Config.Env'),
function(entry) {
var pair = entry.split('=');
return {
name: _.head(pair),
value:_.last(pair)
};
});
scope.DCEnvVarsFromImage = ImagesService.getEnvironment(imageStreamTag);
var ports = ApplicationGenerator.parsePorts(imageStreamTag.image);
if (ports.length === 0) {
scope.routing.include = false;
Expand Down
26 changes: 25 additions & 1 deletion app/scripts/services/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,34 @@ angular.module("openshiftConsole")
return resources;
};

var getEnvironment = function(imageStreamImage) {
return _.map(_.get(imageStreamImage, 'image.dockerImageMetadata.Config.Env'),
function(entry) {
var ind = entry.indexOf('=');
var key = "";
var value = "";
if (ind > 0) {
key = entry.substring(0, ind);
if (ind + 1 < entry.length) {
value = entry.substring(ind + 1);
}
}
else {
key = entry;
}
return {
name: key,
value: value
};
}
);
};

return {
findImage: findImage,
getVolumes: getVolumes,
runsAsRoot: runsAsRoot,
getResources: getResources
getResources: getResources,
getEnvironment: getEnvironment
};
});
35 changes: 25 additions & 10 deletions app/views/browse/build-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,21 @@ <h3>Triggers</h3>
<uib-tab heading="Environment" active="selectedTab.environment" ng-if="buildConfig && !(buildConfig | isJenkinsPipelineStrategy)">
<uib-tab-heading>Environment</uib-tab-heading>
<h3>Environment Variables</h3>
<div style="margin-top: -5px;" ng-if="BCEnvVarsFromImage.length">
Copy link
Member

Choose a reason for hiding this comment

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

class="mar-top-sm"?

Copy link
Member Author

Choose a reason for hiding this comment

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

its negative margin, i dont think we have a class for applying negative margin?

Copy link
Member

Choose a reason for hiding this comment

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

You're right

The builder image has additional environment variables defined. Variables defined below will overwrite any from the image with the same name.
<a href="" ng-click="expand.imageEnv = true" ng-if="!expand.imageEnv">Show image environment variables</a>
<a href="" ng-click="expand.imageEnv = false" ng-if="expand.imageEnv">Hide image environment variables</a>
</div>
<key-value-editor
ng-if="expand.imageEnv"
entries="BCEnvVarsFromImage"
key-placeholder="Name"
value-placeholder="Value"
is-readonly
cannot-add
cannot-sort
cannot-delete
show-header></key-value-editor>
<ng-form name="forms.bcEnvVars">
<div ng-if="'buildconfigs' | canI : 'update'">
<key-value-editor
Expand All @@ -376,6 +391,16 @@ <h3>Environment Variables</h3>
key-validator-error-tooltip="A valid environment variable name is an alphanumeric (a-z and 0-9) string beginning with a letter that may contain underscores."
add-row-link="Add environment variable"
show-header></key-value-editor>
<key-value-editor
ng-if="!('buildconfigs' | canI : 'update')"
entries="envVars"
key-placeholder="Name"
value-placeholder="Value"
is-readonly
cannot-add
cannot-sort
cannot-delete
show-header></key-value-editor>
<button
class="btn btn-default"
ng-click="saveEnvVars()"
Expand All @@ -387,16 +412,6 @@ <h3>Environment Variables</h3>
class="mar-left-sm"
style="vertical-align: -2px;">Clear changes</a>
</div>
<key-value-editor
ng-if="!('buildconfigs' | canI : 'update')"
entries="envVars"
key-placeholder="Name"
value-placeholder="Value"
is-readonly
cannot-add
cannot-sort
cannot-delete
show-header></key-value-editor>
</ng-form>
</uib-tab>
</uib-tabset>
Expand Down
Loading