Skip to content

Instantly share code, notes, and snippets.

@DazWilkin
Last active May 14, 2021 07:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DazWilkin/8005a93dd9402303884141ec688afed1 to your computer and use it in GitHub Desktop.
Save DazWilkin/8005a93dd9402303884141ec688afed1 to your computer and use it in GitHub Desktop.
Cloud Deployment Manager & Kubernetes
def GenerateConfig(context):
"""Generate YAML resource configuration."""
cluster_name = context.properties['CLUSTER_NAME']
cluster_region = context.properties['CLUSTER_ZONE']
number_of_nodes = context.properties['NUM_NODES']
resources = []
outputs = []
resources.append({
'name': cluster_name,
'type': 'gcp-types/container-v1beta1:projects.locations.clusters',
'properties': {
'parent': 'projects/{}/locations/{}'.format(context.env['project'], cluster_region),
'cluster': {
'name': cluster_name,
'nodePools': [{
'name': 'core',
'initialNodeCount': number_of_nodes,
'config': {
'imageType': 'COS',
'preemptible': True,
'oauthScopes': [
'https://www.googleapis.com/auth/' + scope
for scope in [
'compute',
'devstorage.read_only',
'logging.write',
'monitoring'
]
]
},
'autoscaling': {
'enabled': False
},
'management': {
'autoUpgrade': True,
'autoRepair': True,
'upgradeOptions': {}
}
}]
}
}
})
outputs.append({
'name': 'endpoint',
'value': '$(ref.' + cluster_name + '.endpoint)'
})
return {'resources': resources, 'outputs': outputs}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment