From b02b0484b81b93c0cb4ab79e49fbe5a42bb94f70 Mon Sep 17 00:00:00 2001 From: Santiago Del Castillo Date: Fri, 26 Jul 2019 12:20:58 +0200 Subject: [PATCH 1/3] feat(controller): Add POD_IP variable with pod's IP address --- rootfs/scheduler/resources/pod.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rootfs/scheduler/resources/pod.py b/rootfs/scheduler/resources/pod.py index 03af2b90a..5b9ef9bed 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 os.environ.get("DEIS_EXPOSE_POD_IP", False): + data["env"].append({ + "name": "POD_IP", + "valueFrom": { + "fieldRef": { + "fieldPath": "status.podIP", + } + } + }) + # list sorted by dict key name data['env'].sort(key=operator.itemgetter('name')) From f1642a1ca0512205c5090505be190067cc323a84 Mon Sep 17 00:00:00 2001 From: Santiago Del Castillo Date: Tue, 6 Aug 2019 19:27:16 +0200 Subject: [PATCH 2/3] feat(app.py): refactor DEIS_EXPOSE_POD_IP logic in controller --- rootfs/api/models/app.py | 6 +++++- rootfs/api/settings/production.py | 4 ++++ rootfs/scheduler/resources/pod.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) 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 5b9ef9bed..6208a0ec5 100644 --- a/rootfs/scheduler/resources/pod.py +++ b/rootfs/scheduler/resources/pod.py @@ -218,7 +218,7 @@ def _set_container(self, namespace, container_name, data, **kwargs): }) # Inject POD_IP variable with Pod's IP address - if os.environ.get("DEIS_EXPOSE_POD_IP", False): + if kwargs.get('set_pod_ip'): data["env"].append({ "name": "POD_IP", "valueFrom": { From fae66db2600d57bf54b4d80dd94393ff1555616a Mon Sep 17 00:00:00 2001 From: Cryptophobia Date: Wed, 7 Aug 2019 06:29:09 -0400 Subject: [PATCH 3/3] fix(pod.py): only set POD_IP if DEIS_EXPOSE_POD_IP is set to 'True' --- rootfs/scheduler/resources/pod.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rootfs/scheduler/resources/pod.py b/rootfs/scheduler/resources/pod.py index 6208a0ec5..cae144d27 100644 --- a/rootfs/scheduler/resources/pod.py +++ b/rootfs/scheduler/resources/pod.py @@ -218,7 +218,7 @@ def _set_container(self, namespace, container_name, data, **kwargs): }) # Inject POD_IP variable with Pod's IP address - if kwargs.get('set_pod_ip'): + if kwargs.get('set_pod_ip') == 'True': data["env"].append({ "name": "POD_IP", "valueFrom": { @@ -352,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 = {