Skip to content

Commit

Permalink
fix(amazon/deploy): Do not destroy SpEL based load balancers in deplo…
Browse files Browse the repository at this point in the history
…y config (#5016)
  • Loading branch information
Justin Reynolds committed Mar 19, 2018
1 parent 77bd752 commit be99e7f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, IPromise, IQService } from 'angular';
import { chain, clone, cloneDeep, extend, find, flatten, has, intersection, keys, map, some, xor } from 'lodash';
import { chain, clone, cloneDeep, extend, find, flatten, has, intersection, keys, map, partition, some, xor } from 'lodash';

import {
ACCOUNT_SERVICE,
Expand Down Expand Up @@ -63,6 +63,7 @@ export interface IAmazonServerGroupCommand extends IServerGroupCommand {
targetHealthyDeployPercentage: number;
useAmiBlockDeviceMappings: boolean;
targetGroups: string[];
spelTargetGroups: string[];

getBlockDeviceMappingsSource: () => IBlockDeviceMappingSource;
selectBlockDeviceMappingsSource: (selection: string) => void;
Expand Down Expand Up @@ -462,6 +463,13 @@ export class AwsServerGroupConfigurationService {
return instanceTargetGroups.map((tg) => tg.name).sort();
}

private getValidMatches(all: string[], current: string[]): { valid: string[], invalid: string[], spel: string[] } {
const spel = current.filter((v) => v.includes('${'));
const matched = intersection(all, current);
const [ valid, invalid ] = partition(current, (c) => matched.includes(c) || spel.includes(c));
return { valid, invalid, spel };
}

public configureLoadBalancerOptions(command: IAmazonServerGroupCommand): IServerGroupCommandResult {
const result: IAmazonServerGroupCommandResult = { dirty: {} };
const currentLoadBalancers = (command.loadBalancers || []).concat(command.vpcLoadBalancers || []);
Expand All @@ -471,27 +479,27 @@ export class AwsServerGroupConfigurationService {
const allTargetGroups = this.getTargetGroupNames(command);

if (currentLoadBalancers && command.loadBalancers) {
const valid = command.vpcId ? newLoadBalancers : newLoadBalancers.concat(vpcLoadBalancers);
const matched = intersection(valid, currentLoadBalancers);
const removedLoadBalancers = xor(matched, currentLoadBalancers);
command.loadBalancers = intersection(newLoadBalancers, matched);
const allValidLoadBalancers = command.vpcId ? newLoadBalancers : newLoadBalancers.concat(vpcLoadBalancers);
const { valid, invalid, spel } = this.getValidMatches(allValidLoadBalancers, currentLoadBalancers);
command.loadBalancers = intersection(newLoadBalancers, valid);
if (!command.vpcId) {
command.vpcLoadBalancers = intersection(vpcLoadBalancers, matched);
command.vpcLoadBalancers = intersection(vpcLoadBalancers, valid);
} else {
delete command.vpcLoadBalancers;
}
if (removedLoadBalancers.length) {
result.dirty.loadBalancers = removedLoadBalancers;
if (invalid.length) {
result.dirty.loadBalancers = invalid;
}
command.spelLoadBalancers = spel || [];
}

if (currentTargetGroups && command.targetGroups) {
const matched = intersection(allTargetGroups, currentTargetGroups);
const removedTargetGroups = xor(matched, currentTargetGroups);
command.targetGroups = intersection(allTargetGroups, matched);
if (removedTargetGroups.length) {
result.dirty.targetGroups = removedTargetGroups;
const { valid, invalid, spel } = this.getValidMatches(allTargetGroups, currentTargetGroups);
command.targetGroups = valid;
if (invalid.length) {
result.dirty.targetGroups = invalid;
}
command.spelTargetGroups = spel || [];
}

command.backingData.filtered.loadBalancers = newLoadBalancers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ng-model="$ctrl.command.targetGroups"
class="form-control input-sm">
<ui-select-match>{{$item}}</ui-select-match>
<ui-select-choices repeat="targetGroup in $ctrl.command.backingData.filtered.targetGroups | filter: $select.search">
<ui-select-choices repeat="targetGroup in $ctrl.command.backingData.filtered.targetGroups.concat($ctrl.command.spelTargetGroups) | filter: $select.search">
<span ng-bind-html="targetGroup | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
Expand Down Expand Up @@ -57,7 +57,7 @@
ng-model="$ctrl.command.loadBalancers"
class="form-control input-sm">
<ui-select-match>{{$item}}</ui-select-match>
<ui-select-choices repeat="loadBalancer in $ctrl.command.backingData.filtered.loadBalancers | filter: $select.search">
<ui-select-choices repeat="loadBalancer in $ctrl.command.backingData.filtered.loadBalancers.concat($ctrl.command.spelLoadBalancers) | filter: $select.search">
<span ng-bind-html="loadBalancer | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface IServerGroupCommand extends IServerGroupCommandResult {
};
stack?: string;
moniker?: IMoniker;
spelLoadBalancers: string[];
strategy: string;
subnetType: string;
suspendedProcesses: string[];
Expand Down

0 comments on commit be99e7f

Please sign in to comment.