From 15471ae90b46c912b938c8b6e970b698eb2878bf Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Mon, 30 Jul 2018 13:57:40 -0700 Subject: [PATCH] Clean up eks fields rancher/rancher#14622 --- .../driver-amazoneks/component.js | 200 ++++++++++-------- .../driver-amazoneks/template.hbs | 97 ++++++--- translations/en-us.yaml | 16 +- 3 files changed, 188 insertions(+), 125 deletions(-) diff --git a/lib/shared/addon/components/cluster-driver/driver-amazoneks/component.js b/lib/shared/addon/components/cluster-driver/driver-amazoneks/component.js index 265defd44..9834cb0f2 100644 --- a/lib/shared/addon/components/cluster-driver/driver-amazoneks/component.js +++ b/lib/shared/addon/components/cluster-driver/driver-amazoneks/component.js @@ -4,7 +4,7 @@ import layout from './template'; import { INSTANCE_TYPES, nameFromResource, tagsFromResource } from 'shared/components/node-driver/driver-amazonec2/component'; import { get, set, setProperties, computed } from '@ember/object'; import { Promise, resolve } from 'rsvp'; -import { alias, equal } from '@ember/object/computed'; +import { equal } from '@ember/object/computed'; const REGIONS = ['us-east-1', 'us-west-2']; const RANCHER_GROUP = 'rancher-nodes'; @@ -12,14 +12,11 @@ const RANCHER_GROUP = 'rancher-nodes'; export default Component.extend(ClusterDriver, { layout, configField: 'amazonElasticContainerServiceConfig', - instanceTypes: INSTANCE_TYPES, regionChoices: REGIONS, step: 1, serviceRoles: null, securityGroups: null, - - whichSecurityGroup: 'default', defaultSecurityGroupName: RANCHER_GROUP, errors: null, @@ -27,10 +24,7 @@ export default Component.extend(ClusterDriver, { vpcSubnetMode: 'default', allSecurityGroups: null, selectedServiceRole: null, - - - selectedGroupedDetails: null, - + selectedGroupedDetails: null, isCustomSecurityGroup: equal('whichSecurityGroup', 'custom'), init() { @@ -75,10 +69,20 @@ export default Component.extend(ClusterDriver, { return selectedOptions.push(cap.value); }); - debugger; set(this, 'config.securityGroups', selectedOptions); }, + multiSubnetGroupSelect() { + let options = Array.prototype.slice.call($('.existing-subnet-groups')[0], 0); + let selectedOptions = []; + + options.filterBy('selected', true).forEach((cap) => { + return selectedOptions.push(cap.value); + }); + + set(this, 'config.subnets', selectedOptions); + }, + awsLogin(cb) { setProperties(this, { 'errors': [], @@ -124,17 +128,12 @@ export default Component.extend(ClusterDriver, { } }); - eksRoles.insertAt(0, { - RoleName: '--- select a role ---', - RoleId: null - }); - set(this, 'serviceRoles', eksRoles); set(this, 'step', 2); cb(); }).catch((err) => { get(this, 'errors').pushObject(err); - cb(false); + cb(false, err); }); }, @@ -149,35 +148,74 @@ export default Component.extend(ClusterDriver, { region: get(this, 'config.region'), }; - this.loadNodeDetails(auth).then( () => { + this.loadVpcs(auth).then(() => { set(this, 'step', 3); cb(); }).catch((err) => { get(this, 'errors').pushObject(err); - cb(false); + cb(false, err); }); }, - setVPCSubnet() { - if (get(this, 'selectedGroupedDetails')) { - let subnet = get(this, 'subnets').findBy('subnetId', get(this, 'selectedGroupedDetails')); - let config = get(this, 'config'); - - setProperties(config, { - subnets: [get(subnet, 'subnetId')], - virtualNetwork: get(subnet, 'vpcId') - }); - - set(this, 'allSecurityGroups', this.filterSecurityGroups()); + setVPCS(cb) { + const auth = { + accessKeyId: get(this, 'config.accessKey'), + secretAccessKey: get(this, 'config.secretKey'), + region: get(this, 'config.region'), + }; + this.loadSubnets(auth).then(() => { set(this, 'step', 4); - } else { + + cb(); + }).catch((err) => { + get(this, 'errors').pushObject(err); + cb(false, err); + }); + }, + + setSubnets(cb) { + const auth = { + accessKeyId: get(this, 'config.accessKey'), + secretAccessKey: get(this, 'config.secretKey'), + region: get(this, 'config.region'), + }; + + this.loadSecurityGroups(auth).then(() => { set(this, 'step', 5); - } + + cb(); + }).catch((err) => { + get(this, 'errors').pushObject(err); + cb(false, err); + }); }, }, + filteredSubnets: computed('allSubnets', function() { + return get(this, 'allSubnets').filterBy('VpcId', get(this, 'config.virtualNetwork')).map( (subnet) => { + return { + subnetName: nameFromResource(subnet, 'SubnetId'), + subnetId: subnet.SubnetId, + } + }); + }), + + + filteredVpcs: computed('allVpcs', function() { + return get(this, 'allVpcs').filterBy('State', 'available').map((vpc) => { + return { + id: get(vpc, 'VpcId'), + label: `${ get(vpc, 'VpcId') } (${ get(vpc, 'CidrBlock') })` + }; + }); + }), + + filteredSecurityGroups: computed('allSecurityGroups', function() { + return get(this, 'allSecurityGroups').filterBy('VpcId', get(this, 'config.virtualNetwork')); + }), + readableServiceRole: computed('config.serviceRole', function() { const roles = get(this, 'serviceRoles'); const selectedRole = get(this, 'config.serviceRole'); @@ -187,13 +225,11 @@ export default Component.extend(ClusterDriver, { }), canSaveVPC: computed('vpcSubnetMode', 'selectedGroupedDetails', 'config.virtualNetwork', 'config.subnets.[]', function() { - const mode = get(this, 'vpcSubnetMode'); - const config = get(this, 'config'); - const details = get(this, 'selectedGroupedDetails'); - + const mode = get(this, 'vpcSubnetMode'); + const config = get(this, 'config'); let disabled = true; - if (( mode === 'default' || details ) || ( get(config, 'virtualNetwork') && get(config, 'subnets.length') )) { + if (mode === 'default' || get(config, 'virtualNetwork') ) { disabled = false; } @@ -212,10 +248,6 @@ export default Component.extend(ClusterDriver, { return disabled; }), - filterSecurityGroups() { - return get(this, 'securityGroups').filterBy('VpcId', get(this, 'config.virtualNetwork')); - }, - validate() { const model = get(this, 'cluster'); const errors = model.validationErrors(); @@ -232,6 +264,32 @@ export default Component.extend(ClusterDriver, { return errors.length === 0; }, + loadVpcs(auth) { + return this.listVPCs(auth).then( (resp) => { + let { vpcs } = resp; + + let def = vpcs.findBy('IsDefault'); + + if (def && def.VpcId) { + set(this, 'config.virtualNetwork', get(def, 'VpcId')); + } + + return resolve(set(this, 'allVpcs', vpcs)); + }); + }, + + loadSubnets(auth) { + return this.listSubnets(auth).then( (resp) => { + return resolve(set(this, 'allSubnets', resp)); + }); + }, + + loadSecurityGroups(auth) { + return this.listSecurityGroups(auth).then( (resp) => { + return resolve(set(this, 'allSecurityGroups', resp)); + }); + }, + listRoles(auth) { return new Promise((resolve, reject) => { const IAM = new AWS.IAM(auth); @@ -248,14 +306,14 @@ export default Component.extend(ClusterDriver, { }, listVPCs(auth) { - const ec2 = new AWS.EC2(auth); - const vpcNames = {}; - const vpcTags = {}; - return new Promise((resolve, reject) => { + const ec2 = new AWS.EC2(auth); + const vpcNames = {}; + const vpcTags = {}; + ec2.describeVpcs({}, (err, vpcs) => { if ( err ) { - reject(err) + return reject(err); } vpcs.Vpcs.forEach((vpc) => { @@ -263,18 +321,19 @@ export default Component.extend(ClusterDriver, { vpcTags[vpc.VpcId] = tagsFromResource(vpc); }); - resolve({ + return resolve({ vpcNames, - vpcTags + vpcTags, + vpcs: vpcs.Vpcs }); }); }); }, - listSubnets(auth, vpcNames, vpcTags) { - const ec2 = new AWS.EC2(auth); - const rName = get(this, 'config.region'); - const subnets = []; + listSubnets(auth) { + const ec2 = new AWS.EC2(auth); + const rName = get(this, 'config.region'); + let subnets = []; return new Promise((resolve, reject) => { @@ -285,30 +344,7 @@ export default Component.extend(ClusterDriver, { set(this, `clients.${ rName }`, ec2) - data.Subnets.forEach((subnet) => { - if ( (subnet.State || '').toLowerCase() !== 'available' ) { - return; - } - - subnets.pushObject({ - group: `${ vpcNames[subnet.VpcId] }`, - // groupedname: `${ vpcNames[subnet.VpcId] || subnet.VpcId } - ${ nameFromResource(subnet, 'SubnetId') }`, - subnetName: nameFromResource(subnet, 'SubnetId'), - subnetId: subnet.SubnetId, - subnetTags: tagsFromResource(subnet), - vpcName: vpcNames[subnet.VpcId] || subnet.VpcId, - vpcId: subnet.VpcId, - vpcTags: vpcTags[subnet.VpcId] || [], - zone: subnet.AvailabilityZone, - region: rName - }); - }); - - subnets.insertAt(0, { - subnetName: '--- select a vpc/subnet ---', - subnetId: null - }); - + subnets = data.Subnets; resolve(subnets); }); @@ -328,20 +364,4 @@ export default Component.extend(ClusterDriver, { }); }); }, - - loadNodeDetails(auth) { - return this.listVPCs(auth).then( ( vpcDetails ) => { - const { vpcNames, vpcTags } = vpcDetails; - - return this.listSubnets(auth, vpcNames, vpcTags).then((subnets) => { - set(this, 'subnets', subnets); - - return this.listSecurityGroups(auth).then((groups) => { - set(this, 'securityGroups', groups); - - resolve(); - }); - }); - }); - } }); diff --git a/lib/shared/addon/components/cluster-driver/driver-amazoneks/template.hbs b/lib/shared/addon/components/cluster-driver/driver-amazoneks/template.hbs index 926ea356d..11a7080ab 100644 --- a/lib/shared/addon/components/cluster-driver/driver-amazoneks/template.hbs +++ b/lib/shared/addon/components/cluster-driver/driver-amazoneks/template.hbs @@ -50,9 +50,10 @@ {{#if (eq step 1)}} {{save-cancel + editing=(eq mode 'edit') save="awsLogin" cancel=close - createLabel="nodeDriver.amazonec2.access.next" + createLabel="nodeDriver.amazoneks.access.next" savingLabel="nodeDriver.amazoneks.access.loading" }} {{/if}} @@ -72,7 +73,7 @@ {{#if (eq step 2)}} {{#if (eq serviceRoleMode 'default')}}
-
+