Skip to content

Commit

Permalink
Merge pull request #109 from Cryptophobia/master
Browse files Browse the repository at this point in the history
feat(controller): Add POD_IP environment variable if DEIS_EXPOSE_POD_IP
  • Loading branch information
Cryptophobia authored Aug 7, 2019
2 parents 427c6db + 4cbb453 commit a881e4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rootfs/api/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions rootfs/api/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions rootfs/scheduler/resources/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit a881e4d

Please sign in to comment.