From dc4fa0bd26a7c6ea9a86fe0c95d5fbf68bc3cd9b Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Thu, 18 Jan 2018 17:08:58 -0700 Subject: [PATCH] amazon driver updates --- .../cluster/nodes/configure/template.hbs | 9 +- .../addon/machines/configure/template.hbs | 2 +- .../machine/driver-amazonec2/component.js | 222 ++++++------------ .../machine/driver-amazonec2/template.hbs | 13 +- .../components/modal-add-cluster/template.hbs | 2 +- translations/en-us.yaml | 2 +- 6 files changed, 90 insertions(+), 160 deletions(-) diff --git a/app/authenticated/cluster/nodes/configure/template.hbs b/app/authenticated/cluster/nodes/configure/template.hbs index 7593cc1c0..76c272545 100644 --- a/app/authenticated/cluster/nodes/configure/template.hbs +++ b/app/authenticated/cluster/nodes/configure/template.hbs @@ -1,3 +1,10 @@
- {{add-host allowCustom=(not app.isCaas) model=model driver=driver completed=(action 'completed') goBack=(action 'goBack') cancel=(action 'goBack')}} + {{add-host + allowCustom=false + model=model + driver=driver + completed=(action 'completed') + goBack=(action 'goBack') + cancel=(action 'goBack') + }}
\ No newline at end of file diff --git a/lib/global-admin/addon/machines/configure/template.hbs b/lib/global-admin/addon/machines/configure/template.hbs index ef800a23f..2d66a96da 100644 --- a/lib/global-admin/addon/machines/configure/template.hbs +++ b/lib/global-admin/addon/machines/configure/template.hbs @@ -1,6 +1,6 @@
{{add-host - allowCustom=(not app.isCaas) + allowCustom=false model=model driver=driver completed=(action 'completed') diff --git a/lib/shared/addon/components/machine/driver-amazonec2/component.js b/lib/shared/addon/components/machine/driver-amazonec2/component.js index 36692932e..b17c7dbca 100644 --- a/lib/shared/addon/components/machine/driver-amazonec2/component.js +++ b/lib/shared/addon/components/machine/driver-amazonec2/component.js @@ -1,34 +1,13 @@ import $ from 'jquery'; import { scheduleOnce } from '@ember/runloop'; -import EmberObject, { computed } from '@ember/object'; +import EmberObject, { computed, get, set, setProperties } from '@ember/object'; import { alias, equal, gte } from '@ember/object/computed'; import { inject as service } from '@ember/service'; import Component from '@ember/component'; import Driver from 'shared/mixins/host-driver'; import layout from './template'; -let RANCHER_TAG = 'rancher-ui'; -let RANCHER_GROUP = 'rancher-machine'; -let RANCHER_INGRESS_RULES = [ - { FromPort: 6443, ToPort: 6443, CidrIp: '0.0.0.0/0', IpProtocol: 'tcp' }, // Rancher Cluster manager - { FromPort: -1, ToPort: -1, CidrIp: '0.0.0.0/0', IpProtocol: 'icmp' }, // MTU Path discovery (shouldiblockicmp.com) - - // Docker-machine creates these ports if we don't, - // but explodes with race conditions if you try to deploy 2 hosts simultaneously and they both want to create it. - // So we'll just have the UI create them up front. - { FromPort: 22, ToPort: 22, CidrIp: '0.0.0.0/0', IpProtocol: 'tcp' }, // SSH, to install Docker - { FromPort: 2376, ToPort: 2376, CidrIp: '0.0.0.0/0', IpProtocol: 'tcp' }, // Docker Remote API, for no good reason -]; - -let RANCHER_INTERNAL_RULES = [ -// : 2379,2380 (etcd), 10251 (Scheduler), 10252 (Controller), 10250 (kubelet), 10256 (kubeproxy), 6443 (kubeapi) -// 8472/udp (flannel) - { FromPort: 2379, ToPort: 2380, IpProtocol: 'tcp' }, // etcd - { FromPort: 6443, ToPort: 6443, IpProtocol: 'tcp' }, // cluster manager - { FromPort: 4789, ToPort: 4789, IpProtocol: 'udp' }, // vxlan - { FromPort: 8472, ToPort: 8472, IpProtocol: 'udp' }, // flannel - { FromPort: 10250, ToPort: 10256, IpProtocol: 'tcp' }, // kubelet, scheduler, controller, federation, ingress, readonly kublelet, kubeproxy -]; +let RANCHER_GROUP = 'rancher-nodes'; let INSTANCE_TYPES = [ {group: 'T2 - Burstable', name: 't2.nano'}, @@ -195,19 +174,19 @@ export default Component.extend(Driver, { isGteStep7 : gte('step',7), bootstrap: function() { - let pref = this.get('prefs.amazonec2')||{}; - let config = this.get('globalStore').createRecord({ + let pref = get(this, 'prefs.amazonec2')||{}; + let config = get(this, 'globalStore').createRecord({ type : 'amazonec2Config', region : 'us-west-2', instanceType : 't2.micro', - securityGroup : ['rancher-machine',], + securityGroup : '', zone : 'a', rootSize : '16', accessKey : pref.accessKey||'', secretKey : pref.secretKey||'', }); - this.set('model', this.get('globalStore').createRecord({ + set(this, 'model', get(this, 'globalStore').createRecord({ type: 'machineTemplate', driver: 'amazonec2', amazonec2Config: config @@ -217,30 +196,32 @@ export default Component.extend(Driver, { validate() { let errors = []; - if ( !this.get('model.name') ) { + if ( !get(this, 'model.name') ) { errors.push('Name is required'); } - this.set('errors', errors); + set(this, 'errors', errors); return errors.length === 0; }, init: function() { this._super(...arguments); - this.set('editing', false); - this.set('clients', EmberObject.create()); - this.set('allSubnets', []); + setProperties(this, { + editing: false, + clients: EmberObject.create(), + allSubnets: [] + }) - let cur = this.get('amazonec2Config.securityGroup'); + let cur = get(this, 'amazonec2Config.securityGroup'); - if ( cur.length === 1 && cur[0] === RANCHER_GROUP ) { - this.setProperties({ + if ( cur === '' ) { // TODO 2.0 should this be null 403 Vince/Wes/Daishan + setProperties(this, { whichSecurityGroup : 'default', selectedSecurityGroup : null, }); } else { - this.setProperties({ + setProperties(this, { whichSecurityGroup : 'custom', selectedSecurityGroup : cur, }); @@ -248,7 +229,7 @@ export default Component.extend(Driver, { }, willDestroyElement: function() { - this.setProperties({ + setProperties(this, { step : 1, machineId : null, clients : null, @@ -267,17 +248,19 @@ export default Component.extend(Driver, { actions: { awsLogin: function() { let self = this; - this.set('errors',null); - this.set('step',2); - this.set('amazonec2Config.accessKey', (this.get('amazonec2Config.accessKey')||'').trim()); - this.set('amazonec2Config.secretKey', (this.get('amazonec2Config.secretKey')||'').trim()); + setProperties(this, { + 'errors':null, + 'step':2, + 'amazonec2Config.accessKey': (get(this, 'amazonec2Config.accessKey')||'').trim(), + 'amazonec2Config.secretKey': (get(this, 'amazonec2Config.secretKey')||'').trim(), + }); let subnets = []; - let rName = this.get('amazonec2Config.region'); + let rName = get(this, 'amazonec2Config.region'); let ec2 = new AWS.EC2({ - accessKeyId : this.get('amazonec2Config.accessKey'), - secretAccessKey : this.get('amazonec2Config.secretKey'), + accessKeyId : get(this, 'amazonec2Config.accessKey'), + secretAccessKey : get(this, 'amazonec2Config.secretKey'), region : rName, }); @@ -288,8 +271,10 @@ export default Component.extend(Driver, { if ( err ) { let errors = self.get('errors')||[]; errors.pushObject(err); - this.set('errors', errors); - this.set('step', 1); + setProperties(this, { + 'errors': errors, + 'step': 1 + }); return; } @@ -302,12 +287,14 @@ export default Component.extend(Driver, { if ( err ) { let errors = self.get('errors')||[]; errors.pushObject(err); - this.set('errors', errors); - this.set('step', 1); + setProperties(this, { + 'errors': errors, + 'step': 1 + }); return; } - this.get('clients').set(rName, ec2); + get(this, 'clients').set(rName, ec2); data.Subnets.forEach((subnet) => { if ( (subnet.State||'').toLowerCase() !== 'available' ) @@ -327,39 +314,43 @@ export default Component.extend(Driver, { })); }); - this.set('allSubnets', subnets); - this.set('step', 3); + setProperties(this, { + 'allSubnets': subnets, + 'step': 3 + }); + }); }); }, selectSubnet: function() { - this.set('errors',null); + set(this, 'errors',null); - if ( !this.get('selectedZone') ) { - this.set('errors', ['Select an Availability Zone']); + if ( !get(this, 'selectedZone') ) { + set(this, 'errors', ['Select an Availability Zone']); return; } - if ( !this.get('selectedSubnet') ) { - this.set('errors', ['Select a VPC or Subnet']); + if ( !get(this, 'selectedSubnet') ) { + set(this, 'errors', ['Select a VPC or Subnet']); return; } - this.set('step', 4); + set(this, 'step', 4); - let ec2 = this.get('clients').get(this.get('amazonec2Config.region')); - let filter = {Name: 'vpc-id', Values: [ this.get('amazonec2Config.vpcId')]}; + let ec2 = get(this, 'clients').get(get(this, 'amazonec2Config.region')); + let filter = {Name: 'vpc-id', Values: [ get(this, 'amazonec2Config.vpcId')]}; ec2.describeSecurityGroups({Filters: [filter]}, (err, data) => { if ( err ) { - this.set('errors',[err]); - this.set('step', 3); + setProperties(this, { + 'errors': [err], + 'step': 3 + }); return; } let groups = []; - let defaultGroup = null; data.SecurityGroups.forEach((group) => { let tags = {}; @@ -377,20 +368,17 @@ export default Component.extend(Driver, { id : group.GroupId, name : group.GroupName, description : group.Description, - isDefault : group.GroupName === this.get('defaultSecurityGroupName'), - isRancher : (typeof tags[RANCHER_TAG] !== 'undefined') }; groups.push(obj); - if ( obj.isDefault && !defaultGroup) { - defaultGroup = obj; - } }); - this.set('step', 5); - this.set('allSecurityGroups', groups); - this.set('defaultSecurityGroup', defaultGroup); + setProperties(this, { + 'allSecurityGroups': groups, + 'step': 5 + }); + }); }, @@ -402,83 +390,29 @@ export default Component.extend(Driver, { return selectedOptions.push(cap.value); }); - this.set('selectedSecurityGroup', selectedOptions); + set(this, 'selectedSecurityGroup', selectedOptions); }, selectSecurityGroup: function() { - this.set('errors',null); + set(this, 'errors',null); let self = this; - let ec2 = this.get('clients').get(this.get('amazonec2Config.region')); - if ( this.get('isCustomSecurityGroup') ) { - this.set('amazonec2Config.securityGroup', this.get('selectedSecurityGroup')); + if ( get(this, 'isCustomSecurityGroup') ) { + set(this, 'amazonec2Config.securityGroup', get(this, 'selectedSecurityGroup')); done(); } else { - this.set('step', 6); - this.set('amazonec2Config.securityGroup', [this.get('defaultSecurityGroupName')]); - let group = this.get('defaultSecurityGroup'); - if ( group ) { - if ( group.isRancher ) { - this.set('amazonec2Config.securityGroup', group.name); - done(); - } else { - addRules(group.id, done); - } - } else { - ec2.createSecurityGroup({ - GroupName : this.get('defaultSecurityGroupName'), - Description : `${this.get('settings.appName')} default security group`, - VpcId : this.get('amazonec2Config.vpcId'), - }, function(err, data) { - if ( err ) { - return done(err); - } else { - return addRules(data.GroupId, done); - } - }); - } - } - - function addRules(groupId, cb) { - async.each(RANCHER_INGRESS_RULES, function(item, cb) { - let params = JSON.parse(JSON.stringify(item)); // Don't change the original - params.GroupId = groupId; - ec2.authorizeSecurityGroupIngress(params, cb); - }, function(err) { - if ( err ) { - return cb(err); - } - - async.each(RANCHER_INTERNAL_RULES, function(item, cb) { - let ipPermission = JSON.parse(JSON.stringify(item)); // Don't change the original - ipPermission.UserIdGroupPairs = [ - {GroupId: groupId} - ]; - - let params = { - GroupId: groupId, - IpPermissions: [ipPermission], - } - - params.GroupId = groupId; - ec2.authorizeSecurityGroupIngress(params, cb); - }, function(err) { - if ( err ) { - return cb(err); - } - - ec2.createTags({ - Resources : [groupId], - Tags : [ {Key : RANCHER_TAG, Value : self.get('app.version') }] - }, cb); - }); + setProperties(this, { + 'amazonec2Config.securityGroup': '', + 'step': 6 }); + + done(); } function done(err) { if ( err ) { - this.set('errors', [err]); + set(this, 'errors', [err]); self.set('step', 5); } else { self.set('step', 7); @@ -489,7 +423,7 @@ export default Component.extend(Driver, { selectedZone: computed('amazonec2Config.{region,zone}', { get: function() { - let config = this.get('amazonec2Config'); + let config = get(this, 'amazonec2Config'); if ( config.get('region') && config.get('zone') ) { return config.get('region') + config.get('zone'); } else { @@ -498,15 +432,15 @@ export default Component.extend(Driver, { }, set: function(key, val) { - let config = this.get('amazonec2Config'); + let config = get(this, 'amazonec2Config'); config.setProperties({ region : val.substr(0, val.length - 1), zone : val.substr(val.length - 1), }); - let selectedSubnet = this.get('selectedSubnet'); + let selectedSubnet = get(this, 'selectedSubnet'); - if ( this.get('subnetChoices').filterBy('value', selectedSubnet).length === 0 ) { + if ( get(this, 'subnetChoices').filterBy('value', selectedSubnet).length === 0 ) { config.setProperties({ region : val.substr(0, val.length - 1), zone : val.substr(val.length - 1), @@ -524,9 +458,9 @@ export default Component.extend(Driver, { }), zoneChoices: function() { - const choices = (this.get('allSubnets')||[]).map((subnet) => {return subnet.get('zone');}).sort().uniq(); + const choices = (get(this, 'allSubnets')||[]).map((subnet) => {return subnet.get('zone');}).sort().uniq(); if ( choices.length ) { - this.set('selectedZone', choices[0]); + set(this, 'selectedZone', choices[0]); } return choices; }.property('allSubnets.@each.{zone}'), @@ -535,7 +469,7 @@ export default Component.extend(Driver, { let out = []; let seenVpcs = []; - (this.get('allSubnets')||[]).filterBy('zone', this.get('selectedZone')).forEach((subnet) => { + (get(this, 'allSubnets')||[]).filterBy('zone', get(this, 'selectedZone')).forEach((subnet) => { let vpcName = subnet.get('vpcName'); let vpcId = subnet.get('vpcId'); let vpcTags = subnet.get('vpcTags'); @@ -568,7 +502,7 @@ export default Component.extend(Driver, { selectedSubnet: computed('amazonec2Config.{subnetId,vpcId}', { set: function(key, val) { - let config = this.get('amazonec2Config'); + let config = get(this, 'amazonec2Config'); if ( arguments.length > 1 ) { if ( val && val.length ) { if ( val.indexOf('vpc-') === 0 ) { @@ -595,12 +529,12 @@ export default Component.extend(Driver, { }, get: function() { - let config = this.get('amazonec2Config'); + let config = get(this, 'amazonec2Config'); return config.get('subnetId') || config.get('vpcId'); }, }), subnetById: function(id) { - return (this.get('allSubnets')||[]).filterBy('subnetId',id)[0]; + return (get(this, 'allSubnets')||[]).filterBy('subnetId',id)[0]; }, }); diff --git a/lib/shared/addon/components/machine/driver-amazonec2/template.hbs b/lib/shared/addon/components/machine/driver-amazonec2/template.hbs index 933a36326..f2ea5715a 100644 --- a/lib/shared/addon/components/machine/driver-amazonec2/template.hbs +++ b/lib/shared/addon/components/machine/driver-amazonec2/template.hbs @@ -191,11 +191,7 @@
@@ -216,13 +212,6 @@ {{/each}} - -

{{t 'machine.driverAmazon.needs.label' appName=settings.appName}}

- {{/if}} {{else}}
@@ -233,7 +222,7 @@ {{/each}}
{{else}} - {{amazonec2Config.securityGroup}} + {{defaultSecurityGroupName}} {{/if}} {{/if}} diff --git a/lib/shared/addon/components/modal-add-cluster/template.hbs b/lib/shared/addon/components/modal-add-cluster/template.hbs index e95eab635..6e220cd5b 100644 --- a/lib/shared/addon/components/modal-add-cluster/template.hbs +++ b/lib/shared/addon/components/modal-add-cluster/template.hbs @@ -19,7 +19,7 @@ }} {{else if (eq mode 'add')}} {{add-host - allowCustom=(not app.isCaas) + allowCustom=false model=addHostModel.model driver=driver cluster=cluster diff --git a/translations/en-us.yaml b/translations/en-us.yaml index e7c023f07..7f2e92c09 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -3243,7 +3243,7 @@ machine: securityGroup: label: Security Group choose: Choose an existing group - defaultExisting: "Standard: Use the existing {groupName} group" + defaultExisting: "Standard: Use the existing rancher-nodes group" defaultCreate: "Standard: Automatically create a {groupName} group" custom: "Custom: Choose an existing group" updating: Updating Security Group...