runtime.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package container
  14. import (
  15. "context"
  16. "fmt"
  17. "io"
  18. "net/url"
  19. "reflect"
  20. "strings"
  21. "time"
  22. "k8s.io/api/core/v1"
  23. "k8s.io/apimachinery/pkg/types"
  24. "k8s.io/client-go/tools/remotecommand"
  25. "k8s.io/client-go/util/flowcontrol"
  26. runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
  27. "k8s.io/klog"
  28. "k8s.io/kubernetes/pkg/volume"
  29. )
  30. type Version interface {
  31. // Compare compares two versions of the runtime. On success it returns -1
  32. // if the version is less than the other, 1 if it is greater than the other,
  33. // or 0 if they are equal.
  34. Compare(other string) (int, error)
  35. // String returns a string that represents the version.
  36. String() string
  37. }
  38. // ImageSpec is an internal representation of an image. Currently, it wraps the
  39. // value of a Container's Image field, but in the future it will include more detailed
  40. // information about the different image types.
  41. type ImageSpec struct {
  42. Image string
  43. }
  44. // ImageStats contains statistics about all the images currently available.
  45. type ImageStats struct {
  46. // Total amount of storage consumed by existing images.
  47. TotalStorageBytes uint64
  48. }
  49. // Runtime interface defines the interfaces that should be implemented
  50. // by a container runtime.
  51. // Thread safety is required from implementations of this interface.
  52. type Runtime interface {
  53. // Type returns the type of the container runtime.
  54. Type() string
  55. // Version returns the version information of the container runtime.
  56. Version() (Version, error)
  57. // APIVersion returns the cached API version information of the container
  58. // runtime. Implementation is expected to update this cache periodically.
  59. // This may be different from the runtime engine's version.
  60. // TODO(random-liu): We should fold this into Version()
  61. APIVersion() (Version, error)
  62. // Status returns the status of the runtime. An error is returned if the Status
  63. // function itself fails, nil otherwise.
  64. Status() (*RuntimeStatus, error)
  65. // GetPods returns a list of containers grouped by pods. The boolean parameter
  66. // specifies whether the runtime returns all containers including those already
  67. // exited and dead containers (used for garbage collection).
  68. GetPods(all bool) ([]*Pod, error)
  69. // GarbageCollect removes dead containers using the specified container gc policy
  70. // If allSourcesReady is not true, it means that kubelet doesn't have the
  71. // complete list of pods from all avialble sources (e.g., apiserver, http,
  72. // file). In this case, garbage collector should refrain itself from aggressive
  73. // behavior such as removing all containers of unrecognized pods (yet).
  74. // If evictNonDeletedPods is set to true, containers and sandboxes belonging to pods
  75. // that are terminated, but not deleted will be evicted. Otherwise, only deleted pods will be GC'd.
  76. // TODO: Revisit this method and make it cleaner.
  77. GarbageCollect(gcPolicy ContainerGCPolicy, allSourcesReady bool, evictNonDeletedPods bool) error
  78. // Syncs the running pod into the desired pod.
  79. SyncPod(pod *v1.Pod, podStatus *PodStatus, pullSecrets []v1.Secret, backOff *flowcontrol.Backoff) PodSyncResult
  80. // KillPod kills all the containers of a pod. Pod may be nil, running pod must not be.
  81. // TODO(random-liu): Return PodSyncResult in KillPod.
  82. // gracePeriodOverride if specified allows the caller to override the pod default grace period.
  83. // only hard kill paths are allowed to specify a gracePeriodOverride in the kubelet in order to not corrupt user data.
  84. // it is useful when doing SIGKILL for hard eviction scenarios, or max grace period during soft eviction scenarios.
  85. KillPod(pod *v1.Pod, runningPod Pod, gracePeriodOverride *int64) error
  86. // GetPodStatus retrieves the status of the pod, including the
  87. // information of all containers in the pod that are visible in Runtime.
  88. GetPodStatus(uid types.UID, name, namespace string) (*PodStatus, error)
  89. // TODO(vmarmol): Unify pod and containerID args.
  90. // GetContainerLogs returns logs of a specific container. By
  91. // default, it returns a snapshot of the container log. Set 'follow' to true to
  92. // stream the log. Set 'follow' to false and specify the number of lines (e.g.
  93. // "100" or "all") to tail the log.
  94. GetContainerLogs(ctx context.Context, pod *v1.Pod, containerID ContainerID, logOptions *v1.PodLogOptions, stdout, stderr io.Writer) (err error)
  95. // Delete a container. If the container is still running, an error is returned.
  96. DeleteContainer(containerID ContainerID) error
  97. // ImageService provides methods to image-related methods.
  98. ImageService
  99. // UpdatePodCIDR sends a new podCIDR to the runtime.
  100. // This method just proxies a new runtimeConfig with the updated
  101. // CIDR value down to the runtime shim.
  102. UpdatePodCIDR(podCIDR string) error
  103. }
  104. // StreamingRuntime is the interface implemented by runtimes that handle the serving of the
  105. // streaming calls (exec/attach/port-forward) themselves. In this case, Kubelet should redirect to
  106. // the runtime server.
  107. type StreamingRuntime interface {
  108. GetExec(id ContainerID, cmd []string, stdin, stdout, stderr, tty bool) (*url.URL, error)
  109. GetAttach(id ContainerID, stdin, stdout, stderr, tty bool) (*url.URL, error)
  110. GetPortForward(podName, podNamespace string, podUID types.UID, ports []int32) (*url.URL, error)
  111. }
  112. type ImageService interface {
  113. // PullImage pulls an image from the network to local storage using the supplied
  114. // secrets if necessary. It returns a reference (digest or ID) to the pulled image.
  115. PullImage(image ImageSpec, pullSecrets []v1.Secret, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error)
  116. // GetImageRef gets the reference (digest or ID) of the image which has already been in
  117. // the local storage. It returns ("", nil) if the image isn't in the local storage.
  118. GetImageRef(image ImageSpec) (string, error)
  119. // Gets all images currently on the machine.
  120. ListImages() ([]Image, error)
  121. // Removes the specified image.
  122. RemoveImage(image ImageSpec) error
  123. // Returns Image statistics.
  124. ImageStats() (*ImageStats, error)
  125. }
  126. type ContainerAttacher interface {
  127. AttachContainer(id ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) (err error)
  128. }
  129. type ContainerCommandRunner interface {
  130. // RunInContainer synchronously executes the command in the container, and returns the output.
  131. // If the command completes with a non-0 exit code, a k8s.io/utils/exec.ExitError will be returned.
  132. RunInContainer(id ContainerID, cmd []string, timeout time.Duration) ([]byte, error)
  133. }
  134. // Pod is a group of containers.
  135. type Pod struct {
  136. // The ID of the pod, which can be used to retrieve a particular pod
  137. // from the pod list returned by GetPods().
  138. ID types.UID
  139. // The name and namespace of the pod, which is readable by human.
  140. Name string
  141. Namespace string
  142. // List of containers that belongs to this pod. It may contain only
  143. // running containers, or mixed with dead ones (when GetPods(true)).
  144. Containers []*Container
  145. // List of sandboxes associated with this pod. The sandboxes are converted
  146. // to Container temporariliy to avoid substantial changes to other
  147. // components. This is only populated by kuberuntime.
  148. // TODO: use the runtimeApi.PodSandbox type directly.
  149. Sandboxes []*Container
  150. }
  151. // PodPair contains both runtime#Pod and api#Pod
  152. type PodPair struct {
  153. // APIPod is the v1.Pod
  154. APIPod *v1.Pod
  155. // RunningPod is the pod defined in pkg/kubelet/container/runtime#Pod
  156. RunningPod *Pod
  157. }
  158. // ContainerID is a type that identifies a container.
  159. type ContainerID struct {
  160. // The type of the container runtime. e.g. 'docker'.
  161. Type string
  162. // The identification of the container, this is comsumable by
  163. // the underlying container runtime. (Note that the container
  164. // runtime interface still takes the whole struct as input).
  165. ID string
  166. }
  167. func BuildContainerID(typ, ID string) ContainerID {
  168. return ContainerID{Type: typ, ID: ID}
  169. }
  170. // Convenience method for creating a ContainerID from an ID string.
  171. func ParseContainerID(containerID string) ContainerID {
  172. var id ContainerID
  173. if err := id.ParseString(containerID); err != nil {
  174. klog.Error(err)
  175. }
  176. return id
  177. }
  178. func (c *ContainerID) ParseString(data string) error {
  179. // Trim the quotes and split the type and ID.
  180. parts := strings.Split(strings.Trim(data, "\""), "://")
  181. if len(parts) != 2 {
  182. return fmt.Errorf("invalid container ID: %q", data)
  183. }
  184. c.Type, c.ID = parts[0], parts[1]
  185. return nil
  186. }
  187. func (c *ContainerID) String() string {
  188. return fmt.Sprintf("%s://%s", c.Type, c.ID)
  189. }
  190. func (c *ContainerID) IsEmpty() bool {
  191. return *c == ContainerID{}
  192. }
  193. func (c *ContainerID) MarshalJSON() ([]byte, error) {
  194. return []byte(fmt.Sprintf("%q", c.String())), nil
  195. }
  196. func (c *ContainerID) UnmarshalJSON(data []byte) error {
  197. return c.ParseString(string(data))
  198. }
  199. // DockerID is an ID of docker container. It is a type to make it clear when we're working with docker container Ids
  200. type DockerID string
  201. func (id DockerID) ContainerID() ContainerID {
  202. return ContainerID{
  203. Type: "docker",
  204. ID: string(id),
  205. }
  206. }
  207. type ContainerState string
  208. const (
  209. ContainerStateCreated ContainerState = "created"
  210. ContainerStateRunning ContainerState = "running"
  211. ContainerStateExited ContainerState = "exited"
  212. // This unknown encompasses all the states that we currently don't care.
  213. ContainerStateUnknown ContainerState = "unknown"
  214. )
  215. // Container provides the runtime information for a container, such as ID, hash,
  216. // state of the container.
  217. type Container struct {
  218. // The ID of the container, used by the container runtime to identify
  219. // a container.
  220. ID ContainerID
  221. // The name of the container, which should be the same as specified by
  222. // v1.Container.
  223. Name string
  224. // The image name of the container, this also includes the tag of the image,
  225. // the expected form is "NAME:TAG".
  226. Image string
  227. // The id of the image used by the container.
  228. ImageID string
  229. // Hash of the container, used for comparison. Optional for containers
  230. // not managed by kubelet.
  231. Hash uint64
  232. // State is the state of the container.
  233. State ContainerState
  234. }
  235. // PodStatus represents the status of the pod and its containers.
  236. // v1.PodStatus can be derived from examining PodStatus and v1.Pod.
  237. type PodStatus struct {
  238. // ID of the pod.
  239. ID types.UID
  240. // Name of the pod.
  241. Name string
  242. // Namespace of the pod.
  243. Namespace string
  244. // IP of the pod.
  245. IP string
  246. // Status of containers in the pod.
  247. ContainerStatuses []*ContainerStatus
  248. // Status of the pod sandbox.
  249. // Only for kuberuntime now, other runtime may keep it nil.
  250. SandboxStatuses []*runtimeapi.PodSandboxStatus
  251. }
  252. // ContainerStatus represents the status of a container.
  253. type ContainerStatus struct {
  254. // ID of the container.
  255. ID ContainerID
  256. // Name of the container.
  257. Name string
  258. // Status of the container.
  259. State ContainerState
  260. // Creation time of the container.
  261. CreatedAt time.Time
  262. // Start time of the container.
  263. StartedAt time.Time
  264. // Finish time of the container.
  265. FinishedAt time.Time
  266. // Exit code of the container.
  267. ExitCode int
  268. // Name of the image, this also includes the tag of the image,
  269. // the expected form is "NAME:TAG".
  270. Image string
  271. // ID of the image.
  272. ImageID string
  273. // Hash of the container, used for comparison.
  274. Hash uint64
  275. // Number of times that the container has been restarted.
  276. RestartCount int
  277. // A string explains why container is in such a status.
  278. Reason string
  279. // Message written by the container before exiting (stored in
  280. // TerminationMessagePath).
  281. Message string
  282. }
  283. // FindContainerStatusByName returns container status in the pod status with the given name.
  284. // When there are multiple containers' statuses with the same name, the first match will be returned.
  285. func (podStatus *PodStatus) FindContainerStatusByName(containerName string) *ContainerStatus {
  286. for _, containerStatus := range podStatus.ContainerStatuses {
  287. if containerStatus.Name == containerName {
  288. return containerStatus
  289. }
  290. }
  291. return nil
  292. }
  293. // Get container status of all the running containers in a pod
  294. func (podStatus *PodStatus) GetRunningContainerStatuses() []*ContainerStatus {
  295. runningContainerStatuses := []*ContainerStatus{}
  296. for _, containerStatus := range podStatus.ContainerStatuses {
  297. if containerStatus.State == ContainerStateRunning {
  298. runningContainerStatuses = append(runningContainerStatuses, containerStatus)
  299. }
  300. }
  301. return runningContainerStatuses
  302. }
  303. // Basic information about a container image.
  304. type Image struct {
  305. // ID of the image.
  306. ID string
  307. // Other names by which this image is known.
  308. RepoTags []string
  309. // Digests by which this image is known.
  310. RepoDigests []string
  311. // The size of the image in bytes.
  312. Size int64
  313. }
  314. type EnvVar struct {
  315. Name string
  316. Value string
  317. }
  318. type Annotation struct {
  319. Name string
  320. Value string
  321. }
  322. type Mount struct {
  323. // Name of the volume mount.
  324. // TODO(yifan): Remove this field, as this is not representing the unique name of the mount,
  325. // but the volume name only.
  326. Name string
  327. // Path of the mount within the container.
  328. ContainerPath string
  329. // Path of the mount on the host.
  330. HostPath string
  331. // Whether the mount is read-only.
  332. ReadOnly bool
  333. // Whether the mount needs SELinux relabeling
  334. SELinuxRelabel bool
  335. // Requested propagation mode
  336. Propagation runtimeapi.MountPropagation
  337. }
  338. type PortMapping struct {
  339. // Name of the port mapping
  340. Name string
  341. // Protocol of the port mapping.
  342. Protocol v1.Protocol
  343. // The port number within the container.
  344. ContainerPort int
  345. // The port number on the host.
  346. HostPort int
  347. // The host IP.
  348. HostIP string
  349. }
  350. type DeviceInfo struct {
  351. // Path on host for mapping
  352. PathOnHost string
  353. // Path in Container to map
  354. PathInContainer string
  355. // Cgroup permissions
  356. Permissions string
  357. }
  358. // RunContainerOptions specify the options which are necessary for running containers
  359. type RunContainerOptions struct {
  360. // The environment variables list.
  361. Envs []EnvVar
  362. // The mounts for the containers.
  363. Mounts []Mount
  364. // The host devices mapped into the containers.
  365. Devices []DeviceInfo
  366. // The port mappings for the containers.
  367. PortMappings []PortMapping
  368. // The annotations for the container
  369. // These annotations are generated by other components (i.e.,
  370. // not users). Currently, only device plugins populate the annotations.
  371. Annotations []Annotation
  372. // If the container has specified the TerminationMessagePath, then
  373. // this directory will be used to create and mount the log file to
  374. // container.TerminationMessagePath
  375. PodContainerDir string
  376. // The type of container rootfs
  377. ReadOnly bool
  378. // hostname for pod containers
  379. Hostname string
  380. // EnableHostUserNamespace sets userns=host when users request host namespaces (pid, ipc, net),
  381. // are using non-namespaced capabilities (mknod, sys_time, sys_module), the pod contains a privileged container,
  382. // or using host path volumes.
  383. // This should only be enabled when the container runtime is performing user remapping AND if the
  384. // experimental behavior is desired.
  385. EnableHostUserNamespace bool
  386. }
  387. // VolumeInfo contains information about the volume.
  388. type VolumeInfo struct {
  389. // Mounter is the volume's mounter
  390. Mounter volume.Mounter
  391. // BlockVolumeMapper is the Block volume's mapper
  392. BlockVolumeMapper volume.BlockVolumeMapper
  393. // SELinuxLabeled indicates whether this volume has had the
  394. // pod's SELinux label applied to it or not
  395. SELinuxLabeled bool
  396. // Whether the volume permission is set to read-only or not
  397. // This value is passed from volume.spec
  398. ReadOnly bool
  399. // Inner volume spec name, which is the PV name if used, otherwise
  400. // it is the same as the outer volume spec name.
  401. InnerVolumeSpecName string
  402. }
  403. type VolumeMap map[string]VolumeInfo
  404. // RuntimeConditionType is the types of required runtime conditions.
  405. type RuntimeConditionType string
  406. const (
  407. // RuntimeReady means the runtime is up and ready to accept basic containers.
  408. RuntimeReady RuntimeConditionType = "RuntimeReady"
  409. // NetworkReady means the runtime network is up and ready to accept containers which require network.
  410. NetworkReady RuntimeConditionType = "NetworkReady"
  411. )
  412. // RuntimeStatus contains the status of the runtime.
  413. type RuntimeStatus struct {
  414. // Conditions is an array of current observed runtime conditions.
  415. Conditions []RuntimeCondition
  416. }
  417. // GetRuntimeCondition gets a specified runtime condition from the runtime status.
  418. func (r *RuntimeStatus) GetRuntimeCondition(t RuntimeConditionType) *RuntimeCondition {
  419. for i := range r.Conditions {
  420. c := &r.Conditions[i]
  421. if c.Type == t {
  422. return c
  423. }
  424. }
  425. return nil
  426. }
  427. // String formats the runtime status into human readable string.
  428. func (s *RuntimeStatus) String() string {
  429. var ss []string
  430. for _, c := range s.Conditions {
  431. ss = append(ss, c.String())
  432. }
  433. return fmt.Sprintf("Runtime Conditions: %s", strings.Join(ss, ", "))
  434. }
  435. // RuntimeCondition contains condition information for the runtime.
  436. type RuntimeCondition struct {
  437. // Type of runtime condition.
  438. Type RuntimeConditionType
  439. // Status of the condition, one of true/false.
  440. Status bool
  441. // Reason is brief reason for the condition's last transition.
  442. Reason string
  443. // Message is human readable message indicating details about last transition.
  444. Message string
  445. }
  446. // String formats the runtime condition into human readable string.
  447. func (c *RuntimeCondition) String() string {
  448. return fmt.Sprintf("%s=%t reason:%s message:%s", c.Type, c.Status, c.Reason, c.Message)
  449. }
  450. type Pods []*Pod
  451. // FindPodByID finds and returns a pod in the pod list by UID. It will return an empty pod
  452. // if not found.
  453. func (p Pods) FindPodByID(podUID types.UID) Pod {
  454. for i := range p {
  455. if p[i].ID == podUID {
  456. return *p[i]
  457. }
  458. }
  459. return Pod{}
  460. }
  461. // FindPodByFullName finds and returns a pod in the pod list by the full name.
  462. // It will return an empty pod if not found.
  463. func (p Pods) FindPodByFullName(podFullName string) Pod {
  464. for i := range p {
  465. if BuildPodFullName(p[i].Name, p[i].Namespace) == podFullName {
  466. return *p[i]
  467. }
  468. }
  469. return Pod{}
  470. }
  471. // FindPod combines FindPodByID and FindPodByFullName, it finds and returns a pod in the
  472. // pod list either by the full name or the pod ID. It will return an empty pod
  473. // if not found.
  474. func (p Pods) FindPod(podFullName string, podUID types.UID) Pod {
  475. if len(podFullName) > 0 {
  476. return p.FindPodByFullName(podFullName)
  477. }
  478. return p.FindPodByID(podUID)
  479. }
  480. // FindContainerByName returns a container in the pod with the given name.
  481. // When there are multiple containers with the same name, the first match will
  482. // be returned.
  483. func (p *Pod) FindContainerByName(containerName string) *Container {
  484. for _, c := range p.Containers {
  485. if c.Name == containerName {
  486. return c
  487. }
  488. }
  489. return nil
  490. }
  491. func (p *Pod) FindContainerByID(id ContainerID) *Container {
  492. for _, c := range p.Containers {
  493. if c.ID == id {
  494. return c
  495. }
  496. }
  497. return nil
  498. }
  499. func (p *Pod) FindSandboxByID(id ContainerID) *Container {
  500. for _, c := range p.Sandboxes {
  501. if c.ID == id {
  502. return c
  503. }
  504. }
  505. return nil
  506. }
  507. // ToAPIPod converts Pod to v1.Pod. Note that if a field in v1.Pod has no
  508. // corresponding field in Pod, the field would not be populated.
  509. func (p *Pod) ToAPIPod() *v1.Pod {
  510. var pod v1.Pod
  511. pod.UID = p.ID
  512. pod.Name = p.Name
  513. pod.Namespace = p.Namespace
  514. for _, c := range p.Containers {
  515. var container v1.Container
  516. container.Name = c.Name
  517. container.Image = c.Image
  518. pod.Spec.Containers = append(pod.Spec.Containers, container)
  519. }
  520. return &pod
  521. }
  522. // IsEmpty returns true if the pod is empty.
  523. func (p *Pod) IsEmpty() bool {
  524. return reflect.DeepEqual(p, &Pod{})
  525. }
  526. // GetPodFullName returns a name that uniquely identifies a pod.
  527. func GetPodFullName(pod *v1.Pod) string {
  528. // Use underscore as the delimiter because it is not allowed in pod name
  529. // (DNS subdomain format), while allowed in the container name format.
  530. return pod.Name + "_" + pod.Namespace
  531. }
  532. // Build the pod full name from pod name and namespace.
  533. func BuildPodFullName(name, namespace string) string {
  534. return name + "_" + namespace
  535. }
  536. // Parse the pod full name.
  537. func ParsePodFullName(podFullName string) (string, string, error) {
  538. parts := strings.Split(podFullName, "_")
  539. if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
  540. return "", "", fmt.Errorf("failed to parse the pod full name %q", podFullName)
  541. }
  542. return parts[0], parts[1], nil
  543. }
  544. // Option is a functional option type for Runtime, useful for
  545. // completely optional settings.
  546. type Option func(Runtime)
  547. // Sort the container statuses by creation time.
  548. type SortContainerStatusesByCreationTime []*ContainerStatus
  549. func (s SortContainerStatusesByCreationTime) Len() int { return len(s) }
  550. func (s SortContainerStatusesByCreationTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
  551. func (s SortContainerStatusesByCreationTime) Less(i, j int) bool {
  552. return s[i].CreatedAt.Before(s[j].CreatedAt)
  553. }
  554. const (
  555. // MaxPodTerminationMessageLogLength is the maximum bytes any one pod may have written
  556. // as termination message output across all containers. Containers will be evenly truncated
  557. // until output is below this limit.
  558. MaxPodTerminationMessageLogLength = 1024 * 12
  559. // MaxContainerTerminationMessageLength is the upper bound any one container may write to
  560. // its termination message path. Contents above this length will be truncated.
  561. MaxContainerTerminationMessageLength = 1024 * 4
  562. // MaxContainerTerminationMessageLogLength is the maximum bytes any one container will
  563. // have written to its termination message when the message is read from the logs.
  564. MaxContainerTerminationMessageLogLength = 1024 * 2
  565. // MaxContainerTerminationMessageLogLines is the maximum number of previous lines of
  566. // log output that the termination message can contain.
  567. MaxContainerTerminationMessageLogLines = 80
  568. )