From c864534de655d0e66d90cae9728d72128a0268ca Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Tue, 1 Sep 2020 09:14:15 +0800
Subject: [PATCH] feat(controller):drycc run cmd add --mount para

---
 rootfs/api/models/app.py                 |  6 +++---
 rootfs/scheduler/resources/deployment.py | 13 -------------
 rootfs/scheduler/resources/pod.py        | 11 ++++++++++-
 3 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/rootfs/api/models/app.py b/rootfs/api/models/app.py
index 688f2013d..38c0fc34a 100644
--- a/rootfs/api/models/app.py
+++ b/rootfs/api/models/app.py
@@ -583,8 +583,8 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True):  # noqa
         volumes = self.volume_set.all()
         deploys = {}
         for scale_type, replicas in self.structure.items():
-            volumes = [_ for _ in volumes if scale_type in _.path.keys()]
-            deploys[scale_type] = self._gather_app_settings(release, app_settings, scale_type, replicas, volumes=volumes)  # noqa
+            scale_type_volumes = [_ for _ in volumes if scale_type in _.path.keys()]
+            deploys[scale_type] = self._gather_app_settings(release, app_settings, scale_type, replicas, volumes=scale_type_volumes)  # noqa
 
         # Sort deploys so routable comes first
         deploys = OrderedDict(sorted(deploys.items(), key=lambda d: d[1].get('routable')))
@@ -823,7 +823,7 @@ def pod_name(size=5, chars=string.ascii_lowercase + string.digits):
         if volumes:
             volume_objs = Volume.objects.filter(app=release.app, name__in=volumes.keys())
             for _ in volume_objs:
-                _.path["{}-{}".format(self.app.id, str(uuid.uuid4())[:7])] = volumes.get(_.name, None)  # noqa
+                _.path["run"] = volumes.get(_.name, None)  # noqa
                 volume_list.append(_)
         data = self._gather_app_settings(release, app_settings, process_type='run', replicas=1, volumes=volume_list)  # noqa
 
diff --git a/rootfs/scheduler/resources/deployment.py b/rootfs/scheduler/resources/deployment.py
index 215ed60c4..29b43079c 100644
--- a/rootfs/scheduler/resources/deployment.py
+++ b/rootfs/scheduler/resources/deployment.py
@@ -107,19 +107,6 @@ def manifest(self, namespace, name, image, entrypoint, command, spec_annotations
         # set the old deployment spec annotations on this deployment
         manifest['spec']['template']['metadata']['annotations'] = spec_annotations
 
-        # set volumes
-        if volumes:
-            exist_volumes = manifest['spec']['template']['spec'].get("volumes", [])  # noqa
-            for volume in volumes:
-                exist_volumes.append(
-                    {"name": volume.get('name'),
-                     "persistentVolumeClaim": {
-                         "claimName": volume.get('claimName')
-                     }})
-            manifest['spec']['template']['spec']['volumes'] = exist_volumes
-
-        return manifest
-
     def create(self, namespace, name, image, entrypoint, command, spec_annotations, **kwargs):
         manifest = self.manifest(namespace, name, image,
                                  entrypoint, command, spec_annotations, **kwargs)
diff --git a/rootfs/scheduler/resources/pod.py b/rootfs/scheduler/resources/pod.py
index 416f566be..958317aaf 100644
--- a/rootfs/scheduler/resources/pod.py
+++ b/rootfs/scheduler/resources/pod.py
@@ -99,6 +99,7 @@ def state(self, pod):
     def manifest(self, namespace, name, image, **kwargs):
         app_type = kwargs.get('app_type')
         build_type = kwargs.get('build_type')
+        volumes = kwargs.get('volumes')
 
         # labels that represent the pod(s)
         labels = {
@@ -147,7 +148,15 @@ def manifest(self, namespace, name, image, **kwargs):
                 'mountPath': '/var/run/secrets/drycc/objectstore/creds',
                 'readOnly': True
             }]
-
+        if volumes:
+            exist_volumes = spec.get('volumes', [])
+            for volume in volumes:
+                exist_volumes.append(
+                    {"name": volume.get('name'),
+                     "persistentVolumeClaim": {
+                         "claimName": volume.get('claimName')
+                     }})
+            spec['volumes'] = exist_volumes
         # create the base container
         container = {}
 
