diff --git a/rootfs/api/models/app.py b/rootfs/api/models/app.py index d6ad92697..ecb232e00 100644 --- a/rootfs/api/models/app.py +++ b/rootfs/api/models/app.py @@ -1081,6 +1081,9 @@ def _gather_app_settings(self, release, app_settings, process_type, replicas): # set the image pull policy that is associated with the application container image_pull_policy = config.values.get('IMAGE_PULL_POLICY', settings.IMAGE_PULL_POLICY) + # set pod ip if this variable is set + set_pod_ip = config.values.get('DEIS_EXPOSE_POD_IP', settings.DEIS_EXPOSE_POD_IP) + # create image pull secret if needed image_pull_secret_name = self.image_pull_secret(self.id, config.registry, release.image) @@ -1113,7 +1116,8 @@ def _gather_app_settings(self, release, app_settings, process_type, replicas): 'pod_termination_grace_period_seconds': pod_termination_grace_period_seconds, 'pod_termination_grace_period_each': config.termination_grace_period, 'image_pull_secret_name': image_pull_secret_name, - 'image_pull_policy': image_pull_policy + 'image_pull_policy': image_pull_policy, + 'set_pod_ip': set_pod_ip } def set_application_config(self, release): diff --git a/rootfs/api/settings/production.py b/rootfs/api/settings/production.py index 91882ae15..8223c2311 100644 --- a/rootfs/api/settings/production.py +++ b/rootfs/api/settings/production.py @@ -269,6 +269,10 @@ SLUGRUNNER_IMAGE = os.environ.get('SLUGRUNNER_IMAGE_NAME', 'quay.io/deisci/slugrunner:canary') # noqa IMAGE_PULL_POLICY = os.environ.get('IMAGE_PULL_POLICY', "IfNotPresent") # noqa +# Pod IP Exposure +DEIS_EXPOSE_POD_IP = bool(os.environ.get('DEIS_EXPOSE_POD_IP', False)) + + # True, true, yes, y and more evaluate to True # False, false, no, n and more evaluate to False # https://docs.python.org/3/distutils/apiref.html?highlight=distutils.util#distutils.util.strtobool diff --git a/rootfs/scheduler/resources/pod.py b/rootfs/scheduler/resources/pod.py index 03af2b90a..cae144d27 100644 --- a/rootfs/scheduler/resources/pod.py +++ b/rootfs/scheduler/resources/pod.py @@ -217,6 +217,17 @@ def _set_container(self, namespace, container_name, data, **kwargs): "value": "1" }) + # Inject POD_IP variable with Pod's IP address + if kwargs.get('set_pod_ip') == 'True': + data["env"].append({ + "name": "POD_IP", + "valueFrom": { + "fieldRef": { + "fieldPath": "status.podIP", + } + } + }) + # list sorted by dict key name data['env'].sort(key=operator.itemgetter('name')) @@ -341,6 +352,7 @@ def _default_readiness_probe(self, container, build_type, port=None): This should be added only for the build pack apps when a custom liveness probe is not set to make sure that the pod is ready only when the slug is downloaded and started running. """ + def _default_buildpack_readiness_probe(self, delay=30, timeout=5, period_seconds=5, success_threshold=1, failure_threshold=1): readinessprobe = {