Skip to content

Commit d5d267a

Browse files
author
Matthew Fisher
committed
fix(k8s): pull image from private registry and inspect image
1 parent 59960a2 commit d5d267a

1 file changed

Lines changed: 8 additions & 24 deletions

File tree

rootfs/scheduler/k8s.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ def create(self, name, image, command, **kwargs):
477477
"""Create a container."""
478478
logger.debug('create {}, img {}, params {}, cmd "{}"'.format(name, image, kwargs, command))
479479
self._create_rc(name, image, command, **kwargs)
480+
image = self.registry + '/' + image
480481
app_type = name.split('.')[1]
481482
name = name.replace('.', '-').replace('_', '-')
482483
app_name = kwargs.get('aname', {})
@@ -488,7 +489,7 @@ def create(self, name, image, command, **kwargs):
488489
if app_type in ['web', 'cmd']:
489490
data = {'metadata': {'labels': {'routable': 'true'}}}
490491

491-
self._create_service(name, app_name, app_type, data)
492+
self._create_service(name, app_name, app_type, data, image=image)
492493
except:
493494
self._scale_app(name, 0, app_name)
494495
self._delete_rc(name, app_name)
@@ -502,31 +503,14 @@ def _get_service(self, name, namespace):
502503

503504
return response
504505

505-
def _create_service(self, name, app_name, app_type, data={}):
506-
actual_pod = {}
507-
for _ in xrange(300):
508-
status, json_data, reason = self._get_pods(app_name)
509-
parsed_json = json.loads(json_data)
510-
for pod in parsed_json['items']:
511-
if('generateName' in pod['metadata'] and
512-
pod['metadata']['generateName'] == name + '-'):
513-
actual_pod = pod
514-
break
515-
516-
if actual_pod and actual_pod['status']['phase'] == 'Running':
517-
break
518-
519-
time.sleep(1)
520-
521-
container_id = actual_pod['status']['containerStatuses'][0]['containerID'].split("//")[1]
522-
# ip = actual_pod['status']['hostIP']
523-
# TODO: more robust way of determining the first exposed port--this will only work on
524-
# the node where this deis/workflow pod is running.
525-
# Find the first exposed port by inspecting the Docker container
506+
def _create_service(self, name, app_name, app_type, data={}, **kwargs):
526507
docker_cli = Client(version="auto")
527508
try:
528-
container = docker_cli.inspect_container(container_id)
529-
port = int(container['Config']['ExposedPorts'].keys()[0].split("/")[0])
509+
image = kwargs.get('image')
510+
# image already includes the tag, so we split it out here
511+
docker_cli.pull(image.rsplit(':')[0], image.rsplit(':')[1])
512+
image_info = docker_cli.inspect_image(image)
513+
port = int(image_info['Config']['ExposedPorts'].keys()[0].split("/")[0])
530514
except:
531515
port = 5000
532516

0 commit comments

Comments
 (0)