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

Add support for GCE subnets. #2000

Merged
merged 2 commits into from
Feb 22, 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
2 changes: 1 addition & 1 deletion app/scripts/modules/amazon/aws.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = angular.module('spinnaker.aws', [
require('../core/pipeline/config/stages/resizeAsg/aws/awsResizeAsgStage.js'),
require('../core/pipeline/config/stages/scaleDownCluster/aws/awsScaleDownClusterStage.js'),
require('../core/pipeline/config/stages/shrinkCluster/aws/awsShrinkClusterStage.js'),
require('../core/subnet/subnet.module.js'),
require('./serverGroup/details/serverGroup.details.module.js'),
require('./serverGroup/serverGroup.transformer.js'),
require('./serverGroup/configure/wizard/CloneServerGroup.aws.controller.js'),
Expand All @@ -37,7 +38,6 @@ module.exports = angular.module('spinnaker.aws', [
require('./securityGroup/configure/EditSecurityGroupCtrl.js'),
require('./securityGroup/securityGroup.transformer.js'),
require('./securityGroup/securityGroup.reader.js'),
require('./subnet/subnet.module.js'),
require('./validation/applicationName.validator.js'),
require('./vpc/vpc.module.js'),
require('./image/image.reader.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = angular.module('spinnaker.aws.cache.initializer', [
require('../../core/loadBalancer/loadBalancer.read.service.js'),
require('../../core/instance/instanceTypeService.js'),
require('../../core/securityGroup/securityGroup.read.service.js'),
require('../subnet/subnet.read.service.js'),
require('../../core/subnet/subnet.read.service.js'),
require('../vpc/vpc.read.service.js'),
])
.factory('awsCacheConfigurer', function ($q,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = angular.module('spinnaker.loadBalancer.aws.create.controller',
require('../../../core/securityGroup/securityGroup.read.service.js'),
require('../../../core/modal/wizard/v2modalWizard.service.js'),
require('../../../core/task/monitor/taskMonitorService.js'),
require('../../subnet/subnet.read.service.js'),
require('../../../core/subnet/subnet.read.service.js'),
require('../../../core/cache/cacheInitializer.js'),
require('../../../core/cache/infrastructureCaches.js'),
require('../../../core/naming/naming.service.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let angular = require('angular');
module.exports = angular.module('spinnaker.aws.serverGroupCommandBuilder.service', [
require('exports?"restangular"!imports?_=lodash!restangular'),
require('../../../core/account/account.service.js'),
require('../../subnet/subnet.read.service.js'),
require('../../../core/subnet/subnet.read.service.js'),
require('../../../core/instance/instanceTypeService.js'),
require('../../../core/naming/naming.service.js'),
require('./serverGroupConfiguration.service.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = angular.module('spinnaker.aws.serverGroup.configure.service', [
require('../../../core/account/account.service.js'),
require('../../../core/naming/naming.service.js'),
require('../../../core/securityGroup/securityGroup.read.service.js'),
require('../../../core/subnet/subnet.read.service.js'),
require('../../instance/awsInstanceType.service.js'),
require('../../subnet/subnet.read.service.js'),
require('../../keyPairs/keyPairs.read.service.js'),
require('../../../core/loadBalancer/loadBalancer.read.service.js'),
require('../../../core/cache/cacheInitializer.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = angular.module('spinnaker.core.forms.checkmap.checkmap.directiv

scope.updateSelectedItems = updateSelectedItems;

scope.$watch('itemMap', initializeModelHolder);
scope.$watch('selectedItems', initializeModelHolder);
}
};
Expand Down
6 changes: 6 additions & 0 deletions app/scripts/modules/core/help/helpContents.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let angular = require('angular');
module.exports = angular
.module('spinnaker.subnet.read.service', [
require('exports?"restangular"!imports?_=lodash!restangular'),
require('../../core/cache/infrastructureCaches.js')
require('../cache/infrastructureCaches.js')
])
.factory('subnetReader', function (Restangular, infrastructureCaches) {

Expand All @@ -25,8 +25,15 @@ module.exports = angular
});
}

function listSubnetsByProvider(cloudProvider) {
return Restangular.one('subnets', cloudProvider)
.withHttpConfig({cache: infrastructureCaches.subnets})
.getList();
}

return {
listSubnets: listSubnets
listSubnets: listSubnets,
listSubnetsByProvider: listSubnetsByProvider,
};

});
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ module.exports = angular
let accountFilter = (cluster) => cluster.account === vm.component.credentials;
let zoneList = appListExtractorService.getZonesByRegion([vm.application], accountFilter);
vm.zones = Object.keys(zoneList).length ? zoneList : zones;

// Deselect any zones that are not included in the filtered list.
let flattenedZoneList = _(vm.zones)
.map()
.flatten()
.value();
vm.component.zones = _.filter(vm.component.zones, zone => {
return _.includes(flattenedZoneList, zone);
});
};

let setClusterList = () => {
Expand Down
15 changes: 13 additions & 2 deletions app/scripts/modules/google/cache/cacheConfigurer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ let angular = require('angular');

module.exports = angular.module('spinnaker.gce.cache.initializer', [
require('../../core/account/account.service.js'),
require('../../core/loadBalancer/loadBalancer.read.service.js'),
require('../../core/instance/instanceTypeService.js'),
require('../../core/loadBalancer/loadBalancer.read.service.js'),
require('../../core/network/network.read.service.js'),
require('../../core/securityGroup/securityGroup.read.service.js'),
require('../../core/subnet/subnet.read.service.js'),
])
.factory('gceCacheConfigurer', function (accountService, instanceTypeService, loadBalancerReader) {
.factory('gceCacheConfigurer', function (accountService, instanceTypeService, loadBalancerReader,
networkReader, subnetReader) {

let config = Object.create(null);

Expand All @@ -24,5 +27,13 @@ module.exports = angular.module('spinnaker.gce.cache.initializer', [
initializers: [ () => loadBalancerReader.listLoadBalancers('gce') ],
};

config.networks = {
initializers: [ () => networkReader.listNetworksByProvider('gce') ],
};

config.subnets = {
initializers: [ () => subnetReader.listSubnetsByProvider('gce') ],
};

return config;
});
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ module.exports = angular.module('spinnaker.instance.detail.gce.controller', [
$scope.instance.internalIpAddress = $scope.instance.networkInterfaces[0].networkIP;
$scope.instance.externalIpAddress = $scope.instance.networkInterfaces[0].accessConfigs[0].natIP;
$scope.instance.network = getNetwork();
$scope.instance.subnet = getSubnet();

$scope.instance.sshLink =
$scope.instance.selfLink.replace('www.googleapis.com/compute/v1', 'cloudssh.developers.google.com') + '?authuser=0&hl=en_US';
Expand Down Expand Up @@ -188,12 +189,13 @@ module.exports = angular.module('spinnaker.instance.detail.gce.controller', [
}

function getNetwork() {
if ($scope.instance.networkInterfaces[0].network) {
var networkUrl = $scope.instance.networkInterfaces[0].network;
let networkUrl = _.get($scope.instance, 'networkInterfaces[0].network');
return networkUrl ? _.last(networkUrl.split('/')) : null;
}

return _.last(networkUrl.split('/'));
}
return null;
function getSubnet() {
let subnetUrl = _.get($scope.instance, 'networkInterfaces[0].subnetwork');
return subnetUrl ? _.last(subnetUrl.split('/')) : null;
}

this.canRegisterWithLoadBalancer = function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ <h3 select-on-dbl-click>
</dd>
<dt>Network</dt>
<dd>{{instance.network || '(Unknown)'}}</dd>
<dt ng-if="instance.subnet">Subnet</dt>
<dd ng-if="instance.subnet">{{instance.subnet}}</dd>
</dl>
</collapsible-section>
<collapsible-section heading="Status" expanded="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ module.exports = angular.module('spinnaker.gce.serverGroupCommandBuilder.service
}

function extractNetworkName(serverGroup) {
if (_.has(serverGroup, 'launchConfig.instanceTemplate.properties.networkInterfaces')) {
var networkInterfaces = serverGroup.launchConfig.instanceTemplate.properties.networkInterfaces;
if (networkInterfaces.length === 1) {
var networkUrl = networkInterfaces[0].network;
return _.last(networkUrl.split('/'));
}
}
return null;
let networkUrl = _.get(serverGroup, 'launchConfig.instanceTemplate.properties.networkInterfaces[0].network');
return networkUrl ? _.last(networkUrl.split('/')) : null;
}

function extractSubnetName(serverGroup) {
let subnetworkUrl = _.get(serverGroup, 'launchConfig.instanceTemplate.properties.networkInterfaces[0].subnetwork');
return subnetworkUrl ? _.last(subnetworkUrl.split('/')) : null;
}

function populateDisksFromExisting(disks, command) {
Expand Down Expand Up @@ -271,6 +270,7 @@ module.exports = angular.module('spinnaker.gce.serverGroupCommandBuilder.service
},
zone: serverGroup.zones[0],
network: extractNetworkName(serverGroup),
subnet: extractSubnetName(serverGroup),
instanceMetadata: [],
tags: [],
availabilityZones: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
require('../../../core/cache/cacheInitializer.js'),
require('../../../core/loadBalancer/loadBalancer.read.service.js'),
require('../../../core/network/network.read.service.js'),
require('../../../core/subnet/subnet.read.service.js'),
require('../../image/image.reader.js'),
require('../../instance/gceInstanceTypeService.js'),
])
.factory('gceServerGroupConfigurationService', function(gceImageReader, accountService, securityGroupReader,
gceInstanceTypeService, cacheInitializer,
$q, loadBalancerReader, networkReader, _) {
$q, loadBalancerReader, networkReader, subnetReader, _) {

var persistentDiskTypes = [
'pd-standard',
Expand Down Expand Up @@ -57,6 +58,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
regionsKeyedByAccount: accountService.getRegionsKeyedByAccount('gce'),
securityGroups: securityGroupReader.getAllSecurityGroups(),
networks: networkReader.listNetworksByProvider('gce'),
subnets: subnetReader.listSubnetsByProvider('gce'),
loadBalancers: loadBalancerReader.listLoadBalancers('gce'),
packageImages: imageLoader,
instanceTypes: gceInstanceTypeService.getAllTypesByRegion(),
Expand Down Expand Up @@ -177,8 +179,18 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
}

function configureZones(command) {
command.backingData.filtered.zones =
var result = { dirty: {} };
var filteredData = command.backingData.filtered;
if (command.region === null) {
return result;
}
filteredData.zones =
command.backingData.regionsKeyedByAccount[command.credentials].regions[command.region];
if (!_(filteredData.zones).contains(command.zone)) {
command.zone = "";
result.dirty.zone = true;
}
return result;
}

function getLoadBalancerNames(command) {
Expand Down Expand Up @@ -231,6 +243,24 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
});
}

function configureSubnets(command) {
var result = { dirty: {} };
var filteredData = command.backingData.filtered;
if (command.region === null) {
return result;
}
filteredData.subnets = _(command.backingData.subnets)
.filter({ account: command.credentials, network: command.network, region: command.region })
.pluck('name')
.valueOf();

if (!_(filteredData.subnets).contains(command.subnet)) {
command.subnet = "";
result.dirty.subnet = true;
}
return result;
}

function getSecurityGroups(command) {
var newSecurityGroups = command.backingData.securityGroups[command.credentials] || { gce: {}};
newSecurityGroups = _.filter(newSecurityGroups.gce.global, function(securityGroup) {
Expand Down Expand Up @@ -321,11 +351,10 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
command.regionChanged = function regionChanged() {
var result = { dirty: {} };
var filteredData = command.backingData.filtered;
angular.extend(result.dirty, configureSubnets(command).dirty);
if (command.region) {
angular.extend(result.dirty, configureInstanceTypes(command).dirty);

configureZones(command);

angular.extend(result.dirty, configureZones(command).dirty);
angular.extend(result.dirty, configureLoadBalancerOptions(command).dirty);
angular.extend(result.dirty, configureImages(command).dirty);
} else {
Expand All @@ -334,7 +363,6 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati

command.viewState.dirty = command.viewState.dirty || {};
angular.extend(command.viewState.dirty, result.dirty);

return result;
};

Expand Down Expand Up @@ -370,6 +398,17 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
command.networkChanged = function networkChanged() {
var result = { dirty: {} };

command.viewState.autoCreateSubnets = _(command.backingData.networks)
.filter({ account: command.credentials, name: command.network })
.pluck('autoCreateSubnets')
.head();

command.viewState.subnets = _(command.backingData.networks)
.filter({ account: command.credentials, name: command.network })
.pluck('subnets')
.head();

angular.extend(result.dirty, configureSubnets(command).dirty);
angular.extend(result.dirty, configureSecurityGroupOptions(command).dirty);

command.viewState.dirty = command.viewState.dirty || {};
Expand All @@ -384,6 +423,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.configurati
configureInstanceTypes: configureInstanceTypes,
configureImages: configureImages,
configureZones: configureZones,
configureSubnets: configureSubnets,
configureLoadBalancerOptions: configureLoadBalancerOptions,
refreshLoadBalancers: refreshLoadBalancers,
refreshSecurityGroups: refreshSecurityGroups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.cloneServer
processCommandUpdateResult($scope.command.credentialsChanged());
processCommandUpdateResult($scope.command.regionChanged());
processCommandUpdateResult($scope.command.networkChanged());
gceServerGroupConfigurationService.configureSubnets($scope.command);
}

function createResultProcessor(method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.basicSettin
require('../../../gceRegionSelectField.directive.js'),
require('../../../gceZoneSelectField.directive.js'),
require('../../../gceNetworkSelectField.directive.js'),
require('../../../subnet/subnetSelectField.directive.js'),
])
.controller('gceServerGroupBasicSettingsCtrl', function($scope, $controller, $uibModalStack, $state,
v2modalWizardService, rx, imageReader, namingService) {
Expand Down Expand Up @@ -84,6 +85,18 @@ module.exports = angular.module('spinnaker.serverGroup.configure.gce.basicSettin
}
};

this.getSubnetPlaceholder = () => {
if (!$scope.command.region) {
return '(Select an account)';
} else if ($scope.command.viewState.autoCreateSubnets) {
return '(Subnet will be automatically selected)';
} else if ($scope.command.viewState.autoCreateSubnets === null) {
return '(Subnets not supported)';
} else {
return null;
}
};

$scope.$watch('form.$valid', function(newVal) {
if (newVal) {
v2modalWizardService.markClean('location');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
<gce-region-select-field label-columns="3" component="command" field="region" account="command.credentials" regions="command.backingData.filtered.regions"></gce-region-select-field>
<gce-zone-select-field label-columns="3" component="command" field="zone" account="command.credentials" zones="command.backingData.filtered.zones"></gce-zone-select-field>
<gce-network-select-field label-columns="3" component="command" field="network" account="command.credentials" networks="command.backingData.filtered.networks"></gce-network-select-field>
<gce-subnet-select-field label-columns="3"
help-key="gce.serverGroup.subnet"
component="command"
field="subnet"
account="command.credentials"
region="command.region"
subnets="command.backingData.filtered.subnets"
subnet-placeholder="basicSettingsCtrl.getSubnetPlaceholder()"
auto-create-subnets="command.viewState.autoCreateSubnets">
</gce-subnet-select-field>

<div class="form-group">
<div class="col-md-3 sm-label-right">
Expand Down
Loading