From 8aa4dec1224549b9e6ca94ce52c935040baad54d Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Thu, 10 Nov 2016 16:44:31 +0300 Subject: [PATCH] Adding "strategy" field to service definition RollingUpdate cannot be used for some services upgrade, so Recreate type was added. Change-Id: I39f1d801efeda9c073c895f8281a6ecc768f7bf7 --- doc/source/dsl.rst | 44 ++++++++++++++++++---------------- fuel_ccp/deploy.py | 5 ++-- fuel_ccp/templates.py | 19 ++++++++++----- fuel_ccp/validation/service.py | 3 +++ 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/doc/source/dsl.rst b/doc/source/dsl.rst index c942e63a..47d1f0be 100644 --- a/doc/source/dsl.rst +++ b/doc/source/dsl.rst @@ -78,26 +78,30 @@ Parameters description service ------- -+---------------+-----------------------------------------------+----------+------------------+------------+ -| Name | Description | Required | Schema | Default | -+===============+===============================================+==========+==================+============+ -| name | Name of the service. | true | string | | -+---------------+-----------------------------------------------+----------+------------------+------------+ -| kind | Kind of k8s object to use for containers | false | one of: | Deployment | -| | deployment | | ["Deployment", | | -| | | | "DaemonSet"] | | -+---------------+-----------------------------------------------+----------+------------------+------------+ -| containers | List of containers under multi-container pod | true | container_ array | | -+---------------+-----------------------------------------------+----------+------------------+------------+ -| ports | k8s Service will be created if specified | false | internal-port: | | -| | (with NodePort type for now) | | external-port | | -| | Only internal or both internal:external ports | | array | | -| | can be specified | | | | -+---------------+-----------------------------------------------+----------+------------------+------------+ -| hostNetwork | Use the host’s network namespace | false | boolean | false | -+---------------+-----------------------------------------------+----------+------------------+------------+ -| hostPID | Use the host’s pid namespace | false | boolean | false | -+---------------+-----------------------------------------------+----------+------------------+------------+ ++---------------+-----------------------------------------------+----------+------------------+---------------+ +| Name | Description | Required | Schema | Default | ++===============+===============================================+==========+==================+===============+ +| name | Name of the service. | true | string | | ++---------------+-----------------------------------------------+----------+------------------+---------------+ +| kind | Kind of k8s object to use for containers | false | one of: | Deployment | +| | deployment | | ["Deployment", | | +| | | | "DaemonSet"] | | ++---------------+-----------------------------------------------+----------+------------------+---------------+ +| containers | List of containers under multi-container pod | true | container_ array | | ++---------------+-----------------------------------------------+----------+------------------+---------------+ +| ports | k8s Service will be created if specified | false | internal-port: | | +| | (with NodePort type for now) | | external-port | | +| | Only internal or both internal:external ports | | array | | +| | can be specified | | | | ++---------------+-----------------------------------------------+----------+------------------+---------------+ +| hostNetwork | Use the host’s network namespace | false | boolean | false | ++---------------+-----------------------------------------------+----------+------------------+---------------+ +| hostPID | Use the host’s pid namespace | false | boolean | false | ++---------------+-----------------------------------------------+----------+------------------+---------------+ +| strategy | The strategy that should be used to replace | false | one of: | RollingUpdate | +| | old Pods by new ones | | ["RollingUpdate",| | +| | | | "Recreate"] | | ++---------------+-----------------------------------------------+----------+------------------+---------------+ .. _container: diff --git a/fuel_ccp/deploy.py b/fuel_ccp/deploy.py index 703d8597..95a7dc3d 100644 --- a/fuel_ccp/deploy.py +++ b/fuel_ccp/deploy.py @@ -112,8 +112,9 @@ def parse_role(component, topology, configmaps): else: replicas = replicas or 1 - obj = templates.serialize_deployment(service_name, cont_spec, - affinity, replicas, component_name) + strategy = service.get('strategy', 'RollingUpdate') + obj = templates.serialize_deployment(service_name, cont_spec, affinity, + replicas, component_name, strategy) kubernetes.process_object(obj) _process_ports(service) diff --git a/fuel_ccp/templates.py b/fuel_ccp/templates.py index 917c96e4..d6b30442 100644 --- a/fuel_ccp/templates.py +++ b/fuel_ccp/templates.py @@ -288,8 +288,9 @@ def serialize_job(name, spec, component_name, app_name): } -def serialize_deployment(name, spec, affinity, replicas, component_name): - return { +def serialize_deployment(name, spec, affinity, replicas, component_name, + strategy): + deployment = { "apiVersion": "extensions/v1beta1", "kind": "Deployment", "metadata": { @@ -298,10 +299,7 @@ def serialize_deployment(name, spec, affinity, replicas, component_name): "spec": { "replicas": replicas, "strategy": { - "rollingUpdate": { - "maxSurge": 1, - "maxUnavailable": 0 - } + "type": strategy }, "template": { "metadata": { @@ -317,6 +315,15 @@ def serialize_deployment(name, spec, affinity, replicas, component_name): } } + if strategy == 'RollingUpdate': + deployment['spec']['strategy'].update({ + "rollingUpdate": { + "maxSurge": 1, + "maxUnavailable": 0 + } + }) + return deployment + def serialize_affinity(service, topology): policy = { diff --git a/fuel_ccp/validation/service.py b/fuel_ccp/validation/service.py index 9b10e4bd..27ab74fe 100644 --- a/fuel_ccp/validation/service.py +++ b/fuel_ccp/validation/service.py @@ -191,6 +191,9 @@ SERVICE_SCHEMA = { "hostPID": { "type": "boolean" }, + "strategy": { + "enum": ["RollingUpdate", "Recreate"] + }, "containers": { "type": "array", "minItems": 1,