|
8 | 8 | import base64 |
9 | 9 |
|
10 | 10 | from django.conf import settings |
11 | | -from docker import Client |
12 | 11 | from .states import JobState |
13 | 12 | import requests |
14 | 13 | from requests_toolbelt import user_agent |
15 | 14 | from .utils import dict_merge |
16 | | -from retrying import retry |
17 | 15 |
|
18 | 16 | from deis import __version__ as deis_version |
19 | 17 |
|
@@ -343,22 +341,9 @@ def __init__(self): |
343 | 341 | def deploy(self, namespace, name, image, command, **kwargs): # noqa |
344 | 342 | logger.debug('deploy {}, img {}, params {}, cmd "{}"'.format(name, image, kwargs, command)) |
345 | 343 | app_type = kwargs.get('app_type') |
346 | | - build_type = kwargs.get('build_type') |
347 | 344 | routable = kwargs.get('routable', False) |
348 | | - port = None |
349 | | - |
350 | | - try: |
351 | | - if routable: |
352 | | - if build_type == "buildpack": |
353 | | - logger.debug("Using default port 5000 for build pack app {}".format(name)) |
354 | | - port = 5000 |
355 | | - else: |
356 | | - port = self._get_port(image) |
357 | | - if port is None: |
358 | | - raise Exception("Expose a port or make the app non routable by changing" |
359 | | - " the process type") |
360 | | - except Exception as e: |
361 | | - raise KubeException('{} (scheduler::deploy): {}'.format(name, e)) |
| 345 | + envs = kwargs.get('envs', {}) |
| 346 | + port = envs.get('PORT', None) |
362 | 347 |
|
363 | 348 | # Fetch old RC and create the new one for a release |
364 | 349 | old_rc = self._get_old_rc(namespace, app_type) |
@@ -686,7 +671,7 @@ def _set_container(self, namespace, data, **kwargs): # noqa |
686 | 671 | if kwargs.get('healthcheck', None): |
687 | 672 | self._healthcheck(namespace, data, kwargs.get('routable'), **kwargs['healthcheck']) |
688 | 673 | else: |
689 | | - self._default_readiness_probe(data, kwargs.get('build_type'), kwargs.get('image')) |
| 674 | + self._default_readiness_probe(data, kwargs.get('build_type'), kwargs.get('port', None)) |
690 | 675 |
|
691 | 676 | def resolve_state(self, pod): |
692 | 677 | # See "Pod Phase" at http://kubernetes.io/v1.1/docs/user-guide/pod-states.html |
@@ -722,19 +707,6 @@ def resolve_state(self, pod): |
722 | 707 |
|
723 | 708 | return states.get(pod_state, pod_state) |
724 | 709 |
|
725 | | - @retry(stop_max_attempt_number=3, wait_fixed=1000) |
726 | | - def _get_port(self, image): |
727 | | - # try thrice to find the port before raising exception as docker-py is flaky |
728 | | - repo = image.split(":") |
729 | | - # image already includes the tag, so we split it out here |
730 | | - docker_cli = Client(version="auto") |
731 | | - docker_cli.pull(repo[0]+":"+repo[1], tag=repo[2], insecure_registry=True) |
732 | | - image_info = docker_cli.inspect_image(image) |
733 | | - if 'ExposedPorts' not in image_info['Config']: |
734 | | - return None |
735 | | - port = int(list(image_info['Config']['ExposedPorts'].keys())[0].split("/")[0]) |
736 | | - return port |
737 | | - |
738 | 710 | def _api(self, tmpl, *args): |
739 | 711 | """Return a fully-qualified Kubernetes API URL from a string template with args.""" |
740 | 712 | url = "/api/{}".format(self.apiversion) + tmpl.format(*args) |
@@ -1165,12 +1137,12 @@ def _healthcheck(self, namespace, container, routable=False, path='/', port=5000 |
1165 | 1137 | # Update only the application container with the health check |
1166 | 1138 | container.update(healthcheck) |
1167 | 1139 |
|
1168 | | - def _default_readiness_probe(self, container, build_type, image): |
| 1140 | + def _default_readiness_probe(self, container, build_type, port=None): |
1169 | 1141 | # Update only the application container with the health check |
1170 | 1142 | if build_type == "buildpack": |
1171 | 1143 | container.update(self._default_buildpack_readiness_probe()) |
1172 | | - else: |
1173 | | - container.update(self._default_dockerapp_readiness_probe(image)) |
| 1144 | + elif port: |
| 1145 | + container.update(self._default_dockerapp_readiness_probe(port)) |
1174 | 1146 |
|
1175 | 1147 | ''' |
1176 | 1148 | Applies exec readiness probe to the slugrunner container. |
@@ -1213,15 +1185,8 @@ def _default_buildpack_readiness_probe(self, delay=30, timeout=5, period_seconds |
1213 | 1185 | Applies tcp socket readiness probe to the docker app container only if some port is exposed |
1214 | 1186 | by the docker image. |
1215 | 1187 | ''' |
1216 | | - def _default_dockerapp_readiness_probe(self, image, delay=5, timeout=5, period_seconds=5, |
| 1188 | + def _default_dockerapp_readiness_probe(self, port, delay=5, timeout=5, period_seconds=5, |
1217 | 1189 | success_threshold=1, failure_threshold=1): |
1218 | | - try: |
1219 | | - port = self._get_port(image) |
1220 | | - if port is None: |
1221 | | - return None |
1222 | | - except Exception: |
1223 | | - return None |
1224 | | - |
1225 | 1190 | readinessprobe = { |
1226 | 1191 | 'readinessProbe': { |
1227 | 1192 | # an exec probe |
|
0 commit comments