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:
parent
d8b879f0d8
commit
cca092e303
|
@ -17,6 +17,11 @@ Application definition template
|
||||||
hostNetwork: true
|
hostNetwork: true
|
||||||
hostPID: true
|
hostPID: true
|
||||||
antiAffinity: local
|
antiAffinity: local
|
||||||
|
annotations:
|
||||||
|
pod:
|
||||||
|
description: frontend ports
|
||||||
|
service:
|
||||||
|
description: frontend service
|
||||||
containers:
|
containers:
|
||||||
- name: container-name
|
- name: container-name
|
||||||
image: container-image
|
image: container-image
|
||||||
|
@ -107,6 +112,9 @@ service
|
||||||
| | local - within namespace | | [null, "global", | |
|
| | local - within namespace | | [null, "global", | |
|
||||||
| | global - within k8s cluster | | "local"] | |
|
| | global - within k8s cluster | | "local"] | |
|
||||||
+---------------+-----------------------------------------------+----------+------------------+---------------+
|
+---------------+-----------------------------------------------+----------+------------------+---------------+
|
||||||
|
| annotations | pod - annotations for pods | false | string dict | null |
|
||||||
|
| | service - annotations for service | | | |
|
||||||
|
+---------------+-----------------------------------------------+----------+------------------+---------------+
|
||||||
|
|
||||||
.. _container:
|
.. _container:
|
||||||
|
|
||||||
|
|
|
@ -17,4 +17,4 @@ import pbr.version
|
||||||
|
|
||||||
version_info = pbr.version.VersionInfo("fuel_ccp")
|
version_info = pbr.version.VersionInfo("fuel_ccp")
|
||||||
__version__ = version_info.version_string()
|
__version__ = version_info.version_string()
|
||||||
dsl_version = "0.2.0"
|
dsl_version = "0.3.0"
|
||||||
|
|
|
@ -125,7 +125,14 @@ def parse_role(component, topology, configmaps, jinja_imports):
|
||||||
else:
|
else:
|
||||||
replicas = replicas or 1
|
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)
|
replicas, component_name, strategy)
|
||||||
yield [obj]
|
yield [obj]
|
||||||
|
|
||||||
|
@ -192,7 +199,9 @@ def _process_ports(service):
|
||||||
if ingress_host:
|
if ingress_host:
|
||||||
ingress_rules.append(templates.serialize_ingress_rule(
|
ingress_rules.append(templates.serialize_ingress_rule(
|
||||||
service["name"], ingress_host, source_port))
|
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
|
yield service_template
|
||||||
|
|
||||||
if ingress_rules:
|
if ingress_rules:
|
||||||
|
|
|
@ -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):
|
strategy):
|
||||||
if strategy['type'] == 'RollingUpdate':
|
if strategy['type'] == 'RollingUpdate':
|
||||||
strategy.setdefault("rollingUpdate", {
|
strategy.setdefault("rollingUpdate", {
|
||||||
|
@ -327,7 +327,7 @@ def serialize_deployment(name, spec, affinity, replicas, component_name,
|
||||||
"strategy": strategy,
|
"strategy": strategy,
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"annotations": affinity,
|
"annotations": annotations,
|
||||||
"labels": {
|
"labels": {
|
||||||
"app": name,
|
"app": name,
|
||||||
"ccp": "true",
|
"ccp": "true",
|
||||||
|
@ -385,7 +385,7 @@ def serialize_affinity(service, topology):
|
||||||
policy, sort_keys=True)}
|
policy, sort_keys=True)}
|
||||||
|
|
||||||
|
|
||||||
def serialize_service(name, ports, headless=False):
|
def serialize_service(name, ports, headless=False, annotations=None):
|
||||||
ports_spec = []
|
ports_spec = []
|
||||||
for port in ports:
|
for port in ports:
|
||||||
spec_entry = {"port": port["port"],
|
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:
|
if not headless:
|
||||||
obj["spec"]["type"] = "NodePort"
|
obj["spec"]["type"] = "NodePort"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -213,6 +213,25 @@ spec:
|
||||||
objects = list(deploy._process_ports(service))
|
objects = list(deploy._process_ports(service))
|
||||||
self.assertEqual([yaml.load(service_k8s_obj)], objects)
|
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):
|
def test_create_ingress(self):
|
||||||
self.conf.configs._merge({'ingress': {'enabled': True,
|
self.conf.configs._merge({'ingress': {'enabled': True,
|
||||||
'domain': 'test'}})
|
'domain': 'test'}})
|
||||||
|
|
|
@ -198,6 +198,14 @@ SERVICE_SCHEMA = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"annotations": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
|
"properties": {
|
||||||
|
"pod": {"type": "object"},
|
||||||
|
"service": {"type": "object"},
|
||||||
|
}
|
||||||
|
},
|
||||||
"kind": {
|
"kind": {
|
||||||
"enum": ["Deployment", "DaemonSet"]
|
"enum": ["Deployment", "DaemonSet"]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue