runtime.go 22 KB

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