Skip to content

Commit

Permalink
[DM] healthcheck: refactoring (#131)
Browse files Browse the repository at this point in the history
#124

- Added version, links to docs
- Switched to using type provider
- Added support for cross-project resource creation
- Added support for missing fields: "description", "name"
  • Loading branch information
bohdanyurov-gl authored and ocsig committed Jun 26, 2019
1 parent f3b4528 commit 19baaad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
41 changes: 22 additions & 19 deletions dm/templates/healthcheck/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,37 @@ def generate_config(context):
""" Entry point for the deployment resources. """

resources = []
outputs = []
healthcheck = {}
properties = context.properties
healthcheck_name = context.env['name']
healthcheck_name = properties.get('name', context.env['name'])
healthcheck_type = properties['healthcheckType']
healthcheck_version = properties.get('version', 'v1')

project_id = properties.get('project', context.env['project'])

# Deployment Manager resource types per healthcheck type.
healthcheck_type_dictionary = {
'HTTP':
{
'v1': 'compute.v1.httpHealthCheck',
'beta': 'compute.beta.httpHealthCheck'
'v1': 'gcp-types/compute-v1:httpHealthChecks',
'beta': 'gcp-types/compute-beta:httpHealthChecks'
},
'HTTPS':
{
'v1': 'compute.v1.httpsHealthCheck',
'beta': 'compute.beta.httpsHealthCheck'
'v1': 'gcp-types/compute-v1:httpsHealthChecks',
'beta': 'gcp-types/compute-beta:httpsHealthChecks'
},
'SSL':
{
'v1': 'compute.v1.healthCheck',
'beta': 'compute.beta.healthCheck'
'v1': 'gcp-types/compute-v1:healthChecks',
'beta': 'gcp-types/compute-beta:healthChecks'
},
'TCP':
{
'v1': 'compute.v1.healthCheck',
'beta': 'compute.beta.healthCheck'
'v1': 'gcp-types/compute-v1:healthChecks',
'beta': 'gcp-types/compute-beta:healthChecks'
},
'HTTP2': {
'beta': 'compute.beta.healthCheck'
'beta': 'gcp-types/compute-beta:healthChecks'
}
}

Expand All @@ -74,23 +75,25 @@ def generate_config(context):
# Create a generic healthcheck object.
healthcheck = {
'name':
healthcheck_name,
context.env['name'],
'type':
healthcheck_type_dictionary[healthcheck_type][healthcheck_version]
}

# Create the generic healthcheck properties separately.
healthcheck_properties = {
'description': properties.get('description',
''),
'checkIntervalSec': properties['checkIntervalSec'],
'timeoutSec': properties['timeoutSec'],
'unhealthyThreshold': properties['unhealthyThreshold'],
'healthyThreshold': properties['healthyThreshold'],
'kind': 'compute#healthCheck',
'type': healthcheck_type
'type': healthcheck_type,
'project': project_id,
'name': healthcheck_name,
}

set_if_exists(healthcheck_properties, properties, 'description')

# Create a specific healthcheck object.
specific_healthcheck_type = healthcheck_object_dictionary[healthcheck_type]
specific_healthcheck = {
Expand Down Expand Up @@ -125,15 +128,15 @@ def generate_config(context):
outputs = [
{
'name': 'name',
'value': '$(ref.{}.name)'.format(healthcheck_name)
'value': '$(ref.{}.name)'.format(context.env['name'])
},
{
'name': 'selfLink',
'value': '$(ref.{}.selfLink)'.format(healthcheck_name)
'value': '$(ref.{}.selfLink)'.format(context.env['name'])
},
{
'name': 'creationTimestamp',
'value': '$(ref.{}.creationTimestamp)'.format(healthcheck_name)
'value': '$(ref.{}.creationTimestamp)'.format(context.env['name'])
}
]

Expand Down
31 changes: 31 additions & 0 deletions dm/templates/healthcheck/healthcheck.py.schema
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,27 @@
info:
title: Healthcheck
author: Sourced Group Inc.
version: 1.0.0
description: |
Creates a Healthcheck resource.

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

APIs endpoints used by this template:
- gcp-types/compute-v1:httpHealthChecks =>
https://cloud.google.com/compute/docs/reference/rest/v1/httpHealthChecks
- gcp-types/compute-v1:httpsHealthChecks =>
https://cloud.google.com/compute/docs/reference/rest/v1/httpsHealthChecks
- gcp-types/compute-v1:healthChecks =>
https://cloud.google.com/compute/docs/reference/rest/v1/healthChecks
- gcp-types/compute-beta:httpHealthChecks =>
https://cloud.google.com/compute/docs/reference/rest/beta/httpHealthChecks
- gcp-types/compute-beta:httpsHealthChecks =>
https://cloud.google.com/compute/docs/reference/rest/beta/httpsHealthChecks
- gcp-types/compute-beta:healthChecks =>
https://cloud.google.com/compute/docs/reference/rest/beta/healthChecks

imports:
- path: healthcheck.py

Expand All @@ -30,6 +45,22 @@ required:
- healthcheckType

properties:
name:
type: string
description: |
Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long,
and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular
expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all
following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.
project:
type: string
description: |
The project ID of the project containing the Cloud Router instance. The
Google apps domain is prefixed if applicable.
description:
type: string
description: |
An optional description of this resource. Provide this property when you create the resource.
checkIntervalSec:
type: integer
default: 5
Expand Down

0 comments on commit 19baaad

Please sign in to comment.