Skip to content

Commit

Permalink
feat(provider/google): Set Session Affinity for new target pools
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandrov authored and maggieneterval committed Oct 15, 2019
1 parent cde0faf commit 703f777
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.netflix.frigga.Names
import com.netflix.spinnaker.clouddriver.google.model.loadbalancing.GoogleBackendService
import com.netflix.spinnaker.clouddriver.google.model.loadbalancing.GoogleHostRule
import com.netflix.spinnaker.clouddriver.google.model.loadbalancing.GoogleLoadBalancerType
import com.netflix.spinnaker.clouddriver.google.model.loadbalancing.GoogleSessionAffinity
import com.netflix.spinnaker.clouddriver.security.resources.ApplicationNameable

class UpsertGoogleLoadBalancerDescription extends AbstractGoogleCredentialsDescription implements ApplicationNameable {
Expand Down Expand Up @@ -51,6 +52,9 @@ class UpsertGoogleLoadBalancerDescription extends AbstractGoogleCredentialsDescr
*/
List<GoogleBackendService> backendServiceDiff

// NLB attribues.
GoogleSessionAffinity sessionAffinity

// ILB attributes.
String network
String subnet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.netflix.spinnaker.clouddriver.google.deploy.SafeRetry
import com.netflix.spinnaker.clouddriver.google.deploy.description.UpsertGoogleLoadBalancerDescription
import com.netflix.spinnaker.clouddriver.google.deploy.exception.GoogleOperationException
import com.netflix.spinnaker.clouddriver.google.deploy.ops.GoogleAtomicOperation
import com.netflix.spinnaker.clouddriver.google.model.loadbalancing.GoogleSessionAffinity
import org.springframework.beans.factory.annotation.Autowired

class UpsertGoogleLoadBalancerAtomicOperation extends GoogleAtomicOperation<Map> {
Expand Down Expand Up @@ -105,11 +106,13 @@ 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 @@ -139,6 +142,8 @@ 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 @@ -371,7 +376,8 @@ class UpsertGoogleLoadBalancerAtomicOperation extends GoogleAtomicOperation<Map>
def targetPool = new TargetPool(
name: targetPoolName,
healthChecks: httpHealthChecksResourceLinks,
instances: description.instances
instances: description.instances,
sessionAffinity: description.sessionAffinity
)

targetPoolResourceOperation = timeExecute(
Expand Down

0 comments on commit 703f777

Please sign in to comment.