Skip to content

Commit

Permalink
fix(gce): populate custom instance types in edit deploy stage (#3438)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeach committed Mar 29, 2017
1 parent d80bc3b commit 5fe6a98
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/scripts/modules/core/instance/instanceType.service.ts
Expand Up @@ -19,6 +19,7 @@ export interface IInstanceStorage {

export interface IPreferredInstanceType {
name: string;
nameRegex?: RegExp;
label?: string;
cpu?: number;
memory?: number;
Expand Down Expand Up @@ -85,7 +86,7 @@ export class InstanceTypeService {

private getInstanceTypeCategory(cloudProvider: string, instanceType: string): ng.IPromise<IInstanceTypeCategory> {
return this.getCategories(cloudProvider).then((categories: IInstanceTypeCategory[]) => {
return (categories || []).find(c => c.families.some(f => f.instanceTypes.some(i => i.name === instanceType)));
return (categories || []).find(c => c.families.some(f => f.instanceTypes.some(i => i.name === instanceType || (i.nameRegex && i.nameRegex.test(instanceType)))));
});
}

Expand Down
25 changes: 22 additions & 3 deletions app/scripts/modules/core/instance/instanceTypeService.spec.ts
Expand Up @@ -34,7 +34,7 @@ describe('Service: instanceTypeService', function () {
}]
};

const t2Cateogry: IInstanceTypeCategory = {
const t2Category: IInstanceTypeCategory = {
type: 'micro',
families: [{
type: 't2',
Expand All @@ -45,7 +45,15 @@ describe('Service: instanceTypeService', function () {
}]
};

const categories: IInstanceTypeCategory[] = [m3Category, r3Category, t2Cateogry];
const gceCustomInstanceCategory: IInstanceTypeCategory = {
type: 'buildCustom',
families: [{
type: 'buildCustom',
instanceTypes: [{name: 'buildCustom', nameRegex: /custom-\d{1,2}-\d{4,6}/}]
}]
};

const categories: IInstanceTypeCategory[] = [m3Category, r3Category, t2Category, gceCustomInstanceCategory];

beforeEach(
mock.module(INSTANCE_TYPE_SERVICE)
Expand Down Expand Up @@ -91,7 +99,7 @@ describe('Service: instanceTypeService', function () {
});
});

t2Cateogry.families[0].instanceTypes.forEach(function (instanceType) {
t2Category.families[0].instanceTypes.forEach(function (instanceType) {
it('should return "micro" if the ' + instanceType.name + ' is in the "micro" category', function () {
let result: string = null;
instanceTypeService.getCategoryForInstanceType('aws', instanceType.name).then(function(category) {
Expand All @@ -115,6 +123,17 @@ describe('Service: instanceTypeService', function () {
});
});

const gceBuildCustomTypes = ['custom-1-2816', 'custom-6-9984'];
gceBuildCustomTypes.forEach(function(instanceType) {
it('should return "buildCustom" for ' + instanceType, function() {
let result: string = null;
instanceTypeService.getCategoryForInstanceType('gce', instanceType).then(function(category) {
result = category;
});
$scope.$digest();
expect(result).toBe('buildCustom');
});
});
});
});

Expand Down
Expand Up @@ -176,9 +176,11 @@ module.exports = angular.module('spinnaker.gce.instanceType.service', [ACCOUNT_S
};

var customMachine = {
type: 'buildCustom',
instanceTypes : [
{
name: 'buildCustom',
nameRegex: /custom-\d{1,2}-\d{4,6}/,
storage: {
localSSDSupported: true
}
Expand Down
Expand Up @@ -412,6 +412,7 @@ module.exports = angular.module('spinnaker.gce.serverGroupCommandBuilder.service
useSimpleCapacity: !pipelineCluster.autoscalingPolicy,
mode: 'editPipeline',
submitButtonLabel: 'Done',
customInstance: asyncData.instanceProfile === 'buildCustom' ? gceCustomInstanceBuilderService.parseInstanceTypeString(pipelineCluster.instanceType) : null,
};

var viewOverrides = {
Expand Down

0 comments on commit 5fe6a98

Please sign in to comment.