@@ -935,9 +935,11 @@ def _create_rc(self, namespace, name, image, command, **kwargs): # noqa
935935
936936 self ._set_environment (container , namespace , ** kwargs )
937937
938- # add in healtchecks
938+ # add in healthchecks
939939 if kwargs .get ('healthcheck' ):
940940 template = self ._healthcheck (template , kwargs ['routable' ], ** kwargs ['healthcheck' ])
941+ elif kwargs .get ('build_type' ) == "buildpack" :
942+ template = self ._buildpack_readiness_probe (template )
941943
942944 url = self ._api ("/namespaces/{}/replicationcontrollers" , namespace )
943945 resp = self .session .post (url , json = template )
@@ -1045,6 +1047,53 @@ def _healthcheck(self, controller, routable=False, path='/', port=5000, delay=30
10451047
10461048 return controller
10471049
1050+ '''
1051+ Applies exec readiness probe to the slugrunner container.
1052+ http://kubernetes.io/docs/user-guide/pod-states/#container-probes
1053+
1054+ /runner/init is the entry point of the slugrunner.
1055+ https://github.com/deis/slugrunner/blob/01eac53f1c5f1d1dfa7570bbd6b9e45c00441fea/rootfs/Dockerfile#L20
1056+ Once it downloads the slug it starts running using `exec` which means the pid 1
1057+ will point to the slug/application command instead of entry point once the application has
1058+ started.
1059+ https://github.com/deis/slugrunner/blob/01eac53f1c5f1d1dfa7570bbd6b9e45c00441fea/rootfs/runner/init#L90
1060+
1061+ This should be added only for the build pack apps when a custom liveness probe is not set to
1062+ make sure that the pod is ready only when the slug is downloaded and started running.
1063+ '''
1064+ def _buildpack_readiness_probe (self , controller , delay = 30 , timeout = 5 , period_seconds = 5 ,
1065+ success_threshold = 1 , failure_threshold = 1 ):
1066+ readinessprobe = {
1067+ 'readinessProbe' : {
1068+ # an exec probe
1069+ 'exec' : {
1070+ "command" : [
1071+ "bash" ,
1072+ "-c" ,
1073+ "[[ '$(ps -p 1 -o args)' != *'bash /runner/init'* ]]"
1074+ ]
1075+ },
1076+ # length of time to wait for a pod to initialize
1077+ # after pod startup, before applying health checking
1078+ 'initialDelaySeconds' : delay ,
1079+ 'timeoutSeconds' : timeout ,
1080+ 'periodSeconds' : period_seconds ,
1081+ 'successThreshold' : success_threshold ,
1082+ 'failureThreshold' : failure_threshold ,
1083+ },
1084+ }
1085+
1086+ # Update only the application container with the health check
1087+ app_type = controller ['spec' ]['selector' ]['type' ]
1088+ namespace = controller ['spec' ]['selector' ]['app' ]
1089+ container_name = '{}-{}' .format (namespace , app_type )
1090+ containers = controller ['spec' ]['template' ]['spec' ]['containers' ]
1091+ for container in containers :
1092+ if container ['name' ] == container_name :
1093+ container .update (readinessprobe )
1094+
1095+ return controller
1096+
10481097 # SECRETS #
10491098 # http://kubernetes.io/v1.1/docs/api-reference/v1/definitions.html#_v1_secret
10501099 def _get_secret (self , namespace , name ):
0 commit comments