Skip to content

Commit

Permalink
feat(gce): Add GCP internal http(s) load balancer. (#4725)
Browse files Browse the repository at this point in the history
* fix(provider/google): add internal http(s) load balancer. (#5042)

* fix(provider/gce): Fix Internal HTTP LB implementations to use java.

* fix(provider/gce): Fix internal http lb cannot be deployed with other global lbs

* fix(provider/gce): Fix referencing not existing property

* chore(gce): no use ProviderVersion

* chore(gce): null check in common place

* chore(gce): set subnet purpose default value n/a

* chore(gce): refactor internal http lb

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
takaaki7 and mergify[bot] committed Aug 7, 2020
1 parent 2374188 commit a34b951
Show file tree
Hide file tree
Showing 27 changed files with 4,770 additions and 83 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.netflix.spinnaker.clouddriver.google.deploy.converters
import com.netflix.spinnaker.clouddriver.google.GoogleOperation
import com.netflix.spinnaker.clouddriver.google.deploy.description.DeleteGoogleLoadBalancerDescription
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.DeleteGoogleHttpLoadBalancerAtomicOperation
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.DeleteGoogleInternalHttpLoadBalancerAtomicOperation
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.DeleteGoogleInternalLoadBalancerAtomicOperation
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.DeleteGoogleLoadBalancerAtomicOperation
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.DeleteGoogleSslLoadBalancerAtomicOperation
Expand All @@ -42,6 +43,9 @@ class DeleteGoogleLoadBalancerAtomicOperationConverter extends AbstractAtomicOpe
case GoogleLoadBalancerType.HTTP:
return new DeleteGoogleHttpLoadBalancerAtomicOperation(description)
break
case GoogleLoadBalancerType.INTERNAL_MANAGED:
return new DeleteGoogleInternalHttpLoadBalancerAtomicOperation(description)
break
case GoogleLoadBalancerType.INTERNAL:
return new DeleteGoogleInternalLoadBalancerAtomicOperation(description)
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.netflix.spinnaker.clouddriver.google.deploy.converters
import com.netflix.spinnaker.clouddriver.google.GoogleOperation
import com.netflix.spinnaker.clouddriver.google.deploy.description.UpsertGoogleLoadBalancerDescription
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.UpsertGoogleHttpLoadBalancerAtomicOperation
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.UpsertGoogleInternalHttpLoadBalancerAtomicOperation
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.UpsertGoogleInternalLoadBalancerAtomicOperation
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.UpsertGoogleLoadBalancerAtomicOperation
import com.netflix.spinnaker.clouddriver.google.deploy.ops.loadbalancer.UpsertGoogleSslLoadBalancerAtomicOperation
Expand All @@ -41,6 +42,9 @@ class UpsertGoogleLoadBalancerAtomicOperationConverter extends AbstractAtomicOpe
case GoogleLoadBalancerType.HTTP:
return new UpsertGoogleHttpLoadBalancerAtomicOperation(description)
break
case GoogleLoadBalancerType.INTERNAL_MANAGED:
return new UpsertGoogleInternalHttpLoadBalancerAtomicOperation(description)
break
case GoogleLoadBalancerType.INTERNAL:
return new UpsertGoogleInternalLoadBalancerAtomicOperation(description)
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import org.springframework.stereotype.Component

import static com.google.common.base.Preconditions.checkArgument
import static com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil.BACKEND_SERVICE_NAMES
import static com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil.REGION_BACKEND_SERVICE_NAMES
import static com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil.GLOBAL_LOAD_BALANCER_NAMES
import static com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil.LOAD_BALANCING_POLICY
import static com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil.REGIONAL_LOAD_BALANCER_NAMES
Expand Down Expand Up @@ -190,6 +191,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip

def targetPools = []
def internalLoadBalancers = []
def internalHttpLoadBalancers = []
def sslLoadBalancers = []
def tcpLoadBalancers = []

Expand All @@ -205,6 +207,8 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
// Queue ILBs to update, but wait to update metadata until Https LBs are calculated.
internalLoadBalancers = foundLoadBalancers.findAll { it.loadBalancerType == GoogleLoadBalancerType.INTERNAL }

internalHttpLoadBalancers = foundLoadBalancers.findAll { it.loadBalancerType == GoogleLoadBalancerType.INTERNAL_MANAGED }

// Queue SSL LBs to update.
sslLoadBalancers = foundLoadBalancers.findAll { it.loadBalancerType == GoogleLoadBalancerType.SSL }

Expand Down Expand Up @@ -310,10 +314,10 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip

// Update the instance metadata for ILBs and queue up region backend service calls.
List<BackendService> regionBackendServicesToUpdate = []
if (internalLoadBalancers) {
if (internalLoadBalancers || internalHttpLoadBalancers) {
List<String> existingRegionalLbs = instanceMetadata[REGIONAL_LOAD_BALANCER_NAMES]?.split(",") ?: []
def ilbServices = internalLoadBalancers.collect { it.backendService.name }
def ilbNames = internalLoadBalancers.collect { it.name }
def ilbServices = internalLoadBalancers.collect { it.backendService.name } + (instanceMetadata[REGION_BACKEND_SERVICE_NAMES]?.split(",") as List) ?: []
def ilbNames = internalLoadBalancers.collect { it.name } + internalHttpLoadBalancers.collect { it.name }

ilbNames.each { String ilbName ->
if (!(ilbName in existingRegionalLbs)) {
Expand Down Expand Up @@ -488,7 +492,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
.setTargetPools(targetPools)
.setAutoHealingPolicies(autoHealingPolicy)

if (hasBackendServices && (description?.loadBalancingPolicy || description?.source?.serverGroupName)) {
if ((hasBackendServices || internalHttpLoadBalancers) && (description?.loadBalancingPolicy || description?.source?.serverGroupName)) {
List<NamedPort> namedPorts = []
def sourceGroupName = description?.source?.serverGroupName

Expand Down Expand Up @@ -517,8 +521,8 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
}

def willUpdateBackendServices = !description.disableTraffic && hasBackendServices
def willUpdateRegionalBackendServices = !description.disableTraffic && (internalLoadBalancers || internalHttpLoadBalancers)
def willCreateAutoscaler = autoscalerIsSpecified(description)
def willUpdateIlbs = !description.disableTraffic && internalLoadBalancers

if (isRegional) {
if (description.distributionPolicy) {
Expand Down Expand Up @@ -546,7 +550,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
"compute.regionInstanceGroupManagers.insert",
TAG_SCOPE, SCOPE_REGIONAL, TAG_REGION, region)

if (willUpdateBackendServices || willCreateAutoscaler || willUpdateIlbs) {
if (willUpdateBackendServices || willCreateAutoscaler || willUpdateRegionalBackendServices) {
// Before updating the Backend Services or creating the Autoscaler we must wait until the managed instance group is created.
googleOperationPoller.waitForRegionalOperation(compute, project, region, migCreateOperation.getName(),
null, task, "managed instance group $serverGroupName", BASE_PHASE)
Expand All @@ -570,7 +574,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
"compute.instanceGroupManagers.insert",
TAG_SCOPE, SCOPE_ZONAL, TAG_ZONE, zone)

if (willUpdateBackendServices || willCreateAutoscaler || willUpdateIlbs) {
if (willUpdateBackendServices || willCreateAutoscaler || willUpdateRegionalBackendServices) {
// Before updating the Backend Services or creating the Autoscaler we must wait until the managed instance group is created.
googleOperationPoller.waitForZonalOperation(compute, project, zone, migCreateOperation.getName(),
null, task, "managed instance group $serverGroupName", BASE_PHASE)
Expand Down Expand Up @@ -607,7 +611,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
}
}

if (willUpdateIlbs) {
if (willUpdateRegionalBackendServices) {
regionBackendServicesToUpdate.each { BackendService backendService ->
safeRetry.doRetry(
updateRegionBackendServices(compute, project, region, backendService.name, backendService),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ abstract class AbstractEnableDisableAtomicOperation extends GoogleAtomicOperatio
registry
)

task.updateStatus phaseName, "Deregistering server group from Internal Http(s) load balancers..."

safeRetry.doRetry(
destroyInternalHttpLoadBalancerBackends(compute, project, serverGroup, googleLoadBalancerProvider, task, phaseName),
"Internal Http load balancer backends",
task,
RETRY_ERROR_CODES,
SUCCESSFUL_ERROR_CODES,
[operation: "destroyInternalHttpLoadBalancerBackends", action: "destroy", phase: phaseName, (TAG_SCOPE): SCOPE_REGIONAL, (TAG_REGION): region],
registry
)

task.updateStatus phaseName, "Deregistering server group from internal load balancers..."

safeRetry.doRetry(
Expand Down Expand Up @@ -239,6 +251,18 @@ abstract class AbstractEnableDisableAtomicOperation extends GoogleAtomicOperatio
registry
)

task.updateStatus phaseName, "Registering server group with Internal Http(s) load balancers..."

safeRetry.doRetry(
addInternalHttpLoadBalancerBackends(compute, objectMapper, project, serverGroup, googleLoadBalancerProvider, task, phaseName),
"Internal Http load balancer backends",
task,
RETRY_ERROR_CODES,
[],
[operation: "addInternalHttpLoadBalancerBackends", action: "add", phase: phaseName, (TAG_SCOPE): SCOPE_REGIONAL, (TAG_REGION): region],
registry
)

task.updateStatus phaseName, "Registering server group with Internal load balancers..."

safeRetry.doRetry(
Expand Down Expand Up @@ -383,6 +407,14 @@ abstract class AbstractEnableDisableAtomicOperation extends GoogleAtomicOperatio
}
}


Closure destroyInternalHttpLoadBalancerBackends(compute, project, serverGroup, googleLoadBalancerProvider, task, phaseName) {
return {
GCEUtil.destroyInternalHttpLoadBalancerBackends(compute, project, serverGroup, googleLoadBalancerProvider, task, phaseName, googleOperationPoller, this)
null
}
}

Closure destroyInternalLoadBalancerBackends(compute, project, serverGroup, googleLoadBalancerProvider, task, phaseName) {
return {
GCEUtil.destroyInternalLoadBalancerBackends(compute, project, serverGroup, googleLoadBalancerProvider, task, phaseName, googleOperationPoller, this)
Expand Down Expand Up @@ -411,6 +443,13 @@ abstract class AbstractEnableDisableAtomicOperation extends GoogleAtomicOperatio
}
}

Closure addInternalHttpLoadBalancerBackends(compute, objectMapper, project, serverGroup, googleLoadBalancerProvider, task, phaseName) {
return {
GCEUtil.addInternalHttpLoadBalancerBackends(compute, objectMapper, project, serverGroup, googleLoadBalancerProvider, task, phaseName, googleOperationPoller, this)
null
}
}

Closure addSslLoadBalancerBackends(compute, objectMapper, project, serverGroup, googleLoadBalancerProvider, task, phaseName) {
return {
GCEUtil.addSslLoadBalancerBackends(compute, objectMapper, project, serverGroup, googleLoadBalancerProvider, task, phaseName, googleOperationPoller, this)
Expand Down
Loading

0 comments on commit a34b951

Please sign in to comment.