Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gce/internalhttplb) BackendServices for InternalHTTPLb is not hadled correctly #8540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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