Commit f03a4fb5 authored by Daniele Venzano's avatar Daniele Venzano

Implement labels and fix several bugs

parent fe3120c9
...@@ -145,10 +145,18 @@ ...@@ -145,10 +145,18 @@
}, },
"work_dir": { "work_dir": {
"type": "string", "minLength": 1 "type": "string", "minLength": 1
},
"labels": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 0,
"uniqueItems": true
} }
}, },
"additionalProperties": false, "additionalProperties": false,
"required": ["name", "image", "ports", "environment", "volumes", "monitor", "startup_order", "essential_count", "total_count", "resources", "command", "replicas"] "required": ["name", "image", "ports", "environment", "volumes", "monitor", "startup_order", "essential_count", "total_count", "resources", "command"]
}, },
"port": { "port": {
"type": "object", "type": "object",
......
...@@ -108,6 +108,15 @@ ...@@ -108,6 +108,15 @@
{% endif %} {% endif %}
</div> </div>
<div class="container_count">{{ node['container_count'] }} containers</div> <div class="container_count">{{ node['container_count'] }} containers</div>
{% if node['labels']|length > 0 %}
<div class="container_count">Labels:
{% for label in node['labels'] %}
{{ label }}&nbsp;
{% endfor %}
</div>
{% else %}
<div class="container_count">No labels</div>
{% endif %}
<div class="plot-container"> <div class="plot-container">
<p>Memory</p> <p>Memory</p>
......
...@@ -160,9 +160,9 @@ class Service: ...@@ -160,9 +160,9 @@ class Service:
self.volumes = [VolumeDescriptionHostPath(v[0], v[1], v[2]) for v in self.description['volumes']] self.volumes = [VolumeDescriptionHostPath(v[0], v[1], v[2]) for v in self.description['volumes']]
try: try:
self.replicas = self.description['replicas'] self.labels = self.description['labels']
except KeyError: except KeyError:
self.replicas = 0 self.labels = []
def serialize(self): def serialize(self):
"""Generates a dictionary that can be serialized in JSON.""" """Generates a dictionary that can be serialized in JSON."""
......
...@@ -32,7 +32,7 @@ class DockerHostConfig: ...@@ -32,7 +32,7 @@ class DockerHostConfig:
self.tls_cert = None self.tls_cert = None
self.tls_key = None self.tls_key = None
self.tls_ca = None self.tls_ca = None
self.labels = [] self.labels = set()
class DockerConfig: class DockerConfig:
...@@ -61,7 +61,7 @@ class DockerConfig: ...@@ -61,7 +61,7 @@ class DockerConfig:
continue continue
if 'labels' in config[section]: # labels are optional if 'labels' in config[section]: # labels are optional
host.labels = config[section]['labels'].split(',') host.labels = set(config[section]['labels'].split(','))
hosts.append(host) hosts.append(host)
if len(hosts) == 0: if len(hosts) == 0:
......
...@@ -112,7 +112,8 @@ class DockerStateSynchronizer(threading.Thread): ...@@ -112,7 +112,8 @@ class DockerStateSynchronizer(threading.Thread):
node_stats.container_count = info['Containers'] node_stats.container_count = info['Containers']
node_stats.cores_total = info['NCPU'] node_stats.cores_total = info['NCPU']
node_stats.memory_total = info['MemTotal'] node_stats.memory_total = info['MemTotal']
node_stats.labels += info['Labels'] if info['Labels'] is not None:
node_stats.labels += set(info['Labels'])
stats = {} stats = {}
for cont in container_list: for cont in container_list:
......
...@@ -242,7 +242,7 @@ class KubernetesClient: ...@@ -242,7 +242,7 @@ class KubernetesClient:
config.set_labels(ZOE_LABELS) config.set_labels(ZOE_LABELS)
config.set_labels({'service_name': service_instance.name}) config.set_labels({'service_name': service_instance.name})
config.set_replicas(service_instance.replicas_count) config.set_replicas(1)
config.set_spec_selector(ZOE_LABELS) config.set_spec_selector(ZOE_LABELS)
config.set_spec_selector({'service_name': service_instance.name}) config.set_spec_selector({'service_name': service_instance.name})
......
...@@ -69,5 +69,3 @@ class ServiceInstance: ...@@ -69,5 +69,3 @@ class ServiceInstance:
self.ports = [] self.ports = []
for port in service.ports: for port in service.ports:
self.ports.append(BackendPort(port.internal_number, port.protocol)) self.ports.append(BackendPort(port.internal_number, port.protocol))
self.replicas_count = service.replicas
...@@ -26,14 +26,16 @@ class SimulatedNode: ...@@ -26,14 +26,16 @@ class SimulatedNode:
def service_fits(self, service: Service) -> bool: def service_fits(self, service: Service) -> bool:
"""Checks whether a service can fit in this node""" """Checks whether a service can fit in this node"""
return service.resource_reservation.memory.min < self.node_free_memory() and service.resource_reservation.cores.min <= self.node_free_cores() return set(service.labels).issubset(self.labels) and service.resource_reservation.memory.min < self.node_free_memory() and service.resource_reservation.cores.min <= self.node_free_cores()
def service_why_unfit(self, service) -> str: def service_why_unfit(self, service) -> str:
"""Generate an explanation of why the service does not fit this node.""" """Generate an explanation of why the service does not fit this node."""
if service.resource_reservation.memory.min < self.node_free_memory(): if service.resource_reservation.memory.min >= self.node_free_memory():
return 'needs {} bytes of memory'.format(self.node_free_memory() - service.resource_reservation.memory.min) return 'needs {} bytes of memory'.format(self.node_free_memory() - service.resource_reservation.memory.min)
elif service.resource_reservation.cores.min <= self.node_free_cores(): elif service.resource_reservation.cores.min > self.node_free_cores():
return 'needs {} more cores'.format(self.node_free_cores() - service.resource_reservation.cores.min) return 'needs {} more cores'.format(self.node_free_cores() - service.resource_reservation.cores.min)
elif not set(service.labels).issubset(self.labels):
return 'service required labels {} to be defined on the node'.format(service.labels)
def service_add(self, service): def service_add(self, service):
"""Add a service in this node.""" """Add a service in this node."""
......
...@@ -55,7 +55,7 @@ class NodeStats(Stats): ...@@ -55,7 +55,7 @@ class NodeStats(Stats):
'memory_total': self.memory_total, 'memory_total': self.memory_total,
'memory_reserved': self.memory_reserved, 'memory_reserved': self.memory_reserved,
'memory_in_use': self.memory_in_use, 'memory_in_use': self.memory_in_use,
'labels': self.labels, 'labels': list(self.labels),
'status': self.status, 'status': self.status,
'error': self.error, 'error': self.error,
'services': [] 'services': []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment