mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
kubelet: add RawPodStatus and related functions
RawPodStatus will be the internal status of the pod that kubelet relies on for syncing.
This commit is contained in:
parent
70d89a3541
commit
760309f349
@ -24,6 +24,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
@ -36,6 +37,7 @@ type FakeRuntime struct {
|
|||||||
AllPodList []*Pod
|
AllPodList []*Pod
|
||||||
ImageList []Image
|
ImageList []Image
|
||||||
PodStatus api.PodStatus
|
PodStatus api.PodStatus
|
||||||
|
RawPodStatus RawPodStatus
|
||||||
StartedPods []string
|
StartedPods []string
|
||||||
KilledPods []string
|
KilledPods []string
|
||||||
StartedContainers []string
|
StartedContainers []string
|
||||||
@ -230,6 +232,24 @@ func (f *FakeRuntime) GetPodStatus(*api.Pod) (*api.PodStatus, error) {
|
|||||||
return &status, f.Err
|
return &status, f.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FakeRuntime) GetRawPodStatus(uid types.UID, name, namespace string) (*RawPodStatus, error) {
|
||||||
|
f.Lock()
|
||||||
|
defer f.Unlock()
|
||||||
|
|
||||||
|
f.CalledFunctions = append(f.CalledFunctions, "GetRawPodStatus")
|
||||||
|
status := f.RawPodStatus
|
||||||
|
return &status, f.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FakeRuntime) ConvertRawToPodStatus(_ *api.Pod, _ *RawPodStatus) (*api.PodStatus, error) {
|
||||||
|
f.Lock()
|
||||||
|
defer f.Unlock()
|
||||||
|
|
||||||
|
f.CalledFunctions = append(f.CalledFunctions, "ConvertRawToPodStatus")
|
||||||
|
status := f.PodStatus
|
||||||
|
return &status, f.Err
|
||||||
|
}
|
||||||
|
|
||||||
func (f *FakeRuntime) ExecInContainer(containerID ContainerID, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error {
|
func (f *FakeRuntime) ExecInContainer(containerID ContainerID, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error {
|
||||||
f.Lock()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -88,9 +89,23 @@ type Runtime interface {
|
|||||||
// KillPod kills all the containers of a pod. Pod may be nil, running pod must not be.
|
// KillPod kills all the containers of a pod. Pod may be nil, running pod must not be.
|
||||||
KillPod(pod *api.Pod, runningPod Pod) error
|
KillPod(pod *api.Pod, runningPod Pod) error
|
||||||
// GetPodStatus retrieves the status of the pod, including the information of
|
// GetPodStatus retrieves the status of the pod, including the information of
|
||||||
// all containers in the pod. Clients of this interface assume the containers
|
// all containers in the pod. Clients of this interface assume the
|
||||||
// statuses in a pod always have a deterministic ordering (eg: sorted by name).
|
// containers' statuses in a pod always have a deterministic ordering
|
||||||
|
// (e.g., sorted by name).
|
||||||
|
// TODO: Rename this to GetAPIPodStatus, and eventually deprecate the
|
||||||
|
// function in favor of GetRawPodStatus.
|
||||||
GetPodStatus(*api.Pod) (*api.PodStatus, error)
|
GetPodStatus(*api.Pod) (*api.PodStatus, error)
|
||||||
|
// GetRawPodStatus retrieves the status of the pod, including the
|
||||||
|
// information of all containers in the pod that are visble in Runtime.
|
||||||
|
// TODO: Rename this to GetPodStatus to replace the original function.
|
||||||
|
GetRawPodStatus(uid types.UID, name, namespace string) (*RawPodStatus, error)
|
||||||
|
// ConvertRawToPodStatus converts the RawPodStatus object to api.PodStatus.
|
||||||
|
// This function is needed because Docker generates some high-level and/or
|
||||||
|
// pod-level information for api.PodStatus (e.g., check whether the image
|
||||||
|
// exists to determine the reason).
|
||||||
|
// TODO: Deprecate this function once we generalize the logic for all
|
||||||
|
// container runtimes in kubelet.
|
||||||
|
ConvertRawToPodStatus(*api.Pod, *RawPodStatus) (*api.PodStatus, error)
|
||||||
// PullImage pulls an image from the network to local storage using the supplied
|
// PullImage pulls an image from the network to local storage using the supplied
|
||||||
// secrets if necessary.
|
// secrets if necessary.
|
||||||
PullImage(image ImageSpec, pullSecrets []api.Secret) error
|
PullImage(image ImageSpec, pullSecrets []api.Secret) error
|
||||||
@ -136,7 +151,7 @@ type ImagePuller interface {
|
|||||||
PullImage(pod *api.Pod, container *api.Container, pullSecrets []api.Secret) (error, string)
|
PullImage(pod *api.Pod, container *api.Container, pullSecrets []api.Secret) (error, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pod is a group of containers, with the status of the pod.
|
// Pod is a group of containers.
|
||||||
type Pod struct {
|
type Pod struct {
|
||||||
// The ID of the pod, which can be used to retrieve a particular pod
|
// The ID of the pod, which can be used to retrieve a particular pod
|
||||||
// from the pod list returned by GetPods().
|
// from the pod list returned by GetPods().
|
||||||
@ -228,6 +243,52 @@ type Container struct {
|
|||||||
Status ContainerStatus
|
Status ContainerStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RawPodStatus represents the status of the pod and its containers.
|
||||||
|
// api.PodStatus can be derived from examining RawPodStatus and api.Pod.
|
||||||
|
type RawPodStatus struct {
|
||||||
|
// ID of the pod.
|
||||||
|
ID types.UID
|
||||||
|
// Name of the pod.
|
||||||
|
Name string
|
||||||
|
// Namspace of the pod.
|
||||||
|
Namespace string
|
||||||
|
// IP of the pod.
|
||||||
|
IP string
|
||||||
|
// Status of containers in the pod.
|
||||||
|
ContainerStatuses []*RawContainerStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
// RawPodContainer represents the status of a container.
|
||||||
|
type RawContainerStatus struct {
|
||||||
|
// ID of the container.
|
||||||
|
ID ContainerID
|
||||||
|
// Name of the container.
|
||||||
|
Name string
|
||||||
|
// Status of the container.
|
||||||
|
Status ContainerStatus
|
||||||
|
// Creation time of the container.
|
||||||
|
CreatedAt time.Time
|
||||||
|
// Start time of the container.
|
||||||
|
StartedAt time.Time
|
||||||
|
// Finish time of the container.
|
||||||
|
FinishedAt time.Time
|
||||||
|
// Exit code of the container.
|
||||||
|
ExitCode int
|
||||||
|
// Name of the image.
|
||||||
|
Image string
|
||||||
|
// ID of the image.
|
||||||
|
ImageID string
|
||||||
|
// Hash of the container, used for comparison.
|
||||||
|
Hash string
|
||||||
|
// Number of times that the container has been restarted.
|
||||||
|
RestartCount int
|
||||||
|
// A string explains why container is in such a status.
|
||||||
|
Reason string
|
||||||
|
// Message written by the container before exiting (stored in
|
||||||
|
// TerminationMessagePath).
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
// Basic information about a container image.
|
// Basic information about a container image.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
// ID of the image.
|
// ID of the image.
|
||||||
|
@ -2095,3 +2095,11 @@ func (dm *DockerManager) GetNetNs(containerID kubecontainer.ContainerID) (string
|
|||||||
func (dm *DockerManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy) error {
|
func (dm *DockerManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy) error {
|
||||||
return dm.containerGC.GarbageCollect(gcPolicy)
|
return dm.containerGC.GarbageCollect(gcPolicy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dm *DockerManager) GetRawPodStatus(uid types.UID, name, namespace string) (*kubecontainer.RawPodStatus, error) {
|
||||||
|
return nil, fmt.Errorf("Not implemented yet")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dm *DockerManager) ConvertRawToPodStatus(_ *api.Pod, _ *kubecontainer.RawPodStatus) (*api.PodStatus, error) {
|
||||||
|
return nil, fmt.Errorf("Not implemented yet")
|
||||||
|
}
|
||||||
|
@ -1410,3 +1410,11 @@ func (r *Runtime) RemoveImage(image kubecontainer.ImageSpec) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Runtime) GetRawPodStatus(uid types.UID, name, namespace string) (*kubecontainer.RawPodStatus, error) {
|
||||||
|
return nil, fmt.Errorf("Not implemented yet")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Runtime) ConvertRawToPodStatus(_ *api.Pod, _ *kubecontainer.RawPodStatus) (*api.PodStatus, error) {
|
||||||
|
return nil, fmt.Errorf("Not implemented yet")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user