Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion paddlecloud/notebook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def create_user_namespace(username):
secrets = v1api.list_namespaced_secret(user_namespace)
for dc, cfg in settings.DATACENTERS.items():
#create Kubernetes Secret for admin key
if cfg["type"] == "cephfs":
if cfg["fstype"] == "cephfs":
secret_found = False
for ss in secrets.items:
if ss.metadata.name == cfg["secret"]:
Expand All @@ -158,6 +158,20 @@ def create_user_namespace(username):
"data": {
"key": encoded
}})
registry_secret = settings.JOB_DOCKER_IMAGE.get("registry_secret", None)
if registry_secret and registry_secret not in secrets:
docker_config = settings.JOB_DOCKER_IMAGE["docker_config"]
encode = base64.b64encode(json.dumps(docker_config))
v1api.create_namespaced_secret(user_namespace, {
"apiVersion": "v1",
"kind": "Secret",
"metadata": {
"name": registry_secret
},
"data": {
".dockerconfigjson": encode
}
})
return user_namespace


Expand Down
8 changes: 8 additions & 0 deletions paddlecloud/paddlecloud/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,11 @@
"admin_key": "/certs/admin.secret"
}
}

JOB_DOCKER_IMAGE = {
"image": "yancey1989/paddlecloud-job",
"registry_secret": "job-registry-secret",
"docker_config":{"auths":
{"registry.baidu.com":
{"auth": "eWFueHUwNTpRTndVSGV1Rldl"}}}
}
15 changes: 11 additions & 4 deletions paddlecloud/paddlejob/paddle_job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import kubernetes
from kubernetes import client, config
import os

__all__ = ["PaddleJob"]
DEFAULT_PADDLE_PORT=7164

Expand All @@ -21,7 +20,8 @@ def __init__(self,
topology,
image,
gpu=0,
volumes=[]):
volumes=[],
registry_secret=None):

self._ports_num=1
self._ports_num_for_sparse=1
Expand All @@ -39,6 +39,7 @@ def __init__(self,
self._topology = topology
self._image = image
self._volumes = volumes
self._registry_secret = registry_secret

@property
def pservers(self):
Expand Down Expand Up @@ -111,7 +112,7 @@ def new_trainer_job(self):
"""
return: Trainer job, it's a Kubernetes Job
"""
return {
job = {
"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
Expand Down Expand Up @@ -139,11 +140,14 @@ def new_trainer_job(self):
}
}
}
if self._registry_secret:
job["spec"]["template"]["spec"].update({"imagePullSecrets": [{"name": self._registry_secret}]})
return job
def new_pserver_job(self):
"""
return: PServer job, it's a Kubernetes ReplicaSet
"""
return {
rs = {
"apiVersion": "extensions/v1beta1",
"kind": "ReplicaSet",
"metadata":{
Expand All @@ -167,3 +171,6 @@ def new_pserver_job(self):
}
}
}
if self._registry_secret:
rs["spec"]["template"]["spec"].update({"imagePullSecrets": [{"name": self._registry_secret}]})
return rs
7 changes: 5 additions & 2 deletions paddlecloud/paddlejob/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import utils
import notebook.utils
import logging
import volume

class JobsView(APIView):
permission_classes = (permissions.IsAuthenticated,)
Expand Down Expand Up @@ -40,8 +41,9 @@ def post(self, request, format=None):
dc = obj.get("datacenter")
volumes = []
if dc in settings.DATACENTERS:
volumes.append(volume.get_volume_config(settings.DATACENTERS[dc]))
volumes.append(volume.get_volume_config(name=dc.replace("_","-"), **settings.DATACENTERS[dc]))

registry_secret = settings.JOB_DOCKER_IMAGE.get("registry_secret", None)
paddle_job = PaddleJob(
name = obj.get("name", "paddle-cluster-job"),
job_package = obj.get("jobPackage", ""),
Expand All @@ -53,7 +55,8 @@ def post(self, request, format=None):
psmemory = obj.get("psmemory", "1Gi"),
topology = obj["topology"],
gpu = obj.get("gpu", 0),
image = obj.get("image", "yancey1989/paddlecloud-job"),
image = obj.get("image", settings.JOB_DOCKER_IMAGE["image"]),
registry_secret = registry_secret,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if we configured registry secrets, if not no need to provide this, using a public image.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, if there is no registry_secret be configured: L46, and the Kubernetes job won't use registry secret.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool.

volumes = volumes
)
try:
Expand Down
5 changes: 3 additions & 2 deletions paddlecloud/paddlejob/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __render(tmpl, **kwargs):
for k, v in kwargs.items():
tmpl_k = "$%s" % k.upper()
if tmpl_k in tmpl:
if type(v) is str:
if type(v) is str or type(v) is unicode:
tmpl = tmpl.replace(tmpl_k, "\"%s\"" % v)
elif type(v) is list:
tmpl = tmpl.replace(tmpl_k, json.dumps(v))
Expand All @@ -31,7 +31,7 @@ def __get_template(tmpls, fstype):
else:
return ""

def get_volume_config(fstype, **kwargs):
def get_volume_config(**kwargs):
"""
:param fstype: which filesystem type
:type fstype: str
Expand Down Expand Up @@ -60,6 +60,7 @@ def get_volume_config(fstype, **kwargs):
:param mount_path: mount path in Pod
:type mount_path: str
"""
fstype = kwargs["fstype"]
tmpl_v = __get_template(tmpl_volume, fstype)
tmpl_vm = __get_template(tmpl_volume_mount, fstype)
return {"volume":json.loads(__render(tmpl=tmpl_v, **kwargs)),
Expand Down