Merge "Bring back StatefulSet support"

This commit is contained in:
Jenkins 2017-01-13 11:56:23 +00:00 committed by Gerrit Code Review
commit 02050bee2a
6 changed files with 62 additions and 7 deletions

View File

@ -102,7 +102,7 @@ service
* - kind
- Kind of k8s object to use for containers deployment.
- false
- one of: ["Deployment", "DaemonSet"]
- one of: ["Deployment", "DaemonSet", "StatefulSet"]
- Deployment
* - containers
- List of containers under multi-container pod.

View File

@ -1,3 +1,4 @@
import itertools
import logging
import os
import pkg_resources
@ -162,7 +163,8 @@ def get_deploy_components_info(rendering_context=None):
def get_deployed_components():
"""Returns set of deployed components."""
deployed_deployments = kubernetes.list_cluster_deployments()
deployed_components = set(
kubernetes.get_object_names(deployed_deployments)
deployed_statefulsets = kubernetes.list_cluster_statefulsets()
deployed_components = set(kubernetes.get_object_names(
itertools.chain(deployed_deployments, deployed_statefulsets))
)
return deployed_components

View File

@ -135,8 +135,15 @@ def parse_role(component, topology, configmaps):
'Affinity is in conflict with annotations with key: %s'
.format(same_keywords))
annotations.update(affinity)
obj = templates.serialize_deployment(service_name, cont_spec, annotations,
replicas, component_name, strategy)
if service.get("kind") != "StatefulSet":
obj = templates.serialize_deployment(service_name, cont_spec,
annotations, replicas,
component_name, strategy)
else:
obj = templates.serialize_statefulset(service_name, cont_spec,
annotations, replicas,
component_name)
yield [obj]
yield _process_ports(service)
@ -204,6 +211,7 @@ def _process_ports(service):
service["name"], ingress_host, source_port))
service_template = templates.serialize_service(
service["name"], ports,
headless=service.get("kind") == "StatefulSet",
annotations=service.get('annotations', {}).get('service'))
yield service_template

View File

@ -10,7 +10,13 @@ CONF = config.CONF
LOG = logging.getLogger(__name__)
UPDATABLE_OBJECTS = ('ConfigMap', 'Deployment', 'Service', 'Ingress')
UPDATABLE_OBJECTS = (
'ConfigMap',
'Deployment',
'Service',
'Ingress',
'StatefulSet',
)
def get_client(kube_apiserver=None, key_file=None, cert_file=None,
@ -180,6 +186,13 @@ def list_cluster_ingress():
namespace=CONF.kubernetes.namespace)
def list_cluster_statefulsets():
client = get_client()
return pykube.StatefulSet.objects(client).filter(
namespace=CONF.kubernetes.namespace,
selector="ccp=true")
def get_object_names(items):
names = []
for item in items:

View File

@ -357,6 +357,31 @@ def serialize_deployment(name, spec, annotations, replicas, component_name,
return deployment
def serialize_statefulset(name, spec, annotations, replicas, component_name):
return {
"apiVersion": "apps/v1beta1",
"kind": "StatefulSet",
"metadata": {
"name": name
},
"spec": {
"serviceName": name,
"replicas": replicas,
"template": {
"metadata": {
"annotations": annotations,
"labels": {
"ccp": "true",
"app": name,
"ccp-component": component_name
}
},
"spec": spec
}
}
}
def serialize_affinity(service, topology):
policy = {
"nodeAffinity": {

View File

@ -180,6 +180,13 @@ SERVICE_SCHEMA = {
"additionalProperties": False,
"required": ["name", "containers"],
"not": { # strategy needs to be absent for StatefulSet's
"properties": {
"kind": {"enum": ["StatefulSet"]},
},
"required": ["kind", "strategy"],
},
"properties": {
"name": NOT_EMPTY_STRING_SCHEMA,
"ports": {
@ -208,7 +215,7 @@ SERVICE_SCHEMA = {
}
},
"kind": {
"enum": ["Deployment", "DaemonSet"]
"enum": ["Deployment", "DaemonSet", "StatefulSet"]
},
"hostNetwork": {
"type": "boolean"