Skip to content

Commit

Permalink
fix(provider/cf): fix environment variable definition for CF deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelchio authored and jkschneider committed Oct 17, 2018
1 parent d6ee160 commit c8fae53
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class CloudFoundryServerGroupCommandBuilder {
buildpack: serverGroup.droplet.buildpacks.length > 0 ? serverGroup.droplet.buildpacks[0].name : '',
instances: serverGroup.instances.length,
routes: serverGroup.loadBalancers,
env: serverGroup.env,
environment: [],
services: (serverGroup.serviceInstances || []).map(serviceInstance => serviceInstance.name),
reference: '',
account: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ICloudFoundryManifestDirectSource {
instances: number;
buildpack: string;
routes: string[];
env: ICloudFoundryEnvVar[];
environment: ICloudFoundryEnvVar[];
services: string[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ConfigurationSettingsImpl extends React.Component<ICloudFoundryServerGroup
instances: 1,
buildpack: undefined,
routes: [],
env: [],
environment: [],
services: [],
};
break;
Expand Down Expand Up @@ -129,35 +129,35 @@ class ConfigurationSettingsImpl extends React.Component<ICloudFoundryServerGroup
private addEnvironmentVariable = (): void => {
const { manifest } = this.props.formik.values;
if (isManifestDirectSource(manifest)) {
if (manifest.env === undefined) {
manifest.env = [];
if (manifest.environment === undefined) {
manifest.environment = [];
}
manifest.env.push({ key: '', value: '' });
this.props.formik.setFieldValue('manifest.env', manifest.env);
manifest.environment.push({ key: '', value: '' });
this.props.formik.setFieldValue('manifest.env', manifest.environment);
}
};

private removeEnvironmentVariable = (index: number): void => {
const { manifest } = this.props.formik.values;
if (isManifestDirectSource(manifest)) {
manifest.env.splice(index, 1);
this.props.formik.setFieldValue('manifest.env', manifest.env);
manifest.environment.splice(index, 1);
this.props.formik.setFieldValue('manifest.env', manifest.environment);
}
};

private environmentKeyUpdated = (index: number, event: React.ChangeEvent<HTMLInputElement>): void => {
const { manifest } = this.props.formik.values;
if (isManifestDirectSource(manifest)) {
manifest.env[index].key = event.target.value;
this.props.formik.setFieldValue('manifest.env', manifest.env);
manifest.environment[index].key = event.target.value;
this.props.formik.setFieldValue('manifest.env', manifest.environment);
}
};

private environmentValueUpdated = (index: number, event: React.ChangeEvent<HTMLInputElement>): void => {
const { manifest } = this.props.formik.values;
if (isManifestDirectSource(manifest)) {
manifest.env[index].value = event.target.value;
this.props.formik.setFieldValue('manifest.env', manifest.env);
manifest.environment[index].value = event.target.value;
this.props.formik.setFieldValue('manifest.env', manifest.environment);
}
};

Expand Down Expand Up @@ -316,15 +316,15 @@ class ConfigurationSettingsImpl extends React.Component<ICloudFoundryServerGroup
</tr>
</thead>
<tbody>
{manifest.env &&
manifest.env.map(function(env, index) {
{manifest.environment &&
manifest.environment.map(function(environment, index) {
return (
<tr key={index}>
<td>
<input
className="form-control input-sm"
type="text"
value={env.key}
value={environment.key}
required={true}
onChange={event => environmentKeyUpdated(index, event)}
/>
Expand All @@ -333,7 +333,7 @@ class ConfigurationSettingsImpl extends React.Component<ICloudFoundryServerGroup
<input
className="form-control input-sm"
type="text"
value={env.value}
value={environment.value}
required={true}
onChange={event => environmentValueUpdated(index, event)}
/>
Expand Down Expand Up @@ -650,9 +650,9 @@ class ConfigurationSettingsImpl extends React.Component<ICloudFoundryServerGroup
existingServices[service] = service;
});
}
if (values.manifest.env) {
if (values.manifest.environment) {
const existingKeys: any = {};
values.manifest.env.forEach(function(e) {
values.manifest.environment.forEach(function(e) {
if (!e.key || !e.value) {
errors.manifest = errors.manifest || {};
errors.manifest.env = `An environment variable was not set`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { module, IPromise } from 'angular';

import { defaults } from 'lodash';

import { ICloudFoundryServerGroup } from 'cloudfoundry/domain';
import { ICloudFoundryServerGroup, ICloudFoundryEnvVar } from 'cloudfoundry/domain';

export class CloudFoundryServerGroupTransformer {
public constructor(private $q: ng.IQService) {
Expand All @@ -22,10 +22,26 @@ export class CloudFoundryServerGroupTransformer {
command.cloudProvider = 'cloudfoundry';
command.provider = 'cloudfoundry';
command.account = command.credentials;

delete command.viewState;
delete command.selectedProvider;

if (command.manifest.type === 'direct') {
command.manifest.env = this.convertManifestEnv(command.manifest.environment);
} else {
command.manifest.env = command.manifest.environment;
}

return command;
}

private convertManifestEnv(envVars: ICloudFoundryEnvVar[]): {} {
const newEnv = Object.create(null);
for (const envVar of envVars) {
newEnv[envVar.key] = envVar.value;
}
return newEnv;
}
}

export const CLOUD_FOUNDRY_SERVER_GROUP_TRANSFORMER = 'spinnaker.cloudfoundry.serverGroup.transformer';
Expand Down

0 comments on commit c8fae53

Please sign in to comment.