Skip to content

Commit

Permalink
feat(provider/google): improved sessionAffinity handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandrov authored and maggieneterval committed Oct 15, 2019
1 parent de4839d commit c8334dc
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ class UpsertGoogleLoadBalancerAtomicOperation extends GoogleAtomicOperation<Map>
boolean needToUpdateForwardingRule = false
boolean needToUpdateTargetPool = false
boolean needToUpdateHttpHealthCheck = false
boolean needToUpdateSessionAffinity = false
boolean needToDeleteHttpHealthCheck = false
boolean needToCreateNewForwardingRule = false
boolean needToCreateNewTargetPool = false
boolean needToCreateNewHttpHealthCheck = false


// Check if there already exists a forwarding rule with the requested name.
existingForwardingRule =
GCEUtil.queryRegionalForwardingRule(project, description.loadBalancerName, compute, task, BASE_PHASE, this)
Expand Down Expand Up @@ -142,8 +140,6 @@ class UpsertGoogleLoadBalancerAtomicOperation extends GoogleAtomicOperation<Map>
|| description.healthCheck && !existingTargetPool.healthChecks
|| !description.healthCheck && existingTargetPool.healthChecks)

needToUpdateSessionAffinity = description.sessionAffinity != GoogleSessionAffinity.valueOf(existingTargetPool.getSessionAffinity());

if (existingTargetPool.healthChecks) {
existingHttpHealthCheck = GCEUtil.queryHttpHealthCheck(
project, GCEUtil.getLocalName(existingTargetPool.healthChecks[0]), compute, task, BASE_PHASE, this)
Expand Down Expand Up @@ -192,7 +188,15 @@ class UpsertGoogleLoadBalancerAtomicOperation extends GoogleAtomicOperation<Map>
def targetPoolResourceOperation
def targetPoolResourceLink

if (needToUpdateSessionAffinity && existingTargetPool.instances.any()) {
boolean sessionAffinityChanged
if (existingTargetPool == null) {
sessionAffinityChanged = description.sessionAffinity != GoogleSessionAffinity.NONE
}
else {
sessionAffinityChanged = description.sessionAffinity != GoogleSessionAffinity.valueOf(existingTargetPool.getSessionAffinity())
}

if (sessionAffinityChanged && existingTargetPool != null && existingTargetPool.instances.any()) {
task.updateStatus BASE_PHASE, "Impossible to change Session Affinity for target pool $targetPoolName with existing instances in $region"
task.fail()
}
Expand Down

0 comments on commit c8334dc

Please sign in to comment.