Skip to content

Commit

Permalink
Fixes #103: DM/backend_service: refactoring
Browse files Browse the repository at this point in the history
#103

- Added version, links to docs
- Switched to using type provider
- Added support for cross-project resource creation
- Added new fields: "backends[].maxRatePerEndpoint,
.maxConnectionsPerEndpoint", "iap", "customRequestHeaders[]"
- Changed healthCheck to healthChecks[]
- Added checks for INTERNAL/EXTERNAL LB schemes for all relevant fields
- Added checks for backends[].balancingMode
  • Loading branch information
bohdanyurov-gl committed Jun 6, 2019
1 parent 8007e64 commit b633000
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 8 deletions.
16 changes: 12 additions & 4 deletions dm/templates/backend_service/backend_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
""" This template creates a backend service. """

REGIONAL_GLOBAL_TYPE_NAMES = {
True: 'compute.v1.regionBackendService',
False: 'compute.v1.backendService'
# https://cloud.google.com/compute/docs/reference/rest/v1/regionBackendServices
True: 'gcp-types/compute-v1:regionBackendServices',
# https://cloud.google.com/compute/docs/reference/rest/v1/backendServices
False: 'gcp-types/compute-v1:backendServices'
}


Expand Down Expand Up @@ -52,19 +54,24 @@ def generate_config(context):
properties = context.properties
res_name = context.env['name']
name = properties.get('name', res_name)
project_id = properties.get('project', context.env['project'])
is_regional = 'region' in properties
region = properties.get('region')
backend_properties = {'name': name}
backend_properties = {
'name': name,
'project': project_id,
}

resource = {
'name': res_name,
'type': REGIONAL_GLOBAL_TYPE_NAMES[is_regional],
'properties': backend_properties
'properties': backend_properties,
}

optional_properties = [
'description',
'backends',
'iap',
'timeoutSec',
'protocol',
'region',
Expand All @@ -74,6 +81,7 @@ def generate_config(context):
'affinityCookieTtlSec',
'loadBalancingScheme',
'connectionDraining',
'healthChecks',
'cdnPolicy'
]

Expand Down
160 changes: 158 additions & 2 deletions dm/templates/backend_service/backend_service.py.schema
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,91 @@
info:
title: Backend Service
author: Sourced Group Inc.
version: 1.0.0
description: |
Creates a backend service. For details, visit
Creates a backend service.

For more information on this resource:
https://cloud.google.com/load-balancing/docs/backend-service.

APIs endpoints used by this template:
- gcp-types/compute-v1:backendServices =>
https://cloud.google.com/compute/docs/reference/rest/v1/backendServices
- gcp-types/compute-v1:regionBackendServices =>
https://cloud.google.com/compute/docs/reference/rest/v1/regionBackendServices

additionalProperties: false


allOf:
- oneOf:
- required:
- healthCheck
- required:
- healthChecks
- allOf:
- not:
required:
- healthCheck
- not:
required:
- healthChecks
- oneOf:
- allOf:
- properties:
loadBalancingScheme:
enum: ["INTERNAL"]
sessionAffinity:
enum:
- NONE
- CLIENT_IP
- CLIENT_IP_PROTO
- CLIENT_IP_PORT_PROTO
protocol:
default: TCP
enum:
- UDP
- TCP
backends:
items:
balancingMode:
enum: ["CONNECTION"]
- not:
required:
- affinityCookieTtlSec
- not:
required:
- enableCDN
- not:
required:
- portName
- allOf:
- properties:
loadBalancingScheme:
enum: ["EXTERNAL"]
sessionAffinity:
enum:
- NONE
- CLIENT_IP
- GENERATED_COOKIE
protocol:
default: HTTP
enum:
- HTTP
- HTTPS
- TCP
- SSL
- required:
- portName

properties:
name:
type: string
description: The backend service name.
description: The backend service name. Resource name would be used if omitted.
project:
type: string
description: |
The project ID of the project containing the service.
description:
type: string
description: An optional description of the resource.
Expand All @@ -34,13 +109,45 @@ properties:
The URL of the region where the regional backend service resides.
backends:
type: array
uniqueItems: true
description: |
The list of backends (instance groups) to which the backend service
distributes traffic.
items:
type: object
additionalProperties: false
required:
- group
oneOf:
- allOf:
- properties:
balancingMode:
enum: ["RATE"]
- not:
required:
- maxUtilization
- not:
required:
- maxConnections
- not:
required:
- maxConnectionsPerInstance
- not:
required:
- maxConnectionsPerEndpoint
- allOf:
- properties:
balancingMode:
enum: ["CONNECTION"]
- not:
required:
- maxUtilization
- not:
required:
- maxRate
- properties:
balancingMode:
enum: ["UTILIZATION"]
properties:
description:
type: string
Expand Down Expand Up @@ -83,6 +190,14 @@ properties:
Can be used with any balancing mode. For the RATE mode, either maxRate or
maxRatePerInstance must be set. Cannot be used for INTERNAL load
balancing.
maxRatePerEndpoint:
type: number
description: |
The max requests per second (RPS) that a single backend network endpoint can handle.
This is used to calculate the capacity of the group. Can be used in either balancing mode.
For RATE mode, either maxRate or maxRatePerEndpoint must be set.

This cannot be used for internal load balancing.
maxConnections:
type: number
description: |
Expand All @@ -98,6 +213,15 @@ properties:
group. Can be used in either CONNECTION or UTILIZATION balancing
modes. For the CONNECTION mode, either maxConnections or
maxConnectionsPerInstance must be set. Cannot be used for INTERNAL load balancing.
maxConnectionsPerEndpoint:
type: number
description: |
The max number of simultaneous connections that a single backend network endpoint can handle.
This is used to calculate the capacity of the group. Can be used in either
CONNECTION or UTILIZATION balancing modes.
For CONNECTION mode, either maxConnections or maxConnectionsPerEndpoint must be set.

This cannot be used for internal load balancing.
capacityScaler:
type: number
minimum: 0
Expand All @@ -111,6 +235,15 @@ properties:
description: |
The URL of the HealthCheck, HttpHealthCheck, or HttpsHealthCheck resource
for healthchecking the backend service.
healthChecks:
type: array
uniqueItems: true
maxItems: 1
description: |
The URL of the HealthCheck, HttpHealthCheck, or HttpsHealthCheck resource
for healthchecking the backend service.
items:
type: string
timeoutSec:
type: number
default: 30
Expand Down Expand Up @@ -170,24 +303,45 @@ properties:
Defines whether the backend service is used with INTERNAL or
EXTERNAL load balancing schema. Backend service created for one type of load
balancing cannot be used with the other.
default: EXTERNAL
enum:
- INTERNAL
- EXTERNAL
connectionDraining:
type: object
additionalProperties: false
description: the connection draining settings.
properties:
drainingTimeoutSec:
type: integer
description: |
The time period during which the instance is drained (not accepting
new connections but still procedding the ones accepted earlier).
customRequestHeaders:
type: array
uniqueItems: true
description: |
Headers that the HTTP/S load balancer should add to proxied requests.
items:
type: string
iap:
type: object
additionalProperties: false
properties:
enabled:
type: boolean
oauth2ClientId:
type: string
oauth2ClientSecret:
type: string
cdnPolicy:
type: object
additionalProperties: false
description: The cloud CDN configuration for the backend service.
properties:
cacheKeyPolicy:
type: object
additionalProperties: false
description: The CacheKeyPolicy for the CdnPolicy.
properties:
includeProtocol:
Expand All @@ -207,6 +361,7 @@ properties:
False, the query string is excluded from the cache key entirely.
queryStringWhitelist:
type: array
uniqueItems: true
description: |
The names of the query string parameters to include in cache keys.
All other parameters are excluded. Specify either
Expand All @@ -216,6 +371,7 @@ properties:
type: string
queryStringBlacklist:
type: array
uniqueItems: true
description: |
The names of query string parameters to exclude from cache keys.
All other parameters are included. Specify either
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ resources:
- group: <FIXME:instanceGroup>
balancingMode: RATE
maxRate: 10000
healthCheck: <FIXME:healthcheck>
healthCheck:
- <FIXME:healthcheck>
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ resources:
loadBalancingScheme: INTERNAL
backends:
- group: <FIXME:instanceGroup>
healthCheck: <FIXME:healthcheck>
healthChecks:
- <FIXME:healthcheck>

0 comments on commit b633000

Please sign in to comment.