var ErrCreateContainerConfig … var ErrPreCreateHook … var ErrCreateContainer … var ErrPreStartHook … var ErrPostStartHook … // recordContainerEvent should be used by the runtime manager for all container related events. // it has sanity checks to ensure that we do not write events that can abuse our masters. // in particular, it ensures that a containerID never appears in an event message as that // is prone to causing a lot of distinct events that do not count well. // it replaces any reference to a containerID with the containerName which is stable, and is what users know. func (m *kubeGenericRuntimeManager) recordContainerEvent(pod *v1.Pod, container *v1.Container, containerID, eventType, reason, message string, args ...interface{ … } type startSpec … func containerStartSpec(c *v1.Container) *startSpec { … } func ephemeralContainerStartSpec(ec *v1.EphemeralContainer) *startSpec { … } // getTargetID returns the kubecontainer.ContainerID for ephemeral container namespace // targeting. The target is stored as EphemeralContainer.TargetContainerName, which must be // resolved to a ContainerID using podStatus. The target container must already exist, which // usually isn't a problem since ephemeral containers aren't allowed at pod creation time. func (s *startSpec) getTargetID(podStatus *kubecontainer.PodStatus) (*kubecontainer.ContainerID, error) { … } func calcRestartCountByLogDir(path string) (int, error) { … } func (m *kubeGenericRuntimeManager) getPodRuntimeHandler(pod *v1.Pod) (podRuntimeHandler string, err error) { … } // startContainer starts a container and returns a message indicates why it is failed on error. // It starts the container through the following steps: // * pull the image // * create the container // * start the container // * run the post start lifecycle hooks (if applicable) func (m *kubeGenericRuntimeManager) startContainer(ctx context.Context, podSandboxID string, podSandboxConfig *runtimeapi.PodSandboxConfig, spec *startSpec, pod *v1.Pod, podStatus *kubecontainer.PodStatus, pullSecrets []v1.Secret, podIP string, podIPs []string, imageVolumes kubecontainer.ImageVolumes) (string, error) { … } // generateContainerConfig generates container config for kubelet runtime v1. func (m *kubeGenericRuntimeManager) generateContainerConfig(ctx context.Context, container *v1.Container, pod *v1.Pod, restartCount int, podIP, imageRef string, podIPs []string, nsTarget *kubecontainer.ContainerID, imageVolumes kubecontainer.ImageVolumes) (*runtimeapi.ContainerConfig, func(), error) { … } func (m *kubeGenericRuntimeManager) updateContainerResources(pod *v1.Pod, container *v1.Container, containerID kubecontainer.ContainerID) error { … } // makeDevices generates container devices for kubelet runtime v1. func makeDevices(opts *kubecontainer.RunContainerOptions) []*runtimeapi.Device { … } // makeCDIDevices generates container CDIDevices for kubelet runtime v1. func makeCDIDevices(opts *kubecontainer.RunContainerOptions) []*runtimeapi.CDIDevice { … } // makeMounts generates container volume mounts for kubelet runtime v1. func (m *kubeGenericRuntimeManager) makeMounts(opts *kubecontainer.RunContainerOptions, container *v1.Container) []*runtimeapi.Mount { … } // getKubeletContainers lists containers managed by kubelet. // The boolean parameter specifies whether returns all containers including // those already exited and dead containers (used for garbage collection). func (m *kubeGenericRuntimeManager) getKubeletContainers(ctx context.Context, allContainers bool) ([]*runtimeapi.Container, error) { … } // makeUID returns a randomly generated string. func makeUID() string { … } // getTerminationMessage looks on the filesystem for the provided termination message path, returning a limited // amount of those bytes, or returns true if the logs should be checked. func getTerminationMessage(status *runtimeapi.ContainerStatus, terminationMessagePath string, fallbackToLogs bool) (string, bool) { … } // readLastStringFromContainerLogs attempts to read up to the max log length from the end of the CRI log represented // by path. It reads up to max log lines. func (m *kubeGenericRuntimeManager) readLastStringFromContainerLogs(path string) string { … } func (m *kubeGenericRuntimeManager) convertToKubeContainerStatus(status *runtimeapi.ContainerStatus) (cStatus *kubecontainer.Status) { … } // getPodContainerStatuses gets all containers' statuses for the pod. func (m *kubeGenericRuntimeManager) getPodContainerStatuses(ctx context.Context, uid kubetypes.UID, name, namespace string) ([]*kubecontainer.Status, error) { … } func toKubeContainerStatus(status *runtimeapi.ContainerStatus, runtimeName string) *kubecontainer.Status { … } // executePreStopHook runs the pre-stop lifecycle hooks if applicable and returns the duration it takes. func (m *kubeGenericRuntimeManager) executePreStopHook(ctx context.Context, pod *v1.Pod, containerID kubecontainer.ContainerID, containerSpec *v1.Container, gracePeriod int64) int64 { … } // restoreSpecsFromContainerLabels restores all information needed for killing a container. In some // case we may not have pod and container spec when killing a container, e.g. pod is deleted during // kubelet restart. // To solve this problem, we've already written necessary information into container labels. Here we // just need to retrieve them from container labels and restore the specs. // TODO(random-liu): Add a node e2e test to test this behaviour. // TODO(random-liu): Change the lifecycle handler to just accept information needed, so that we can // just pass the needed function not create the fake object. func (m *kubeGenericRuntimeManager) restoreSpecsFromContainerLabels(ctx context.Context, containerID kubecontainer.ContainerID) (*v1.Pod, *v1.Container, error) { … } // killContainer kills a container through the following steps: // * Run the pre-stop lifecycle hooks (if applicable). // * Stop the container. func (m *kubeGenericRuntimeManager) killContainer(ctx context.Context, pod *v1.Pod, containerID kubecontainer.ContainerID, containerName string, message string, reason containerKillReason, gracePeriodOverride *int64, ordering *terminationOrdering) error { … } // killContainersWithSyncResult kills all pod's containers with sync results. func (m *kubeGenericRuntimeManager) killContainersWithSyncResult(ctx context.Context, pod *v1.Pod, runningPod kubecontainer.Pod, gracePeriodOverride *int64) (syncResults []*kubecontainer.SyncResult) { … } // pruneInitContainersBeforeStart ensures that before we begin creating init // containers, we have reduced the number of outstanding init containers still // present. This reduces load on the container garbage collector by only // preserving the most recent terminated init container. func (m *kubeGenericRuntimeManager) pruneInitContainersBeforeStart(ctx context.Context, pod *v1.Pod, podStatus *kubecontainer.PodStatus) { … } // Remove all init containers. Note that this function does not check the state // of the container because it assumes all init containers have been stopped // before the call happens. func (m *kubeGenericRuntimeManager) purgeInitContainers(ctx context.Context, pod *v1.Pod, podStatus *kubecontainer.PodStatus) { … } // findNextInitContainerToRun returns the status of the last failed container, the // index of next init container to start, or done if there are no further init containers. // Status is only returned if an init container is failed, in which case next will // point to the current container. func findNextInitContainerToRun(pod *v1.Pod, podStatus *kubecontainer.PodStatus) (status *kubecontainer.Status, next *v1.Container, done bool) { … } // hasAnyRegularContainerCreated returns true if any regular container has been // created, which indicates all init containers have been initialized. func hasAnyRegularContainerCreated(pod *v1.Pod, podStatus *kubecontainer.PodStatus) bool { … } // computeInitContainerActions sets the actions on the given changes that need // to be taken for the init containers. This includes actions to initialize the // init containers and actions to keep restartable init containers running. // computeInitContainerActions returns true if pod has been initialized. // // The actions include: // - Start the first init container that has not been started. // - Restart all restartable init containers that have started but are not running. // - Kill the restartable init containers that are not alive or started. // // Note that this is a function for the SidecarContainers feature. // Please sync with the findNextInitContainerToRun function if any changes are // made, as either this or that function will be called. func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, podStatus *kubecontainer.PodStatus, changes *podActions) bool { … } // GetContainerLogs returns logs of a specific container. func (m *kubeGenericRuntimeManager) GetContainerLogs(ctx context.Context, pod *v1.Pod, containerID kubecontainer.ContainerID, logOptions *v1.PodLogOptions, stdout, stderr io.Writer) (err error) { … } // GetExec gets the endpoint the runtime will serve the exec request from. func (m *kubeGenericRuntimeManager) GetExec(ctx context.Context, id kubecontainer.ContainerID, cmd []string, stdin, stdout, stderr, tty bool) (*url.URL, error) { … } // GetAttach gets the endpoint the runtime will serve the attach request from. func (m *kubeGenericRuntimeManager) GetAttach(ctx context.Context, id kubecontainer.ContainerID, stdin, stdout, stderr, tty bool) (*url.URL, error) { … } // RunInContainer synchronously executes the command in the container, and returns the output. func (m *kubeGenericRuntimeManager) RunInContainer(ctx context.Context, id kubecontainer.ContainerID, cmd []string, timeout time.Duration) ([]byte, error) { … } // removeContainer removes the container and the container logs. // Notice that we remove the container logs first, so that container will not be removed if // container logs are failed to be removed, and kubelet will retry this later. This guarantees // that container logs to be removed with the container. // Notice that we assume that the container should only be removed in non-running state, and // it will not write container logs anymore in that state. func (m *kubeGenericRuntimeManager) removeContainer(ctx context.Context, containerID string) error { … } // removeContainerLog removes the container log. func (m *kubeGenericRuntimeManager) removeContainerLog(ctx context.Context, containerID string) error { … } // DeleteContainer removes a container. func (m *kubeGenericRuntimeManager) DeleteContainer(ctx context.Context, containerID kubecontainer.ContainerID) error { … } // setTerminationGracePeriod determines the grace period to use when killing a container func setTerminationGracePeriod(pod *v1.Pod, containerSpec *v1.Container, containerName string, containerID kubecontainer.ContainerID, reason containerKillReason) int64 { … } func isProbeTerminationGracePeriodSecondsSet(pod *v1.Pod, containerSpec *v1.Container, probe *v1.Probe, containerName string, containerID kubecontainer.ContainerID, probeType string) bool { … }