pod.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 compute
  15. import (
  16. "time"
  17. "yunion.io/x/onecloud/pkg/httperrors"
  18. )
  19. const (
  20. POD_STATUS_CREATING_CONTAINER = "creating_container"
  21. POD_STATUS_CREATE_CONTAINER_FAILED = "create_container_failed"
  22. POD_STATUS_STARTING_CONTAINER = "starting_container"
  23. POD_STATUS_START_CONTAINER_FAILED = "start_container_failed"
  24. POD_STATUS_STOPPING_CONTAINER = "stopping_container"
  25. POD_STATUS_STOP_CONTAINER_FAILED = "stop_container_failed"
  26. POD_STATUS_DELETING_CONTAINER = "deleting_container"
  27. POD_STATUS_DELETE_CONTAINER_FAILED = "delete_container_failed"
  28. POD_STATUS_UPLOADING_STATUS = "uploading_status"
  29. POD_STATUS_UPLOADING_STATUS_FAILED = "upload_status_failed"
  30. POD_STATUS_CRASH_LOOP_BACK_OFF = "crash_loop_back_off"
  31. POD_STATUS_CONTAINER_EXITED = "container_exited"
  32. )
  33. const (
  34. POD_METADATA_CRI_ID = "cri_id"
  35. POD_METADATA_CRI_CONFIG = "cri_config"
  36. POD_METADATA_PORT_MAPPINGS = "port_mappings"
  37. POD_METADATA_POST_STOP_CLEANUP_CONFIG = "post_stop_cleanup_config"
  38. )
  39. type PodContainerCreateInput struct {
  40. // Container name
  41. Name string `json:"name"`
  42. ContainerSpec
  43. }
  44. type PodPortMappingProtocol string
  45. const (
  46. PodPortMappingProtocolTCP = "tcp"
  47. PodPortMappingProtocolUDP = "udp"
  48. //PodPortMappingProtocolSCTP = "sctp"
  49. )
  50. const (
  51. POD_PORT_MAPPING_RANGE_START = 20000
  52. POD_PORT_MAPPING_RANGE_END = 25000
  53. )
  54. type PodPortMappingPortRange struct {
  55. Start int `json:"start"`
  56. End int `json:"end"`
  57. }
  58. type PodPortMapping struct {
  59. Protocol PodPortMappingProtocol `json:"protocol"`
  60. ContainerPort int `json:"container_port"`
  61. HostPort *int `json:"host_port,omitempty"`
  62. HostIp string `json:"host_ip"`
  63. HostPortRange *PodPortMappingPortRange `json:"host_port_range,omitempty"`
  64. }
  65. type PodSecurityContext struct {
  66. RunAsUser *int64 `json:"run_as_user,omitempty"`
  67. RunAsGroup *int64 `json:"run_as_group,omitempty"`
  68. }
  69. type PodCreateInput struct {
  70. Containers []*PodContainerCreateInput `json:"containers"`
  71. HostIPC bool `json:"host_ipc"`
  72. //PortMappings []*PodPortMapping `json:"port_mappings"`
  73. SecurityContext *PodSecurityContext `json:"security_context,omitempty"`
  74. }
  75. type PodStartResponse struct {
  76. CRIId string `json:"cri_id"`
  77. IsRunning bool `json:"is_running"`
  78. }
  79. type PodMetadataPortMapping struct {
  80. Protocol PodPortMappingProtocol `json:"protocol"`
  81. ContainerPort int32 `json:"container_port"`
  82. HostPort int32 `json:"host_port,omitempty"`
  83. HostIp string `json:"host_ip"`
  84. }
  85. type GuestSetPortMappingsInput struct {
  86. PortMappings []*PodPortMapping `json:"port_mappings"`
  87. }
  88. type PodLogOptions struct {
  89. // The container for which to stream logs. Defaults to only container if there is one container in the pod.
  90. // +optional
  91. Container string `json:"container,omitempty"`
  92. // Follow the log stream of the pod. Defaults to false.
  93. // +optional
  94. Follow bool `json:"follow,omitempty"`
  95. // Return previous terminated container logs. Defaults to false.
  96. // +optional
  97. Previous bool `json:"previous,omitempty"`
  98. // A relative time in seconds before the current time from which to show logs. If this value
  99. // precedes the time a pod was started, only logs since the pod start will be returned.
  100. // If this value is in the future, no logs will be returned.
  101. // Only one of sinceSeconds or sinceTime may be specified.
  102. // +optional
  103. SinceSeconds *int64 `json:"sinceSeconds,omitempty"`
  104. // An RFC3339 timestamp from which to show logs. If this value
  105. // precedes the time a pod was started, only logs since the pod start will be returned.
  106. // If this value is in the future, no logs will be returned.
  107. // Only one of sinceSeconds or sinceTime may be specified.
  108. // +optional
  109. SinceTime *time.Time `json:"sinceTime,omitempty"`
  110. // If true, add an RFC3339 or RFC3339Nano timestamp at the beginning of every line
  111. // of log output. Defaults to false.
  112. // +optional
  113. Timestamps bool `json:"timestamps,omitempty"`
  114. // If set, the number of lines from the end of the logs to show. If not specified,
  115. // logs are shown from the creation of the container or sinceSeconds or sinceTime
  116. // +optional
  117. TailLines *int64 `json:"tailLines,omitempty"`
  118. // If set, the number of bytes to read from the server before terminating the
  119. // log output. This may not display a complete final line of logging, and may return
  120. // slightly more or slightly less than the specified limit.
  121. // +optional
  122. LimitBytes *int64 `json:"limitBytes,omitempty"`
  123. // insecureSkipTLSVerifyBackend indicates that the apiserver should not confirm the validity of the
  124. // serving certificate of the backend it is connecting to. This will make the HTTPS connection between the apiserver
  125. // and the backend insecure. This means the apiserver cannot verify the log data it is receiving came from the real
  126. // kubelet. If the kubelet is configured to verify the apiserver's TLS credentials, it does not mean the
  127. // connection to the real kubelet is vulnerable to a man in the middle attack (e.g. an attacker could not intercept
  128. // the actual log data coming from the real kubelet).
  129. // +optional
  130. InsecureSkipTLSVerifyBackend bool `json:"insecureSkipTLSVerifyBackend,omitempty"`
  131. }
  132. func ValidatePodLogOptions(opts *PodLogOptions) error {
  133. if opts.TailLines != nil && *opts.TailLines < 0 {
  134. return httperrors.NewInputParameterError("negative tail lines")
  135. }
  136. if opts.LimitBytes != nil && *opts.LimitBytes < 1 {
  137. return httperrors.NewInputParameterError("limit_bytes must be greater than zero")
  138. }
  139. if opts.SinceSeconds != nil && opts.SinceTime != nil {
  140. return httperrors.NewInputParameterError("at most one of since_time or since_seconds must be specified")
  141. }
  142. if opts.SinceSeconds != nil {
  143. if *opts.SinceSeconds < 1 {
  144. return httperrors.NewInputParameterError("since_seconds must be greater than zero")
  145. }
  146. }
  147. return nil
  148. }
  149. type PodPostStopCleanupConfig struct {
  150. Dirs []string `json:"dirs"`
  151. }