mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 16:06:51 +00:00
Merge pull request #31395 from yujuhong/getpods
Automatic merge from submit-queue Instruct PLEG to detect pod sandbox state changes This PR adds a Sandboxes list in `kubecontainer.Pod`, so that PLEG can check sandbox changes using `GetPods()` . The sandboxes are treated as regular containers (type `kubecontainer.Container`) for now to avoid additional changes in PLEG. /cc @feiskyer @yifan-gu @euank
This commit is contained in:
@@ -77,6 +77,21 @@ func toKubeContainerState(state runtimeApi.ContainerState) kubecontainer.Contain
|
||||
return kubecontainer.ContainerStateUnknown
|
||||
}
|
||||
|
||||
// sandboxToKubeContainerState converts runtimeApi.PodSandboxState to
|
||||
// kubecontainer.ContainerState.
|
||||
// This is only needed because we need to return sandboxes as if they were
|
||||
// kubecontainer.Containers to avoid substantial changes to PLEG.
|
||||
// TODO: Remove this once it becomes obsolete.
|
||||
func sandboxToKubeContainerState(state runtimeApi.PodSandBoxState) kubecontainer.ContainerState {
|
||||
switch state {
|
||||
case runtimeApi.PodSandBoxState_READY:
|
||||
return kubecontainer.ContainerStateRunning
|
||||
case runtimeApi.PodSandBoxState_NOTREADY:
|
||||
return kubecontainer.ContainerStateExited
|
||||
}
|
||||
return kubecontainer.ContainerStateUnknown
|
||||
}
|
||||
|
||||
// toRuntimeProtocol converts api.Protocol to runtimeApi.Protocol.
|
||||
func toRuntimeProtocol(protocol api.Protocol) runtimeApi.Protocol {
|
||||
switch protocol {
|
||||
@@ -107,6 +122,21 @@ func (m *kubeGenericRuntimeManager) toKubeContainer(c *runtimeApi.Container) (*k
|
||||
}, nil
|
||||
}
|
||||
|
||||
// sandboxToKubeContainer converts runtimeApi.PodSandbox to kubecontainer.Container.
|
||||
// This is only needed because we need to return sandboxes as if they were
|
||||
// kubecontainer.Containers to avoid substantial changes to PLEG.
|
||||
// TODO: Remove this once it becomes obsolete.
|
||||
func (m *kubeGenericRuntimeManager) sandboxToKubeContainer(s *runtimeApi.PodSandbox) (*kubecontainer.Container, error) {
|
||||
if s == nil || s.Id == nil || s.State == nil {
|
||||
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime container")
|
||||
}
|
||||
|
||||
return &kubecontainer.Container{
|
||||
ID: kubecontainer.ContainerID{Type: m.runtimeName, ID: s.GetId()},
|
||||
State: sandboxToKubeContainerState(s.GetState()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// milliCPUToShares converts milliCPU to CPU shares
|
||||
func milliCPUToShares(milliCPU int64) int64 {
|
||||
if milliCPU == 0 {
|
||||
|
||||
Reference in New Issue
Block a user