Skip to content

Commit

Permalink
change default of mpi-operator to v1alpha2 (#2)
Browse files Browse the repository at this point in the history
* change PyYAML to 5.1

* make mpijob great again!

* imagePullPolicy

* bump to 0.0.2

* remove pull policy never

* bump 0.0.3

* change default of mph-operator to v1alpha2
  • Loading branch information
gshatz authored Jul 14, 2019
1 parent 79800af commit 6aa5e8e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ verify_ssl = true

[packages]
kubernetes = "==9.0.0"
PyYAML = "==5.1.1"
PyYAML = "==5.1"

[requires]
python_version = "3.7"
2 changes: 1 addition & 1 deletion v3io_gputils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.1'
__version__ = '0.0.4'
31 changes: 21 additions & 10 deletions v3io_gputils/mpijob.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from kubernetes.client.rest import ApiException

_mpijob_template = {
'apiVersion': 'kubeflow.org/v1alpha1',
'apiVersion': 'kubeflow.org/v1alpha2',
'kind': 'MPIJob',
'metadata': {
'name': '',
Expand All @@ -17,15 +17,24 @@
'template': {
'spec': {
'containers': [{
'image': 'gshatz/horovod:0.1.0',
'image': 'iguaziodocker/horovod:0.1.1',
'name': '',
'command': [],
'volumeMounts': [],
'volumeMounts': [{'name': 'v3io', 'mountPath': '/User'}],
'securityContext': {
'capabilities': {'add': ['IPC_LOCK']}},
'resources': {
'limits': {'nvidia.com/gpu': 1}}}],
'volumes': []
'volumes': [{
'name': 'v3io',
'flexVolume': {
'driver': 'v3io/fuse',
'options': {
'container': 'users',
'subPath': '/iguazio',
'accessKey': '',
}
}}]
}}}}


Expand All @@ -38,17 +47,16 @@ class MpiJob:
from mpijob import MpiJob
job = MpiJob('myname', 'img', ['a','b'])
job.volume() # add v3io volume
print(job.to_yaml())
job.submit()
"""
group = 'kubeflow.org'
version = 'v1alpha1'
version = 'v1alpha2'
plural = 'mpijobs'

def __init__(self, name, image=None, command=None,
replicas=0, namespace='default-tenant'):
replicas=1, namespace='default-tenant'):
self.api_instance = None
self.name = name
self.namespace = namespace
Expand All @@ -61,10 +69,14 @@ def __init__(self, name, image=None, command=None,
self._update_container('command', ['mpirun','python'] + command)
if replicas:
self._struct['spec']['replicas'] = replicas
self._update_access_token(environ.get('V3IO_ACCESS_KEY',''))

def _update_container(self, key, value):
self._struct['spec']['template']['spec']['containers'][0][key] = value

def _update_access_token(self, token):
self._struct['spec']['template']['spec']['volumes'][0]['flexVolume']['options']['accessKey'] = token

def volume(self, mount='/User', volpath='~/', access_key=''):
self._update_container('volumeMounts', [{'name': 'v3io', 'mountPath': mount}])

Expand Down Expand Up @@ -114,15 +126,14 @@ def submit(self):

def delete(self):
try:
# delete the mpi job\
# delete the mpi job
body = client.V1DeleteOptions()
api_response = self.api_instance.delete_namespaced_custom_object(
MpiJob.group, MpiJob.version, self.namespace, MpiJob.plural, self.name, body)
pprint(api_response)
except ApiException as e:
print("Exception when calling CustomObjectsApi->delete_namespaced_custom_object: %s\\n" % e)


def split_path(mntpath=''):
if mntpath[0] == '/':
mntpath = mntpath[1:]
Expand All @@ -131,4 +142,4 @@ def split_path(mntpath=''):
subpath = ''
if len(paths) > 1:
subpath = mntpath[len(container):]
return container, subpath
return container, subpath

0 comments on commit 6aa5e8e

Please sign in to comment.