Clean up eks fields

rancher/rancher#14622
This commit is contained in:
Westly Wright 2018-07-30 13:57:40 -07:00
parent 05408648c3
commit 15471ae90b
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
3 changed files with 188 additions and 125 deletions

View File

@ -4,7 +4,7 @@ import layout from './template';
import { INSTANCE_TYPES, nameFromResource, tagsFromResource } from 'shared/components/node-driver/driver-amazonec2/component'; import { INSTANCE_TYPES, nameFromResource, tagsFromResource } from 'shared/components/node-driver/driver-amazonec2/component';
import { get, set, setProperties, computed } from '@ember/object'; import { get, set, setProperties, computed } from '@ember/object';
import { Promise, resolve } from 'rsvp'; 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 REGIONS = ['us-east-1', 'us-west-2'];
const RANCHER_GROUP = 'rancher-nodes'; const RANCHER_GROUP = 'rancher-nodes';
@ -12,14 +12,11 @@ const RANCHER_GROUP = 'rancher-nodes';
export default Component.extend(ClusterDriver, { export default Component.extend(ClusterDriver, {
layout, layout,
configField: 'amazonElasticContainerServiceConfig', configField: 'amazonElasticContainerServiceConfig',
instanceTypes: INSTANCE_TYPES, instanceTypes: INSTANCE_TYPES,
regionChoices: REGIONS, regionChoices: REGIONS,
step: 1, step: 1,
serviceRoles: null, serviceRoles: null,
securityGroups: null, securityGroups: null,
whichSecurityGroup: 'default', whichSecurityGroup: 'default',
defaultSecurityGroupName: RANCHER_GROUP, defaultSecurityGroupName: RANCHER_GROUP,
errors: null, errors: null,
@ -27,10 +24,7 @@ export default Component.extend(ClusterDriver, {
vpcSubnetMode: 'default', vpcSubnetMode: 'default',
allSecurityGroups: null, allSecurityGroups: null,
selectedServiceRole: null, selectedServiceRole: null,
selectedGroupedDetails: null,
selectedGroupedDetails: null,
isCustomSecurityGroup: equal('whichSecurityGroup', 'custom'), isCustomSecurityGroup: equal('whichSecurityGroup', 'custom'),
init() { init() {
@ -75,10 +69,20 @@ export default Component.extend(ClusterDriver, {
return selectedOptions.push(cap.value); return selectedOptions.push(cap.value);
}); });
debugger;
set(this, 'config.securityGroups', selectedOptions); 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) { awsLogin(cb) {
setProperties(this, { setProperties(this, {
'errors': [], '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, 'serviceRoles', eksRoles);
set(this, 'step', 2); set(this, 'step', 2);
cb(); cb();
}).catch((err) => { }).catch((err) => {
get(this, 'errors').pushObject(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'), region: get(this, 'config.region'),
}; };
this.loadNodeDetails(auth).then( () => { this.loadVpcs(auth).then(() => {
set(this, 'step', 3); set(this, 'step', 3);
cb(); cb();
}).catch((err) => { }).catch((err) => {
get(this, 'errors').pushObject(err); get(this, 'errors').pushObject(err);
cb(false); cb(false, err);
}); });
}, },
setVPCSubnet() { setVPCS(cb) {
if (get(this, 'selectedGroupedDetails')) { const auth = {
let subnet = get(this, 'subnets').findBy('subnetId', get(this, 'selectedGroupedDetails')); accessKeyId: get(this, 'config.accessKey'),
let config = get(this, 'config'); secretAccessKey: get(this, 'config.secretKey'),
region: get(this, 'config.region'),
setProperties(config, { };
subnets: [get(subnet, 'subnetId')],
virtualNetwork: get(subnet, 'vpcId')
});
set(this, 'allSecurityGroups', this.filterSecurityGroups());
this.loadSubnets(auth).then(() => {
set(this, 'step', 4); 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); 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() { readableServiceRole: computed('config.serviceRole', function() {
const roles = get(this, 'serviceRoles'); const roles = get(this, 'serviceRoles');
const selectedRole = get(this, 'config.serviceRole'); const selectedRole = get(this, 'config.serviceRole');
@ -187,13 +225,11 @@ export default Component.extend(ClusterDriver, {
}), }),
canSaveVPC: computed('vpcSubnetMode', 'selectedGroupedDetails', 'config.virtualNetwork', 'config.subnets.[]', function() { canSaveVPC: computed('vpcSubnetMode', 'selectedGroupedDetails', 'config.virtualNetwork', 'config.subnets.[]', function() {
const mode = get(this, 'vpcSubnetMode'); const mode = get(this, 'vpcSubnetMode');
const config = get(this, 'config'); const config = get(this, 'config');
const details = get(this, 'selectedGroupedDetails');
let disabled = true; let disabled = true;
if (( mode === 'default' || details ) || ( get(config, 'virtualNetwork') && get(config, 'subnets.length') )) { if (mode === 'default' || get(config, 'virtualNetwork') ) {
disabled = false; disabled = false;
} }
@ -212,10 +248,6 @@ export default Component.extend(ClusterDriver, {
return disabled; return disabled;
}), }),
filterSecurityGroups() {
return get(this, 'securityGroups').filterBy('VpcId', get(this, 'config.virtualNetwork'));
},
validate() { validate() {
const model = get(this, 'cluster'); const model = get(this, 'cluster');
const errors = model.validationErrors(); const errors = model.validationErrors();
@ -232,6 +264,32 @@ export default Component.extend(ClusterDriver, {
return errors.length === 0; 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) { listRoles(auth) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const IAM = new AWS.IAM(auth); const IAM = new AWS.IAM(auth);
@ -248,14 +306,14 @@ export default Component.extend(ClusterDriver, {
}, },
listVPCs(auth) { listVPCs(auth) {
const ec2 = new AWS.EC2(auth);
const vpcNames = {};
const vpcTags = {};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const ec2 = new AWS.EC2(auth);
const vpcNames = {};
const vpcTags = {};
ec2.describeVpcs({}, (err, vpcs) => { ec2.describeVpcs({}, (err, vpcs) => {
if ( err ) { if ( err ) {
reject(err) return reject(err);
} }
vpcs.Vpcs.forEach((vpc) => { vpcs.Vpcs.forEach((vpc) => {
@ -263,18 +321,19 @@ export default Component.extend(ClusterDriver, {
vpcTags[vpc.VpcId] = tagsFromResource(vpc); vpcTags[vpc.VpcId] = tagsFromResource(vpc);
}); });
resolve({ return resolve({
vpcNames, vpcNames,
vpcTags vpcTags,
vpcs: vpcs.Vpcs
}); });
}); });
}); });
}, },
listSubnets(auth, vpcNames, vpcTags) { listSubnets(auth) {
const ec2 = new AWS.EC2(auth); const ec2 = new AWS.EC2(auth);
const rName = get(this, 'config.region'); const rName = get(this, 'config.region');
const subnets = []; let subnets = [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -285,30 +344,7 @@ export default Component.extend(ClusterDriver, {
set(this, `clients.${ rName }`, ec2) set(this, `clients.${ rName }`, ec2)
data.Subnets.forEach((subnet) => { subnets = data.Subnets;
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
});
resolve(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();
});
});
});
}
}); });

View File

@ -50,9 +50,10 @@
{{#if (eq step 1)}} {{#if (eq step 1)}}
{{save-cancel {{save-cancel
editing=(eq mode 'edit')
save="awsLogin" save="awsLogin"
cancel=close cancel=close
createLabel="nodeDriver.amazonec2.access.next" createLabel="nodeDriver.amazoneks.access.next"
savingLabel="nodeDriver.amazoneks.access.loading" savingLabel="nodeDriver.amazoneks.access.loading"
}} }}
{{/if}} {{/if}}
@ -72,7 +73,7 @@
{{#if (eq step 2)}} {{#if (eq step 2)}}
{{#if (eq serviceRoleMode 'default')}} {{#if (eq serviceRoleMode 'default')}}
<div class="radio"> <div class="radio">
<div class="radio pt-10"> <div class="radio">
<label> <label>
{{radio-button selection=serviceRoleMode value="default"}} {{radio-button selection=serviceRoleMode value="default"}}
{{t 'nodeDriver.amazoneks.role.radio.default'}} {{t 'nodeDriver.amazoneks.role.radio.default'}}
@ -96,8 +97,6 @@
<div> <div>
{{#if config.serviceRole}} {{#if config.serviceRole}}
{{readableServiceRole}} {{readableServiceRole}}
{{!--
{{config.serviceRole}} --}}
{{else}} {{else}}
{{t 'nodeDriver.amazoneks.role.noneSelected'}} {{t 'nodeDriver.amazoneks.role.noneSelected'}}
{{/if}} {{/if}}
@ -129,11 +128,11 @@
}} }}
<div class="row"> <div class="row">
<div class="col span-6"> <div class="col span-6">
<label class="acc-label">{{t 'nodeDriver.amazonec2.subnet'}}</label> <label class="acc-label">{{t 'nodeDriver.amazoneks.vpc.title'}}</label>
{{#if (eq step 3)}} {{#if (eq step 3)}}
{{#if (eq vpcSubnetMode 'default')}} {{#if (eq vpcSubnetMode 'default')}}
<div class="radio"> <div class="radio">
<div class="radio pt-10"> <div class="radio">
<label> <label>
{{radio-button selection=vpcSubnetMode value="default"}} {{radio-button selection=vpcSubnetMode value="default"}}
{{t 'nodeDriver.amazoneks.vpc.radio.default'}} {{t 'nodeDriver.amazoneks.vpc.radio.default'}}
@ -147,11 +146,10 @@
{{else}} {{else}}
{{new-select {{new-select
classNames="form-control" classNames="form-control"
value=selectedGroupedDetails value=config.virtualNetwork
content=subnets content=filteredVpcs
optionValuePath="subnetId" optionValuePath="id"
optionLabelPath="subnetName" optionLabelPath="label"
optionalGroupPath="group"
}} }}
{{/if}} {{/if}}
{{else}} {{else}}
@ -160,35 +158,71 @@
{{t 'nodeDriver.amazoneks.vpc.noneSelected'}} {{t 'nodeDriver.amazoneks.vpc.noneSelected'}}
</div> </div>
{{else}} {{else}}
{{#if config.virtualNetwork}} <div>
<div> {{config.virtualNetwork}}
{{config.virtualNetwork}}: </div>
</div>
{{/if}}
{{#if config.subnets}}
{{#each config.subnets as |subnet index|}}
<span class="ml-10 inline-block">{{subnet}}</span>
{{/each}}
{{/if}}
{{/if}} {{/if}}
{{/if}} {{/if}}
</div> </div>
{{#if (eq step 4)}}
<div class="col span-6">
<label class="acc-label">{{t 'nodeDriver.amazoneks.subnet.title'}}</label>
<select class="form-control existing-subnet-groups" multiple="true" onchange={{action 'multiSubnetGroupSelect' ''}}>
{{#each filteredSubnets as |choice|}}
<option value={{choice.subnetId}} selected={{array-includes config.subnets choice.subnetId}}>{{choice.subnetName}} ({{choice.subnetId}})</option>
{{/each}}
</select>
</div>
{{else}}
{{#if (and (eq vpcSubnetMode "custom") (gte step 4)) }}
<div class="col span-6">
<label class="acc-label">{{t 'nodeDriver.amazoneks.subnet.title'}}</label>
{{#each config.subnets as |sub|}}
<div>{{sub}}</div>
{{/each}}
</div>
{{/if}}
{{/if}}
</div> </div>
{{/accordion-list-item}} {{/accordion-list-item}}
{{#if (eq step 3)}} {{#if (eq step 3)}}
{{#if (eq vpcSubnetMode "default")}}
{{save-cancel
editing=(eq mode 'edit')
saveDisabled=canSaveVPC
save="setVPCS"
cancel="cancel"
createLabel="nodeDriver.amazoneks.vpc.nextRancherDefault"
savingLabel="nodeDriver.amazoneks.vpc.loadingRancherDefault"
}}
{{else}}
{{save-cancel
editing=(eq mode 'edit')
saveDisabled=canSaveVPC
save="setVPCS"
cancel="cancel"
createLabel="nodeDriver.amazoneks.vpc.next"
savingLabel="nodeDriver.amazoneks.vpc.loading"
}}
{{/if}}
{{/if}}
{{#if (eq step 4)}}
{{save-cancel {{save-cancel
saveDisabled=canSaveVPC editing=(eq mode 'edit')
save="setVPCSubnet" saveDisabled=(lte config.subnets.length 0)
save="setSubnets"
cancel="cancel" cancel="cancel"
createLabel="nodeDriver.amazoneks.vpc.next" createLabel="nodeDriver.amazoneks.subnet.next"
savingLabel="nodeDriver.amazonec2.access.loading" savingLabel="nodeDriver.amazoneks.subnet.loading"
}} }}
{{/if}} {{/if}}
{{/if}} {{/if}}
{{#if (and (gte step 4) (eq vpcSubnetMode "custom") )}} {{#if (and (gte step 5) (eq vpcSubnetMode "custom") )}}
{{#accordion-list-item {{#accordion-list-item
title=(t 'nodeDriver.amazoneks.securityGroup.title') title=(t 'nodeDriver.amazoneks.securityGroup.title')
detail=(t 'nodeDriver.amazoneks.securityGroup.detail') detail=(t 'nodeDriver.amazoneks.securityGroup.detail')
@ -198,9 +232,9 @@
expand=(action expandFn) expand=(action expandFn)
}} }}
<div class="row"> <div class="row">
{{#if (eq step 4)}} {{#if (eq step 5)}}
<select class="form-control existing-security-groups" multiple="true" onchange={{action 'multiSecurityGroupSelect' ''}}> <select class="form-control existing-security-groups" multiple="true" onchange={{action 'multiSecurityGroupSelect' ''}}>
{{#each allSecurityGroups as |choice|}} {{#each filteredSecurityGroups as |choice|}}
<option value={{choice.GroupId}} selected={{array-includes config.securityGroups choice.GroupId}}>{{choice.GroupName}} ({{choice.GroupId}})</option> <option value={{choice.GroupId}} selected={{array-includes config.securityGroups choice.GroupId}}>{{choice.GroupName}} ({{choice.GroupId}})</option>
{{/each}} {{/each}}
</select> </select>
@ -214,10 +248,11 @@
</div> </div>
{{/accordion-list-item}} {{/accordion-list-item}}
{{#if (eq step 4)}} {{#if (eq step 5)}}
{{save-cancel {{save-cancel
editing=(eq mode 'edit')
saveDisabled=canSaveSG saveDisabled=canSaveSG
save=(action (mut step) 5) save=(action (mut step) 6)
cancel="cancel" cancel="cancel"
createLabel="nodeDriver.amazonec2.securityGroup.next" createLabel="nodeDriver.amazonec2.securityGroup.next"
savingLabel="nodeDriver.amazonec2.securityGroup.loading" savingLabel="nodeDriver.amazonec2.securityGroup.loading"
@ -225,7 +260,7 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
{{#if (eq step 5)}} {{#if (eq step 6)}}
{{#accordion-list-item {{#accordion-list-item
title=(t 'clusterNew.nodes.title') title=(t 'clusterNew.nodes.title')
detail=(t 'clusterNew.nodes.detail') detail=(t 'clusterNew.nodes.detail')

View File

@ -4687,7 +4687,8 @@ nodeDriver:
templateOptions: "{appName} Template" templateOptions: "{appName} Template"
amazoneks: amazoneks:
access: access:
loading: Loading Instance info from Amazon... next: "Next: Select Service Role"
loading: Loading Service Roles from Amazon...
role: role:
title: Service Roles title: Service Roles
detail: Choose the service role that will be used to launch EKS Instances detail: Choose the service role that will be used to launch EKS Instances
@ -4699,13 +4700,20 @@ nodeDriver:
custom: "Custom: Choose from your existing service roles" custom: "Custom: Choose from your existing service roles"
next: "Next: Select VPC & Subnet" next: "Next: Select VPC & Subnet"
vpc: vpc:
title: VPC/Subnet title: VPC & Subnet
detail: Choose the VPC/Subnet for that will be used for EKS Instances detail: Choose the VPC for that will be used for EKS Instances
next: "Next: Select Security Group" next: "Next: Select Subnets"
loading: "Loading Subnets..."
nextRancherDefault: "Next: Select Instance Options"
loadingRancherDefault: "Loading Instance options..."
noneSelected: "Rancher created VPC and Subnet" noneSelected: "Rancher created VPC and Subnet"
radio: radio:
default: "Standard: Rancher generated VPC and Subnet" default: "Standard: Rancher generated VPC and Subnet"
custom: "Custom: Choose from your existing VPC and Subnets" custom: "Custom: Choose from your existing VPC and Subnets"
subnet:
title: Subnet
next: "Next: Select Security Group"
loading: "Loading Security Groups..."
securityGroup: securityGroup:
title: Security Groups title: Security Groups
detail: Choose the security groups that will be applied to EKS Instances detail: Choose the security groups that will be applied to EKS Instances