diff --git a/rootfs/api/models/config.py b/rootfs/api/models/config.py index 08636f861..cf41e0c80 100644 --- a/rootfs/api/models/config.py +++ b/rootfs/api/models/config.py @@ -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""" @@ -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""" diff --git a/rootfs/scheduler/__init__.py b/rootfs/scheduler/__init__.py index ea0691969..9b1158d87 100644 --- a/rootfs/scheduler/__init__.py +++ b/rootfs/scheduler/__init__.py @@ -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 @@ -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 @@ -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, }, }