Adding Support for Annotations in DSL

Full Annotations support for pod and service is needed for setting
extra options in kubernates for users.

Change-Id: Icbde776e5e8b44cfabe752fb43cab2ed9978ffe5
This commit is contained in:
Krzysztof Szukiełojć 2016-12-08 08:24:26 +01:00
parent d8b879f0d8
commit cca092e303
6 changed files with 53 additions and 6 deletions

View File

@ -17,6 +17,11 @@ Application definition template
hostNetwork: true
hostPID: true
antiAffinity: local
annotations:
pod:
description: frontend ports
service:
description: frontend service
containers:
- name: container-name
image: container-image
@ -107,6 +112,9 @@ service
| | local - within namespace | | [null, "global", | |
| | global - within k8s cluster | | "local"] | |
+---------------+-----------------------------------------------+----------+------------------+---------------+
| annotations | pod - annotations for pods | false | string dict | null |
| | service - annotations for service | | | |
+---------------+-----------------------------------------------+----------+------------------+---------------+
.. _container:

View File

@ -17,4 +17,4 @@ import pbr.version
version_info = pbr.version.VersionInfo("fuel_ccp")
__version__ = version_info.version_string()
dsl_version = "0.2.0"
dsl_version = "0.3.0"

View File

@ -125,7 +125,14 @@ def parse_role(component, topology, configmaps, jinja_imports):
else:
replicas = replicas or 1
obj = templates.serialize_deployment(service_name, cont_spec, affinity,
annotations = service.get('annotations', {}).get('pod', {})
same_keywords = set(annotations) & set(affinity)
if same_keywords:
raise RuntimeError(
'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)
yield [obj]
@ -192,7 +199,9 @@ def _process_ports(service):
if ingress_host:
ingress_rules.append(templates.serialize_ingress_rule(
service["name"], ingress_host, source_port))
service_template = templates.serialize_service(service["name"], ports)
service_template = templates.serialize_service(
service["name"], ports,
annotations=service.get('annotations', {}).get('service'))
yield service_template
if ingress_rules:

View File

@ -308,7 +308,7 @@ def serialize_job(name, spec, component_name, app_name):
}
def serialize_deployment(name, spec, affinity, replicas, component_name,
def serialize_deployment(name, spec, annotations, replicas, component_name,
strategy):
if strategy['type'] == 'RollingUpdate':
strategy.setdefault("rollingUpdate", {
@ -327,7 +327,7 @@ def serialize_deployment(name, spec, affinity, replicas, component_name,
"strategy": strategy,
"template": {
"metadata": {
"annotations": affinity,
"annotations": annotations,
"labels": {
"app": name,
"ccp": "true",
@ -385,7 +385,7 @@ def serialize_affinity(service, topology):
policy, sort_keys=True)}
def serialize_service(name, ports, headless=False):
def serialize_service(name, ports, headless=False, annotations=None):
ports_spec = []
for port in ports:
spec_entry = {"port": port["port"],
@ -414,6 +414,9 @@ def serialize_service(name, ports, headless=False):
}
}
if annotations:
obj['metadata']['annotations'] = annotations
if not headless:
obj["spec"]["type"] = "NodePort"
else:

View File

@ -213,6 +213,25 @@ spec:
objects = list(deploy._process_ports(service))
self.assertEqual([yaml.load(service_k8s_obj)], objects)
def test_create_service_with_annotations(self):
self.conf.configs._merge({'ingress': {'enabled': False}})
service = {
"name": "foo",
"annotations": {'service': {"bla": "ble", "foo": "boo"}},
"ports": [
{"cont": 1111},
{"cont": "2222"},
{"cont": 3333,
"node": 30000},
{"cont": "4444",
"node": "33333"}
]
}
objects = list(deploy._process_ports(service))
self.assertEqual(
{'bla': 'ble', 'foo': 'boo'},
objects[0]['metadata']['annotations'])
def test_create_ingress(self):
self.conf.configs._merge({'ingress': {'enabled': True,
'domain': 'test'}})

View File

@ -198,6 +198,14 @@ SERVICE_SCHEMA = {
}
}
},
"annotations": {
"type": "object",
"additionalProperties": False,
"properties": {
"pod": {"type": "object"},
"service": {"type": "object"},
}
},
"kind": {
"enum": ["Deployment", "DaemonSet"]
},