container_probe.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package apis
  15. // ContainerProbeHandlerExecAction describes a "run in container" action.
  16. type ContainerProbeHandlerExecAction struct {
  17. // Command is the command line to execute inside the container, the working directory for the
  18. // command is root ('/') in the container's filesystem. The command is simply exec'd, it is
  19. // not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use
  20. // a shell, you need to explicitly call out to that shell.
  21. // Exit status of 0 is treated as live/healthy and non-zero is unhealthy.
  22. // +optional
  23. Command []string `json:"command,omitempty"`
  24. }
  25. // URIScheme identifies the scheme used for connection to a host for Get actions
  26. type URIScheme string
  27. const (
  28. // URISchemeHTTP means that the scheme used will be http://
  29. URISchemeHTTP URIScheme = "HTTP"
  30. // URISchemeHTTPS means that the scheme used will be https://
  31. URISchemeHTTPS URIScheme = "HTTPS"
  32. )
  33. // HTTPHeader describes a custom header to be used in HTTP probes
  34. type HTTPHeader struct {
  35. // The header field name
  36. Name string `json:"name"`
  37. // The header field value
  38. Value string `json:"value"`
  39. }
  40. // ContainerProbeHTTPGetAction describes an action based on HTTP Get requests.
  41. type ContainerProbeHTTPGetAction struct {
  42. // Path to access on the HTTP server.
  43. // +optional
  44. Path string `json:"path,omitempty"`
  45. // Name or number of the port to access on the container.
  46. // Number must be in the range 1 to 65535.
  47. // Name must be an IANA_SVC_NAME.
  48. Port int `json:"port"`
  49. // Host name to connect to, defaults to the pod IP. You probably want to set
  50. // "Host" in httpHeaders instead.
  51. // +optional
  52. Host string `json:"host,omitempty"`
  53. // Scheme to use for connecting to the host.
  54. // Defaults to HTTP.
  55. // +optional
  56. Scheme URIScheme `json:"scheme,omitempty"`
  57. // Custom headers to set in the request. HTTP allows repeated headers.
  58. // +optional
  59. HTTPHeaders []HTTPHeader `json:"httpHeaders,omitempty"`
  60. }
  61. // ContainerProbeTCPSocketAction describes an action based on opening a socket
  62. type ContainerProbeTCPSocketAction struct {
  63. // Number or name of the port to access on the container.
  64. // Number must be in the range 1 to 65535.
  65. // Name must be an IANA_SVC_NAME.
  66. Port int `json:"port"`
  67. // Optional: Host name to connect to, defaults to the pod IP.
  68. // +optional
  69. Host string `json:"host,omitempty"`
  70. }
  71. type ContainerProbeType string
  72. const (
  73. ContainerProbeTypeLiveness ContainerProbeType = "Liveness"
  74. ContainerProbeTypeReadiness ContainerProbeType = "Readiness"
  75. ContainerProbeTypeStartup ContainerProbeType = "Startup"
  76. )
  77. // ContainerProbeHandler defines a specific action that should be taken
  78. type ContainerProbeHandler struct {
  79. // One and only one of the following should be specified.
  80. // Exec specifies the action to take.
  81. Exec *ContainerProbeHandlerExecAction `json:"exec,omitempty"`
  82. // HTTPGet specifies the http request to perform.
  83. HTTPGet *ContainerProbeHTTPGetAction `json:"http_get,omitempty"`
  84. // TCPSocket specifies an action involving a TCP port.
  85. TCPSocket *ContainerProbeTCPSocketAction `json:"tcp_socket,omitempty"`
  86. }
  87. // ContainerProbe describes a health check to be performed against a container to determine whether it is
  88. // alive or ready to receive traffic.
  89. type ContainerProbe struct {
  90. // The action taken to determine the health of a container
  91. ContainerProbeHandler `json:",inline"`
  92. // Number of seconds after the container has started before liveness probes are initiated.
  93. // InitialDelaySeconds int32 `json:"initial_delay_seconds,omitempty"`
  94. // Number of seconds after which the probe times out.
  95. TimeoutSeconds int32 `json:"timeout_seconds,omitempty"`
  96. // How often (in seconds) to perform the probe.
  97. // Default to 10 seconds. Minimum value is 1.
  98. PeriodSeconds int32 `json:"period_seconds,omitempty"`
  99. // Minimum consecutive successes for the probe to be considered successful after having failed.
  100. // Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.
  101. SuccessThreshold int32 `json:"success_threshold,omitempty"`
  102. // Minimum consecutive failures for the probe to be considered failed after having succeeded.
  103. // Defaults to 3. Minimum value is 1.
  104. FailureThreshold int32 `json:"failure_threshold,omitempty"`
  105. }