Fix the issue with getting replicas and update the task caption + the conditions

This commit is contained in:
Peter Jausovec 2017-02-14 08:59:18 -08:00
Родитель 5b97ccd166
Коммит ec0ea32f1f
3 изменённых файлов: 28 добавлений и 19 удалений

Просмотреть файл

@ -112,7 +112,8 @@ class DockerComposeParser(object):
try:
namespace = self.group_info.get_namespace()
logging.info('Removing all resources from namespace "%s".', namespace)
logging.info(
'Removing all resources from namespace "%s".', namespace)
self._delete_all(namespace)
except Exception as remove_exception:
raise remove_exception
@ -153,9 +154,11 @@ class DockerComposeParser(object):
deployed_version = namespaces[0][
'metadata']['labels']['group_version']
if deployed_version == group_version:
raise Exception('App with the same version already deployed')
raise Exception(
'App with the same version already deployed')
else:
# This version is not deployed yet, so we are doing an update
# This version is not deployed yet, so we are doing an
# update
is_update = True
existing_namespace = namespaces[0]['metadata']['name']
return (is_update, deployed_version, existing_namespace)
@ -212,13 +215,17 @@ class DockerComposeParser(object):
if is_update:
for deployment_item in all_deployments:
service_name = deployment_item['service_name']
existing_replicas = self.kubernetes.get_replicas(
existing_namespace, service_name)
logging.info('Update replicas for "%s" to "%s"',
service_name, existing_replicas)
deployment_json = json.loads(
deployment_item['deployment']['json'])
deployment_json['spec']['replicas'] = existing_replicas
if self.kubernetes.deployment_exists(service_name, existing_namespace):
existing_replicas = self.kubernetes.get_replicas(
existing_namespace, service_name)
logging.info('Update replicas for "%s" to "%s"',
service_name, existing_replicas)
deployment_json['spec']['replicas'] = existing_replicas
else:
logging.info('Deploying new service "%s"', service_name)
# Create the deployment
self.kubernetes.create_deployment(

Просмотреть файл

@ -95,7 +95,9 @@ class Kubernetes(object):
Checks if deployment exists in a namespace or not
"""
logging.debug('Check if deployment "%s.%s" exists', name, namespace)
response = self.get_deployment(namespace, name)
response = self.get_request(
'namespaces/{}/deployments/{}'.format(
namespace, name), self._beta_endpoint()).json()
return not self._has_failed(response)
def delete_deployment(self, name, namespace):
@ -300,10 +302,10 @@ class Kubernetes(object):
"""
Gets the number of replicas for a deployment
"""
logging.debug('Getting replicas for "%s" from "%s".', deployment_name, namespace)
deployment = self.get_deployment(namespace, deployment_name)
if 'spec' in deployment:
if 'replicas' in deployment:
if 'replicas' in deployment['spec']:
return deployment['spec']['replicas']
raise Exception(
'Could not find replicas in deployment "{}" from namespace "{}".',

Просмотреть файл

@ -37,7 +37,7 @@
"required": true,
"options": {
"ACS DCOS": "Azure Container Service (DC/OS)",
"ACS Kubernetes": "Azure Container Service (Kubernetes)"
"ACS Kubernetes": "Azure Container Service (Kubernetes) (PREVIEW)"
},
"helpMarkDown": "Select a deployment target type."
},
@ -46,7 +46,7 @@
"type": "filePath",
"label": "Docker Compose File",
"required": true,
"visibleRule": "targetType = ACS DCOS | targetType = ACS Kubernetes",
"visibleRule": "targetType = ACS DCOS || targetType = ACS Kubernetes",
"helpMarkDown": "Path to the primary Docker Compose file to use."
},
{
@ -57,7 +57,7 @@
"rows": "2"
},
"label": "Additional Docker Compose Files",
"visibleRule": "targetType = ACS DCOS | targetType = ACS Kubernetes",
"visibleRule": "targetType = ACS DCOS || targetType = ACS Kubernetes",
"helpMarkDown": "Additional Docker Compose files to be combined with the primary Docker Compose file. Relative paths are resolved relative to the directory containing the primary Docker Compose file. If a specified file is not found, it is ignored. Specify each file path on a new line."
},
{
@ -68,7 +68,7 @@
"rows": "2"
},
"label": "Environment Variables",
"visibleRule": "targetType = ACS DCOS | targetType = ACS Kubernetes",
"visibleRule": "targetType = ACS DCOS || targetType = ACS Kubernetes",
"helpMarkDown": "Environment variables to be set during the command. Specify each name=value pair on a new line."
},
{
@ -76,7 +76,7 @@
"type": "string",
"label": "Project Name",
"defaultValue": "$(Release.DefinitionName)",
"visibleRule": "targetType = ACS DCOS | targetType = ACS Kubernetes",
"visibleRule": "targetType = ACS DCOS || targetType = ACS Kubernetes",
"helpMarkDown": "Project name used for default naming of images and containers."
},
{
@ -84,7 +84,7 @@
"type": "boolean",
"label": "Qualify Image Names",
"defaultValue": "false",
"visibleRule": "targetType = ACS DCOS | targetType = ACS Kubernetes",
"visibleRule": "targetType = ACS DCOS || targetType = ACS Kubernetes",
"helpMarkDown": "Automatically qualify image names for built services with the Docker registry connection's hostname if not otherwise specified."
},
{
@ -157,7 +157,7 @@
"label": "Application Group Qualifier",
"required": true,
"defaultValue": "$(System.TeamFoundationCollectionUri)/$(System.TeamProject)",
"visibleRule": "targetType = ACS DCOS | targetType = ACS Kubernetes",
"visibleRule": "targetType = ACS DCOS || targetType = ACS Kubernetes",
"helpMarkDown": "Qualifier for the Marathon application group name that is hashed and appended to create a unique identifier for deployment definitions."
},
{
@ -166,7 +166,7 @@
"label": "Application Group Version",
"required": true,
"defaultValue": "$(Release.ReleaseId).$(Release.AttemptNumber)",
"visibleRule": "targetType = ACS DCOS | targetType = ACS Kubernetes",
"visibleRule": "targetType = ACS DCOS || targetType = ACS Kubernetes",
"helpMarkDown": "Version for the Marathon application group name that is appended to create a unique identifier for specific deployments."
},
{