-
Notifications
You must be signed in to change notification settings - Fork 78
Hostpath volume #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hostpath volume #60
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,6 +270,15 @@ | |
| # "admin_key": "/certs/admin.secret" | ||
| # } | ||
| #} | ||
| #for HostPath example: | ||
| #DATACENTERS = { | ||
| # ... | ||
| # "dc1":{ | ||
| # "type": "hostpath", | ||
|
||
| # "host_path": "/mnt/hdfs/", | ||
| # "mount_path" "/pfs/dc1/home/%s/" # mount_path % username | ||
| # } | ||
| #} | ||
| DATACENTERS = { | ||
| "datacenter1":{ | ||
| "type": "cephfs", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| from paddle_job import PaddleJob | ||
| from cephfs_volume import CephFSVolume | ||
|
|
||
| __all__ = ["CephFSVolume", "PaddleJob"] | ||
| import volumes | ||
| __all__ = ["volumes", "PaddleJob"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,8 @@ | |
| from django.conf import settings | ||
| from kubernetes import client, config | ||
| from kubernetes.client.rest import ApiException | ||
| from . import PaddleJob, CephFSVolume | ||
| from . import PaddleJob | ||
| from volumes import CephFSVolume, HostPathVolume | ||
| from rest_framework.authtoken.models import Token | ||
| from rest_framework import viewsets, generics, permissions | ||
| from rest_framework.response import Response | ||
|
|
@@ -40,14 +41,21 @@ def post(self, request, format=None): | |
| dc = obj.get("datacenter") | ||
| volumes = [] | ||
| for name, cfg in settings.DATACENTERS.items(): | ||
| if cfg["type"] == "cephfs": | ||
| volumes.append(CephFSVolume( | ||
| monitors_addr = cfg["monitors_addr"], | ||
| user = cfg["user"], | ||
| secret_name = cfg["secret"], | ||
| mount_path = cfg["mount_path"] % username, | ||
| cephfs_path = cfg["cephfs_path"] % username | ||
| )) | ||
| if dc == name: | ||
| if cfg["type"] == "cephfs": | ||
| volumes.append(CephFSVolume( | ||
|
||
| monitors_addr = cfg["monitors_addr"], | ||
| user = cfg["user"], | ||
| secret_name = cfg["secret"], | ||
| mount_path = cfg["mount_path"] % username, | ||
| cephfs_path = cfg["cephfs_path"] % username | ||
| )) | ||
| elif cfg["type"] == "hostpath": | ||
| volumes.append(HostPathVolume( | ||
| name = dc.replace("_", "-"), | ||
| host_path = cfg["host_path"], | ||
| mount_path = cfg["mount_path"] % username | ||
| )) | ||
|
|
||
|
|
||
| paddle_job = PaddleJob( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from cephfs_volume import CephFSVolume | ||
|
||
| from hostpath_volume import HostPathVolume | ||
|
|
||
| __all__ = ["CephFSVolume", "HostPathVolume"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from volume import Volume | ||
| __all__ = ["HostPathVolume"] | ||
| class HostPathVolume(Volume): | ||
| def __init__(self, name, host_path, mount_path): | ||
| self._name = name | ||
| self._host_path = host_path | ||
| self._mount_path = mount_path | ||
|
|
||
| @property | ||
| def volume(self): | ||
| return { | ||
| "name": self._name, | ||
| "hostPath": { | ||
| "path": self._host_path | ||
| } | ||
| } | ||
|
|
||
| @property | ||
| def volume_mount(self): | ||
| return { | ||
| "name": self._name, | ||
| "mountPath": self._mount_path | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
|
|
||
| class Volume(object): | ||
| def __init__(self): | ||
| pass | ||
|
|
||
| @property | ||
| def volume(self): | ||
| return {} | ||
|
|
||
| @property | ||
| def volume_mount(self): | ||
| return {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should contain
typein this example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type=>fstypeDone.