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 { 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();
});
});
});
}
});

View File

@ -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')}}
<div class="radio">
<div class="radio pt-10">
<div class="radio">
<label>
{{radio-button selection=serviceRoleMode value="default"}}
{{t 'nodeDriver.amazoneks.role.radio.default'}}
@ -96,8 +97,6 @@
<div>
{{#if config.serviceRole}}
{{readableServiceRole}}
{{!--
{{config.serviceRole}} --}}
{{else}}
{{t 'nodeDriver.amazoneks.role.noneSelected'}}
{{/if}}
@ -129,11 +128,11 @@
}}
<div class="row">
<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 vpcSubnetMode 'default')}}
<div class="radio">
<div class="radio pt-10">
<div class="radio">
<label>
{{radio-button selection=vpcSubnetMode value="default"}}
{{t 'nodeDriver.amazoneks.vpc.radio.default'}}
@ -147,11 +146,10 @@
{{else}}
{{new-select
classNames="form-control"
value=selectedGroupedDetails
content=subnets
optionValuePath="subnetId"
optionLabelPath="subnetName"
optionalGroupPath="group"
value=config.virtualNetwork
content=filteredVpcs
optionValuePath="id"
optionLabelPath="label"
}}
{{/if}}
{{else}}
@ -160,35 +158,71 @@
{{t 'nodeDriver.amazoneks.vpc.noneSelected'}}
</div>
{{else}}
{{#if config.virtualNetwork}}
<div>
{{config.virtualNetwork}}:
</div>
{{/if}}
{{#if config.subnets}}
{{#each config.subnets as |subnet index|}}
<span class="ml-10 inline-block">{{subnet}}</span>
{{/each}}
{{/if}}
<div>
{{config.virtualNetwork}}
</div>
{{/if}}
{{/if}}
</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>
{{/accordion-list-item}}
{{#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
saveDisabled=canSaveVPC
save="setVPCSubnet"
editing=(eq mode 'edit')
saveDisabled=(lte config.subnets.length 0)
save="setSubnets"
cancel="cancel"
createLabel="nodeDriver.amazoneks.vpc.next"
savingLabel="nodeDriver.amazonec2.access.loading"
createLabel="nodeDriver.amazoneks.subnet.next"
savingLabel="nodeDriver.amazoneks.subnet.loading"
}}
{{/if}}
{{/if}}
{{#if (and (gte step 4) (eq vpcSubnetMode "custom") )}}
{{#if (and (gte step 5) (eq vpcSubnetMode "custom") )}}
{{#accordion-list-item
title=(t 'nodeDriver.amazoneks.securityGroup.title')
detail=(t 'nodeDriver.amazoneks.securityGroup.detail')
@ -198,9 +232,9 @@
expand=(action expandFn)
}}
<div class="row">
{{#if (eq step 4)}}
{{#if (eq step 5)}}
<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>
{{/each}}
</select>
@ -214,10 +248,11 @@
</div>
{{/accordion-list-item}}
{{#if (eq step 4)}}
{{#if (eq step 5)}}
{{save-cancel
editing=(eq mode 'edit')
saveDisabled=canSaveSG
save=(action (mut step) 5)
save=(action (mut step) 6)
cancel="cancel"
createLabel="nodeDriver.amazonec2.securityGroup.next"
savingLabel="nodeDriver.amazonec2.securityGroup.loading"
@ -225,7 +260,7 @@
{{/if}}
{{/if}}
{{#if (eq step 5)}}
{{#if (eq step 6)}}
{{#accordion-list-item
title=(t 'clusterNew.nodes.title')
detail=(t 'clusterNew.nodes.detail')

View File

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