Adjust default strategy for DaemonSet-like deployments

When emulating DaemonSets, we have antiaffinity rule that prevents 2
pods from running on the same host and we have no spare nodes to start
new pods, so we should do -1+1 update there.

Change-Id: I733d426d80e09aec015a05cc3324fcf7a2c8699c
This commit is contained in:
Yuriy Taraday 2016-11-13 00:01:14 +03:00
parent 024f1ed9fd
commit a54511cbba
2 changed files with 10 additions and 11 deletions

View File

@ -101,6 +101,7 @@ def parse_role(component, topology, configmaps):
affinity = templates.serialize_affinity(service, topology) affinity = templates.serialize_affinity(service, topology)
replicas = CONF.replicas.get(service_name) replicas = CONF.replicas.get(service_name)
strategy = {'type': service.get('strategy', 'RollingUpdate')}
if service.get("kind") == 'DaemonSet': if service.get("kind") == 'DaemonSet':
LOG.warning("Deployment is being used instead of DaemonSet to support " LOG.warning("Deployment is being used instead of DaemonSet to support "
"updates") "updates")
@ -112,10 +113,11 @@ def parse_role(component, topology, configmaps):
raise RuntimeError("Replicas couldn't be specified for services " raise RuntimeError("Replicas couldn't be specified for services "
"implemented using Kubernetes DaemonSet") "implemented using Kubernetes DaemonSet")
replicas = len(set(topology[service_name])) replicas = len(set(topology[service_name]))
if strategy['type'] == 'RollingUpdate':
strategy['rollingUpdate'] = {'maxSurge': 0, 'maxUnavailable': 1}
else: else:
replicas = replicas or 1 replicas = replicas or 1
strategy = service.get('strategy', 'RollingUpdate')
obj = templates.serialize_deployment(service_name, cont_spec, affinity, obj = templates.serialize_deployment(service_name, cont_spec, affinity,
replicas, component_name, strategy) replicas, component_name, strategy)
yield [obj] yield [obj]

View File

@ -290,6 +290,12 @@ def serialize_job(name, spec, component_name, app_name):
def serialize_deployment(name, spec, affinity, replicas, component_name, def serialize_deployment(name, spec, affinity, replicas, component_name,
strategy): strategy):
if strategy['type'] == 'RollingUpdate':
strategy.setdefault("rollingUpdate", {
"maxSurge": 1,
"maxUnavailable": 0
})
deployment = { deployment = {
"apiVersion": "extensions/v1beta1", "apiVersion": "extensions/v1beta1",
"kind": "Deployment", "kind": "Deployment",
@ -298,9 +304,7 @@ def serialize_deployment(name, spec, affinity, replicas, component_name,
}, },
"spec": { "spec": {
"replicas": replicas, "replicas": replicas,
"strategy": { "strategy": strategy,
"type": strategy
},
"template": { "template": {
"metadata": { "metadata": {
"annotations": affinity, "annotations": affinity,
@ -315,13 +319,6 @@ def serialize_deployment(name, spec, affinity, replicas, component_name,
} }
} }
if strategy == 'RollingUpdate':
deployment['spec']['strategy'].update({
"rollingUpdate": {
"maxSurge": 1,
"maxUnavailable": 0
}
})
return deployment return deployment