Adding "strategy" field to service definition
RollingUpdate cannot be used for some services upgrade, so Recreate type was added. Change-Id: I39f1d801efeda9c073c895f8281a6ecc768f7bf7
This commit is contained in:
parent
06a012c593
commit
8aa4dec122
|
@ -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:
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -191,6 +191,9 @@ SERVICE_SCHEMA = {
|
|||
"hostPID": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"strategy": {
|
||||
"enum": ["RollingUpdate", "Recreate"]
|
||||
},
|
||||
"containers": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
|
|
Loading…
Reference in New Issue