Skip to content

Commit

Permalink
fix(gce): fix backendservice for internalhttplb is not handled correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
takaaki7 committed Sep 2, 2020
1 parent 0de610e commit 3e8a522
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ angular
}, []);
}

function extractBackendServices(asg) {
return ['backend-service-names', 'region-backend-service-names'].reduce((backendServices, property) => {
if (asg[property]) {
backendServices = backendServices.concat(asg[property]);
}
return backendServices;
}, []);
}

function extractLoadBalancersFromMetadata(metadata) {
return ['load-balancer-names', 'global-load-balancer-names'].reduce((loadBalancers, property) => {
if (metadata[property]) {
Expand Down Expand Up @@ -423,7 +432,7 @@ angular
credentials: serverGroup.account,
loadBalancers: extractLoadBalancers(serverGroup.asg),
loadBalancingPolicy: _.cloneDeep(serverGroup.loadBalancingPolicy),
backendServiceMetadata: serverGroup.asg['backend-service-names'],
backendServiceMetadata: extractBackendServices(serverGroup.asg),
securityGroups: serverGroup.securityGroups,
region: serverGroup.region,
capacity: {
Expand Down Expand Up @@ -567,6 +576,12 @@ angular
extendedCommand.backendServiceMetadata = instanceMetadata['backend-service-names']
? instanceMetadata['backend-service-names'].split(',')
: [];

if (instanceMetadata['region-backend-service-names']) {
extendedCommand.backendServiceMetadata = extendedCommand.backendServiceMetadata.concat(
instanceMetadata['region-backend-service-names'].split(','),
);
}
extendedCommand.minCpuPlatform = pipelineCluster.minCpuPlatform || '(Automatic)';
extendedCommand.instanceMetadata = {};
populateCustomMetadata(instanceMetadata, extendedCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,41 +275,45 @@ angular
return ModalWizard.allPagesVisited();
};

function buildLoadBalancerMetadata(loadBalancerNames, loadBalancerIndex, backendServices) {
let metadata = {};
function buildLoadBalancerMetadata(loadBalancerNames, loadBalancerIndex) {
let metadata = {
'load-balancer-names': [],
'global-load-balancer-names': [],
'backend-service-names': [],
'region-backend-service-names': [],
};

if (_.get(loadBalancerNames, 'length') > 0) {
metadata = loadBalancerNames.reduce(
(metadata, name) => {
const loadBalancerDetails = loadBalancerIndex[name];

if (loadBalancerDetails.loadBalancerType === 'HTTP') {
metadata['global-load-balancer-names'] = metadata['global-load-balancer-names'].concat(
loadBalancerDetails.listeners.map(listener => listener.name),
);
} else if (loadBalancerDetails.loadBalancerType === 'INTERNAL_MANAGED') {
metadata['load-balancer-names'] = metadata['load-balancer-names'].concat(
loadBalancerDetails.listeners.map(listener => listener.name),
);
} else if (loadBalancerDetails.loadBalancerType === 'SSL') {
metadata['global-load-balancer-names'].push(name);
} else if (loadBalancerDetails.loadBalancerType === 'TCP') {
metadata['global-load-balancer-names'].push(name);
} else {
metadata['load-balancer-names'].push(name);
}
return metadata;
},
{ 'load-balancer-names': [], 'global-load-balancer-names': [] },
);
}
metadata = loadBalancerNames.reduce((metadata, name) => {
const loadBalancerDetails = loadBalancerIndex[name];

if (loadBalancerDetails.loadBalancerType === 'HTTP') {
metadata['global-load-balancer-names'] = metadata['global-load-balancer-names'].concat(
loadBalancerDetails.listeners.map(listener => listener.name),
);
} else if (loadBalancerDetails.loadBalancerType === 'INTERNAL_MANAGED') {
metadata['load-balancer-names'] = metadata['load-balancer-names'].concat(
loadBalancerDetails.listeners.map(listener => listener.name),
);
} else if (loadBalancerDetails.loadBalancerType === 'SSL') {
metadata['global-load-balancer-names'].push(name);
} else if (loadBalancerDetails.loadBalancerType === 'TCP') {
metadata['global-load-balancer-names'].push(name);
} else {
metadata['load-balancer-names'].push(name);
}

if (_.isObject(backendServices) && Object.keys(backendServices).length > 0) {
metadata['backend-service-names'] = _.reduce(
backendServices,
(accumulatedBackends, backends) => accumulatedBackends.concat(backends),
[],
);
if (loadBalancerDetails.loadBalancerType === 'INTERNAL_MANAGED') {
metadata['region-backend-service-names'] = metadata['region-backend-service-names'].concat(
loadBalancerDetails.backendServices,
);
} else {
metadata['backend-service-names'] = metadata['backend-service-names'].concat(
loadBalancerDetails.backendServices,
);
}
return metadata;
}, metadata);
}

for (const key in metadata) {
Expand Down Expand Up @@ -357,7 +361,6 @@ angular
const loadBalancerMetadata = buildLoadBalancerMetadata(
$scope.command.loadBalancers,
$scope.command.backingData.filtered.loadBalancerIndex,
$scope.command.backendServices,
);

const origLoadBalancers = $scope.command.loadBalancers;
Expand Down

0 comments on commit 3e8a522

Please sign in to comment.