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:
Kubernetes Submit Queue
2016-09-08 05:41:16 -07:00
committed by GitHub
6 changed files with 175 additions and 14 deletions

View File

@@ -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 {