lifecycle
Description
lifecycle allows scripts to be executed after starting and before stopping the DataPower container. For more details on container lifecycle hooks, please refer to the following Kubernetes documentation:
Delaying SIGTERM with preStop
When the DataPower container is terminated by Kubernetes under normal conditions (such as a scaling event or rolling update), any in-flight transactions may be terminated. The use of the preStop lifecycle hook can help to mitigate
this by delaying the SIGTERM being sent to the container. For example, a 20 second delay in the below example would delay the shutdown by 20 seconds giving in-flight transactions on the gateway that much time to complete successfully
before being terminated.
spec:
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 20"]
Note The preStop handler should complete within terminationGracePeriodSeconds, which by default is 30 seconds. Otherwise it will not prevent the TERM signal being sent to the DataPower container. If a delay longer than 30 seconds is needed, the terminationGracePeriodSeconds can be set to a higher value to accommodate. See the Kubernetes documentation on termination of Pods for a deeper understanding of this lifecycle.
Example
apiVersion: datapower.ibm.com/v1beta3
kind: DataPowerService
metadata:
name: example-dpservice
spec:
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler >> ~/lifecycle.log"]
preStop:
exec:
command: ["/bin/sh", "-c", "echo Hello from the preStop handler >> ~/lifecycle.log"]