Commit ac9623f1 authored by Daniele Venzano's avatar Daniele Venzano

Fix volumes according to Nhat's comments

parent c9057b4e
......@@ -18,5 +18,5 @@
from zoe_lib.state.base import Base
from zoe_lib.state.execution import Execution
from zoe_lib.state.sql_manager import SQLManager
from zoe_lib.state.service import Service, VolumeDescription
from zoe_lib.state.service import Service, VolumeDescription, VolumeDescriptionHostPath
from zoe_lib.state.port import Port
......@@ -70,7 +70,7 @@ class VolumeDescription:
class VolumeDescriptionHostPath(VolumeDescription):
"""Host-based volumes."""
def __init__(self, name: str, path: str, readonly: bool):
super().__init__("host-directory")
super().__init__("host_directory")
self.path = path
self.mount_point = '/mnt/' + name
self.readonly = readonly
......
......@@ -26,7 +26,7 @@ import pykube
from zoe_master.stats import ClusterStats, NodeStats
from zoe_master.backends.service_instance import ServiceInstance
from zoe_lib.version import ZOE_VERSION
from zoe_lib.state import VolumeDescription
from zoe_lib.state import VolumeDescription, VolumeDescriptionHostPath
from zoe_lib.config import get_conf
log = logging.getLogger(__name__)
......@@ -191,22 +191,29 @@ class KubernetesReplicationControllerConf:
count = 0
for vol in volumes:
if vol.type != "host_directory":
log.error('Swarm backend does not support volume type {}'.format(vol.type))
aux['spec']['containers'][0]['volumeMounts'][count]['mountPath'] = vol.mount_point
aux['spec']['containers'][0]['volumeMounts'][count]['name'] = name + "-" + str(count)
count += 1
if vol.type == "host_directory":
assert isinstance(vol, VolumeDescriptionHostPath)
aux['spec']['containers'][0]['volumeMounts'][count]['mountPath'] = vol.mount_point
aux['spec']['containers'][0]['volumeMounts'][count]['name'] = name + "-" + str(count)
count += 1
else:
log.error('Kubernetes backend does not support volume type {}'.format(vol.type))
continue
aux['spec']['volumes'] = [{} for _ in range(len(volumes))]
count = 0
for vol in volumes:
aux['spec']['volumes'][count]['name'] = name + "-" + str(count)
aux['spec']['volumes'][count]['hostPath'] = {
'path': vol.path
}
count += 1
if vol.type == "host_directory":
assert isinstance(vol, VolumeDescriptionHostPath)
aux['spec']['volumes'][count]['name'] = name + "-" + str(count)
aux['spec']['volumes'][count]['hostPath'] = {
'path': vol.path
}
count += 1
else:
log.error('Kubernetes backend does not support volume type {}'.format(vol.type))
continue
def get_json(self):
"""Get json file"""
......
......@@ -40,7 +40,7 @@ import docker.models.containers
import requests.exceptions
from zoe_lib.config import get_conf
from zoe_lib.state import Service
from zoe_lib.state import Service, VolumeDescriptionHostPath
from zoe_master.stats import ClusterStats, NodeStats
from zoe_master.backends.service_instance import ServiceInstance
from zoe_master.exceptions import ZoeException, ZoeNotEnoughResourcesException
......@@ -169,9 +169,11 @@ class SwarmClient:
volumes = {}
for volume in service_instance.volumes:
if volume.type != "host_directory":
if volume.type == "host_directory":
assert isinstance(volume, VolumeDescriptionHostPath)
volumes[volume.path] = {'bind': volume.mount_point, 'mode': ("ro" if volume.readonly else "rw")}
else:
log.error('Swarm backend does not support volume type {}'.format(volume.type))
volumes[volume.path] = {'bind': volume.mount_point, 'mode': ("ro" if volume.readonly else "rw")}
if service_instance.memory_limit is not None:
mem_limit = service_instance.memory_limit.max
......
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