Last active
May 14, 2021 07:10
-
-
Save DazWilkin/3b0f7ded69e8f2b17cee35ba697c718a to your computer and use it in GitHub Desktop.
Cloud Deployment Manager & Kubernetes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def GenerateConfig(context): | |
"""Generate YAML resource configuration.""" | |
cluster_types_root = '{}/kubernetes'.format(context.env['project']) | |
cluster_types = { | |
'Service': '{}-v1:/api/v1/namespaces/{{namespace}}/services'.format(cluster_types_root), | |
'Deployment': '{}-v1beta1-apps:/apis/apps/v1beta1/namespaces/{{namespace}}/deployments'.format(cluster_types_root) | |
} | |
name = context.properties['name'] | |
image = context.properties['image'] | |
port = context.properties['port'] | |
resources = [{ | |
'name': name + '-service', | |
'type': cluster_types['Service'], | |
'properties': { | |
'apiVersion': 'v1', | |
'kind': 'Service', | |
'namespace': 'default', | |
'metadata': { | |
'name': name + '-service', | |
'labels': { | |
'id': 'deployment-manager' | |
} | |
}, | |
'spec': { | |
'type': 'NodePort', | |
'ports': [{ | |
'port': port, | |
'targetPort': port, | |
'protocol': 'TCP' | |
}], | |
'selector': { | |
'app': name | |
} | |
} | |
} | |
}, { | |
'name': name + '-deployment', | |
'type': cluster_types['Deployment'], | |
'properties': { | |
'apiVersion': 'apps/v1beta1', | |
'kind': 'Deployment', | |
'namespace': 'default', | |
'metadata': { | |
'name': name + '-deployment' | |
}, | |
'spec': { | |
'replicas': 1, | |
'template': { | |
'metadata': { | |
'labels': { | |
'name': name + '-deployment', | |
'app': name | |
} | |
}, | |
'spec': { | |
'containers': [{ | |
'name': 'container', | |
'image': image, | |
'ports': [{ | |
'containerPort': port | |
}] | |
}] | |
} | |
} | |
} | |
} | |
}] | |
return {'resources': resources} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment