Browse Source

Merge "Bring back StatefulSet support"

Jenkins 2 years ago
parent
commit
02050bee2a

+ 1
- 1
doc/source/dsl.rst View File

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

+ 4
- 2
fuel_ccp/common/utils.py View File

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

+ 10
- 2
fuel_ccp/deploy.py View File

@@ -135,8 +135,15 @@ def parse_role(component, topology, configmaps):
135 135
             'Affinity is in conflict with annotations with key: %s'
136 136
             .format(same_keywords))
137 137
     annotations.update(affinity)
138
-    obj = templates.serialize_deployment(service_name, cont_spec, annotations,
139
-                                         replicas, component_name, strategy)
138
+
139
+    if service.get("kind") != "StatefulSet":
140
+        obj = templates.serialize_deployment(service_name, cont_spec,
141
+                                             annotations, replicas,
142
+                                             component_name, strategy)
143
+    else:
144
+        obj = templates.serialize_statefulset(service_name, cont_spec,
145
+                                              annotations, replicas,
146
+                                              component_name)
140 147
     yield [obj]
141 148
 
142 149
     yield _process_ports(service)
@@ -204,6 +211,7 @@ def _process_ports(service):
204 211
                     service["name"], ingress_host, source_port))
205 212
     service_template = templates.serialize_service(
206 213
         service["name"], ports,
214
+        headless=service.get("kind") == "StatefulSet",
207 215
         annotations=service.get('annotations', {}).get('service'))
208 216
     yield service_template
209 217
 

+ 14
- 1
fuel_ccp/kubernetes.py View File

@@ -10,7 +10,13 @@ CONF = config.CONF
10 10
 
11 11
 LOG = logging.getLogger(__name__)
12 12
 
13
-UPDATABLE_OBJECTS = ('ConfigMap', 'Deployment', 'Service', 'Ingress')
13
+UPDATABLE_OBJECTS = (
14
+    'ConfigMap',
15
+    'Deployment',
16
+    'Service',
17
+    'Ingress',
18
+    'StatefulSet',
19
+)
14 20
 
15 21
 
16 22
 def get_client(kube_apiserver=None, key_file=None, cert_file=None,
@@ -180,6 +186,13 @@ def list_cluster_ingress():
180 186
         namespace=CONF.kubernetes.namespace)
181 187
 
182 188
 
189
+def list_cluster_statefulsets():
190
+    client = get_client()
191
+    return pykube.StatefulSet.objects(client).filter(
192
+        namespace=CONF.kubernetes.namespace,
193
+        selector="ccp=true")
194
+
195
+
183 196
 def get_object_names(items):
184 197
     names = []
185 198
     for item in items:

+ 25
- 0
fuel_ccp/templates.py View File

@@ -357,6 +357,31 @@ def serialize_deployment(name, spec, annotations, replicas, component_name,
357 357
     return deployment
358 358
 
359 359
 
360
+def serialize_statefulset(name, spec, annotations, replicas, component_name):
361
+    return {
362
+        "apiVersion": "apps/v1beta1",
363
+        "kind": "StatefulSet",
364
+        "metadata": {
365
+            "name": name
366
+        },
367
+        "spec": {
368
+            "serviceName": name,
369
+            "replicas": replicas,
370
+            "template": {
371
+                "metadata": {
372
+                    "annotations": annotations,
373
+                    "labels": {
374
+                        "ccp": "true",
375
+                        "app": name,
376
+                        "ccp-component": component_name
377
+                    }
378
+                },
379
+                "spec": spec
380
+            }
381
+        }
382
+    }
383
+
384
+
360 385
 def serialize_affinity(service, topology):
361 386
     policy = {
362 387
         "nodeAffinity": {

+ 8
- 1
fuel_ccp/validation/service.py View File

@@ -180,6 +180,13 @@ SERVICE_SCHEMA = {
180 180
             "additionalProperties": False,
181 181
             "required": ["name", "containers"],
182 182
 
183
+            "not": {  # strategy needs to be absent for StatefulSet's
184
+                "properties": {
185
+                    "kind": {"enum": ["StatefulSet"]},
186
+                },
187
+                "required": ["kind", "strategy"],
188
+            },
189
+
183 190
             "properties": {
184 191
                 "name": NOT_EMPTY_STRING_SCHEMA,
185 192
                 "ports": {
@@ -208,7 +215,7 @@ SERVICE_SCHEMA = {
208 215
                     }
209 216
                 },
210 217
                 "kind": {
211
-                    "enum": ["Deployment", "DaemonSet"]
218
+                    "enum": ["Deployment", "DaemonSet", "StatefulSet"]
212 219
                 },
213 220
                 "hostNetwork": {
214 221
                     "type": "boolean"

Loading…
Cancel
Save