Yuvipanda has uploaded a new change for review.
https://gerrit.wikimedia.org/r/298302
Change subject: Factor out container specification
......................................................................
Factor out container specification
Change-Id: I2cac81c8b439a0ba9622bd5a7d575d45ba4a9bce
---
M toollabs/webservice/backends/kubernetesbackend.py
1 file changed, 42 insertions(+), 39 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/operations/software/tools-webservice
refs/changes/02/298302/1
diff --git a/toollabs/webservice/backends/kubernetesbackend.py
b/toollabs/webservice/backends/kubernetesbackend.py
index 25b7948..afa014a 100644
--- a/toollabs/webservice/backends/kubernetesbackend.py
+++ b/toollabs/webservice/backends/kubernetesbackend.py
@@ -112,13 +112,6 @@
"""
Return the full spec of the deployment object for this webservice
"""
- # All the paths we want to mount from host nodes onto container
- hostMounts = {
- 'home': '/data/project/',
- 'scratch': '/data/scratch/',
- 'dumps': '/public/dumps/'
- }
-
cmd = [
"/usr/bin/webservice-runner",
"--type",
@@ -127,10 +120,14 @@
"8000"
]
- homedir = '/data/project/{toolname}/'.format(toolname=self.tool.name)
-
if self.extra_args:
cmd += " --extra-args '%s'" % self.extra_args
+
+ ports = [{
+ "name": "http",
+ "containerPort": 8000,
+ "protocol": "TCP"
+ }]
return {
"kind": "Deployment",
@@ -149,40 +146,46 @@
"metadata": {
"labels": self.labels
},
- "spec": {
- "volumes": [
- {"name": key, "hostPath": {"path": value}}
- for key, value in hostMounts.items()
- ],
- "containers": [
- {
- "name": "webservice",
- "image": self.container_image,
- "command": cmd,
- "workingDir": homedir,
- "env": [
- # FIXME: This should be set by NSS maybe?!
- {"name": "HOME", "value": homedir}
- ],
- "ports": [
- {
- "name": "http",
- "containerPort": 8000,
- "protocol": "TCP"
- }
- ],
- "volumeMounts": [
- {"name": key, "mountPath": value}
- for key, value in hostMounts.items()
- ],
- "resources": self.container_resources
- }
- ],
- }
+ "spec": self._get_container_spec("webservice",
self.container_image, cmd, self.container_resources, ports)
}
}
}
+ def _get_container_spec(self, name, container_image, cmd, resources,
ports=None, stdin=False, tty=False):
+ # All the paths we want to mount from host nodes onto container
+ hostMounts = {
+ 'home': '/data/project/',
+ 'scratch': '/data/scratch/',
+ 'dumps': '/public/dumps/'
+ }
+
+ homedir = '/data/project/{toolname}/'.format(toolname=self.tool.name)
+
+ return {
+ "volumes": [
+ {"name": key, "hostPath": {"path": value}}
+ for key, value in hostMounts.items()
+ ],
+ "containers": [{
+ "name": name,
+ "image": container_image,
+ "command": cmd,
+ "workingDir": homedir,
+ "env": [
+ # FIXME: This should be set by NSS maybe?!
+ {"name": "HOME", "value": homedir}
+ ],
+ "ports": ports,
+ "volumeMounts": [
+ {"name": key, "mountPath": value}
+ for key, value in hostMounts.items()
+ ],
+ "resources": resources,
+ "tty": tty,
+ "stdin": stdin
+ }],
+ }
+
def request_start(self):
self.webservice.check()
if self._find_obj(pykube.Deployment, self.label_selector) is None:
--
To view, visit https://gerrit.wikimedia.org/r/298302
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2cac81c8b439a0ba9622bd5a7d575d45ba4a9bce
Gerrit-PatchSet: 1
Gerrit-Project: operations/software/tools-webservice
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits