Skip to content

Commit

Permalink
feat(provider/google): Add support for canIpForward property. (#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Duftler committed Mar 27, 2017
1 parent 05ddd33 commit 63dcefa
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BaseGoogleInstanceDescription extends AbstractGoogleCredentialsDescription
String subnet
// This will be treated as true if it is null to preserve backwards-compatibility with existing pipelines.
Boolean associatePublicIpAddress
Boolean canIpForward
String serviceAccountEmail
List<String> authScopes
Boolean preemptible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
def location = isRegional ? region : zone
def instanceMetadata = description.instanceMetadata
def labels = description.labels
def canIpForward = description.canIpForward

def serverGroupNameResolver = new GCEServerGroupNameResolver(project, region, credentials, safeRetry, this)
def clusterName = serverGroupNameResolver.combineAppStackDetail(description.application, description.stack, description.freeFormDetails)
Expand Down Expand Up @@ -307,6 +308,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
def instanceProperties = new InstanceProperties(machineType: machineTypeName,
disks: attachedDisks,
networkInterfaces: [networkInterface],
canIpForward: canIpForward,
metadata: metadata,
tags: tags,
labels: labels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class CopyLastGoogleServerGroupAtomicOperation extends GoogleAtomicOperation<Dep
description.associatePublicIpAddress != null
? description.associatePublicIpAddress
: ancestorInstanceProperties.networkInterfaces?.getAt(0)?.accessConfigs?.size() > 0

newDescription.canIpForward =
description.canIpForward != null
? description.canIpForward
: ancestorInstanceProperties.canIpForward
}

AutoscalingPolicy ancestorAutoscalingPolicy = ancestorServerGroup.autoscalingPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CreateGoogleInstanceAtomicOperation extends GoogleAtomicOperation<Deployme
def project = description.credentials.project
def zone = description.zone
def region = credentials.regionFromZone(zone)
def canIpForward = description.canIpForward

def machineTypeName
if (description.instanceType.startsWith('custom')) {
Expand Down Expand Up @@ -129,6 +130,7 @@ class CreateGoogleInstanceAtomicOperation extends GoogleAtomicOperation<Deployme
machineType: "zones/$zone/machineTypes/$machineTypeName",
disks: attachedDisks,
networkInterfaces: [networkInterface],
canIpForward: canIpForward,
metadata: metadata,
tags: tags,
labels: description.labels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ModifyGoogleServerGroupInstanceTemplateAtomicOperation extends GoogleAtomi
def compute = credentials.compute
def project = credentials.project
def region = description.region
def canIpForward = description.canIpForward
def serverGroupName = description.serverGroupName
def serverGroup = GCEUtil.queryServerGroup(googleClusterProvider, accountName, region, serverGroupName)
def isRegional = serverGroup.regional
Expand Down Expand Up @@ -191,6 +192,11 @@ class ModifyGoogleServerGroupInstanceTemplateAtomicOperation extends GoogleAtomi
instanceTemplateProperties.setMachineType(machineTypeName)
}

// Override the instance template's canIpForward property if it was specified.
if (overriddenProperties.canIpForward) {
instanceTemplateProperties.setCanIpForward(canIpForward)
}

// Override the instance template's metadata if instanceMetadata was specified.
if (overriddenProperties.instanceMetadata) {
def metadata = GCEUtil.buildMetadataFromMap(description.instanceMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class GoogleServerGroup {
Boolean disabled = false
Boolean discovery = false
String networkName
Boolean canIpForward = false
Set<String> instanceTemplateTags = []
Map<String, String> instanceTemplateLabels = [:]
String selfLink
Expand Down Expand Up @@ -92,6 +93,7 @@ class GoogleServerGroup {
Map buildInfo = GoogleServerGroup.this.buildInfo
Boolean disabled = GoogleServerGroup.this.disabled
String networkName = GoogleServerGroup.this.networkName
Boolean canIpForward = GoogleServerGroup.this.canIpForward
Set<String> instanceTemplateTags = GoogleServerGroup.this.instanceTemplateTags
Map<String, String> instanceTemplateLabels = GoogleServerGroup.this.instanceTemplateLabels
String selfLink = GoogleServerGroup.this.selfLink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ class GoogleRegionalServerGroupCachingAgent extends AbstractGoogleCachingAgent i
void onSuccess(InstanceTemplate instanceTemplate, HttpHeaders responseHeaders) throws IOException {
serverGroup.with {
networkName = Utils.getNetworkNameFromInstanceTemplate(instanceTemplate)
canIpForward = instanceTemplate?.properties?.canIpForward
instanceTemplateTags = instanceTemplate?.properties?.tags?.items
instanceTemplateLabels = instanceTemplate?.properties?.labels
launchConfig.with {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ class GoogleZonalServerGroupCachingAgent extends AbstractGoogleCachingAgent impl
void onSuccess(InstanceTemplate instanceTemplate, HttpHeaders responseHeaders) throws IOException {
serverGroup.with {
networkName = Utils.getNetworkNameFromInstanceTemplate(instanceTemplate)
canIpForward = instanceTemplate?.properties?.canIpForward
instanceTemplateTags = instanceTemplate?.properties?.tags?.items
instanceTemplateLabels = instanceTemplate?.properties?.labels
launchConfig.with {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CopyLastGoogleServerGroupAtomicOperationUnitSpec extends Specification {
instanceProperties = new InstanceProperties(machineType: INSTANCE_TYPE,
disks: attachedDisks,
networkInterfaces: [networkInterface],
canIpForward: false,
metadata: instanceMetadata,
tags: tags,
labels: LABELS,
Expand Down Expand Up @@ -169,6 +170,7 @@ class CopyLastGoogleServerGroupAtomicOperationUnitSpec extends Specification {
network: "other-network",
subnet: "other-subnet",
associatePublicIpAddress: false,
canIpForward: true,
loadBalancers: ["testlb-west-1", "testlb-west-2"],
autoscalingPolicy:
new GoogleAutoscalingPolicy(
Expand Down Expand Up @@ -237,6 +239,7 @@ class CopyLastGoogleServerGroupAtomicOperationUnitSpec extends Specification {
newDescription.network = DEFAULT_NETWORK_NAME
newDescription.subnet = SUBNET_NAME
newDescription.associatePublicIpAddress = true
newDescription.canIpForward = false
newDescription.loadBalancers = LOAD_BALANCERS
newDescription.autoscalingPolicy = new GoogleAutoscalingPolicy(coolDownPeriodSec: 45,
minNumReplicas: 2,
Expand Down

0 comments on commit 63dcefa

Please sign in to comment.