Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

feat(health checks): implement new kubernetes 1.2 health check features #600

Merged
merged 1 commit into from
Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions rootfs/api/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ def healthcheck(self):
timeout = int(self.values.get('HEALTHCHECK_TIMEOUT', 50))
delay = int(self.values.get('HEALTHCHECK_INITIAL_DELAY', 50))
port = int(self.values.get('HEALTHCHECK_PORT', 5000))

return {'path': path, 'timeout': timeout, 'delay': delay, 'port': port}
period_seconds = int(self.values.get('HEALTHCHECK_PERIOD_SECONDS', 10))
success_threshold = int(self.values.get('HEALTHCHECK_SUCCESS_THRESHOLD', 1))
failure_threshold = int(self.values.get('HEALTHCHECK_FAILURE_THRESHOLD', 3))

return {
'path': path,
'timeout': timeout,
'delay': delay,
'port': port,
'period_seconds': period_seconds,
'success_threshold': success_threshold,
'failure_threshold': failure_threshold,
}

def set_healthchecks(self):
"""Defines default values for HTTP healthchecks"""
Expand All @@ -49,10 +60,25 @@ def set_healthchecks(self):
# fetch set health values and any defaults
# this approach allows new health items to be added without issues
health = self.healthcheck()

# HTTP GET related
self.values['HEALTHCHECK_URL'] = health['path']
self.values['HEALTHCHECK_PORT'] = health['port']

# Number of seconds after which the probe times out.
# More info: http://releases.k8s.io/HEAD/docs/user-guide/pod-states.md#container-probes
self.values['HEALTHCHECK_TIMEOUT'] = health['timeout']
# Number of seconds after the container has started before liveness probes are initiated.
# More info: http://releases.k8s.io/HEAD/docs/user-guide/pod-states.md#container-probes
self.values['HEALTHCHECK_INITIAL_DELAY'] = health['delay']
self.values['HEALTHCHECK_PORT'] = health['port']
# How often (in seconds) to perform the probe.
self.values['HEALTHCHECK_PERIOD_SECONDS'] = health['period_seconds']
# Minimum consecutive successes for the probe to be considered successful
# after having failed.
self.values['HEALTHCHECK_SUCCESS_THRESHOLD'] = health['success_threshold']
# Minimum consecutive failures for the probe to be considered failed after
# having succeeded.
self.values['HEALTHCHECK_FAILURE_THRESHOLD'] = health['failure_threshold']

def save(self, **kwargs):
"""merge the old config with the new"""
Expand Down
20 changes: 17 additions & 3 deletions rootfs/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,15 @@ def _delete_rc(self, namespace, name):

return response

def _healthcheck(self, controller, routable=False, path='/', port=5000, delay=30, timeout=5): # noqa
def _healthcheck(self, controller, routable=False, path='/', port=5000, delay=30, timeout=5,
period_seconds=1, success_threshold=1, failure_threshold=3): # noqa
"""
Apply HTTP GET healthcehck to the application container

http://kubernetes.io/docs/user-guide/walkthrough/k8s201/#health-checking
http://kubernetes.io/docs/user-guide/pod-states/#container-probes
http://kubernetes.io/docs/user-guide/liveness/
"""
if not routable:
return controller

Expand All @@ -1011,7 +1019,10 @@ def _healthcheck(self, controller, routable=False, path='/', port=5000, delay=30
# length of time to wait for a pod to initialize
# after pod startup, before applying health checking
'initialDelaySeconds': delay,
'timeoutSeconds': timeout
'timeoutSeconds': timeout,
'periodSeconds': period_seconds,
'successThreshold': success_threshold,
'failureThreshold': failure_threshold,
},
'readinessProbe': {
# an http probe
Expand All @@ -1022,7 +1033,10 @@ def _healthcheck(self, controller, routable=False, path='/', port=5000, delay=30
# length of time to wait for a pod to initialize
# after pod startup, before applying health checking
'initialDelaySeconds': delay,
'timeoutSeconds': timeout
'timeoutSeconds': timeout,
'periodSeconds': period_seconds,
'successThreshold': success_threshold,
'failureThreshold': failure_threshold,
},
}

Expand Down