Support of kubernetes lifecycle hooks
What does this MR do?
Add support of kubernetes lifecycle hook
- preStop
- postStart
Why was this MR needed?
This MR is needed to allow execution of script at the start of the pod or before the stop of the pod
What's the best way to test this MR?
.gitlab-ci.yml
job:
script:
- ls -l /builds
Invalid hook configuration
config.toml
[[runners]]
name = "kubernetes"
url = "https://gitlab.com/"
token = "TOKEN_HERE"
executor = "kubernetes"
[runners.kubernetes]
image = "alpine:3.11"
privileged = true
namespace = "default"
[runners.kubernetes.container_lifecycle.pre_stop.exec]
command = []
[runners.kubernetes.container_lifecycle.pre_stop.tcp_socket]
port = 8080
host = "localhost"
- Run a job
- The job fails with the following error
ERROR: Job failed (system failure): prepare environment: setting up build pod: Pod "runner-lr33aybb-project-24422682-concurrent-0dw4b6" is invalid: [spec.containers[0].lifecycle.preStop.exec.command: Required value, spec.containers[0].lifecycle.preStop.tcpSocket: Forbidden: may not specify more than 1 handler type, spec.containers[1].lifecycle.preStop.exec.command: Required value, spec.containers[1].lifecycle.preStop.tcpSocket: Forbidden: may not specify more than 1 handler type]. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information
Test postStart hook
config.toml
[[runners]]
name = "kubernetes"
url = "https://gitlab.com/"
token = "TOKEN_HERE"
executor = "kubernetes"
[runners.kubernetes]
image = "alpine:3.11"
privileged = true
namespace = "default"
[runners.kubernetes.container_lifecycle.post_start.exec]
command = ["touch", "/builds/postStart.txt"]
- Run a job
- The job succeeds and the file
postStart.txt
is listed as inside the/builds
repository
What are the relevant issue numbers?
closes: #3630 (closed)
Edited by Romuald Atchadé